kochy
kochy

Reputation: 69

MIPS assembly understanding READ syscall

I have a piece of code in MIPS I am failing to understand. Namely the register convention using the "read" linux syscall:

...
move    a0,zero #a0 = 0
move    a1,s0    #a1 = some adress in memory
li  v0,4003  #v0 = 4003 = SYSCALL READ
syscall
bnez    a3, label #What is in a3??
li  v1,1
bne v0,v1
...

Now I get understand it as

char buffer;
int v0 = read(0, &buffer, 1);
????

What I do not get at all is what is the meaning of reg a3 in this context? v0 is the return value of read, but a3 should be parameter and not ret value. Is it errno?

Upvotes: 0

Views: 347

Answers (1)

Michael
Michael

Reputation: 58427

It's a boolean indicating whether or not there was an error:

On a few architectures, a register is used as a boolean (0 indicating no error, and -1 indicating an error) to signal that the system call failed.

Arch/ABI    Instruction           System   Ret   Ret    Error 
                                  call #   val   val2
-------------------------------------------------------------
mips        syscall               v0       v0    v1     a3

source

Upvotes: 1

Related Questions