Difference between “addi” and “add” for pseudoinstruction “move” in MIPS?

The addi instruction requires an immediate operand rather than a register, so the $0 would actually be 0: Both will work and have all the needed information encoded into the instruction itself): However, it would be more usual to just use the zero-locked $0 register in this particular case since that is, after all, its purpose. I would also tend to use the unsigned variant however, since I … Read more

writing functions in assembler

(assuming NASM x86) Use call in order to call the function and ret to return from the function. What occurs when you type call is that the address of the next instruction is pushed into the stack. When ret is hit, it will pop that address off the stack and jmp to it. Calling convention dictates that the EAX register should contain the return value. Also note that the __cdecl calling … Read more

MIPS program jr $ra instructions and stack handling

On function entry, ra holds the return address where our caller wants us to jump when we’re done. The function preamble saves it to the stack because the function body uses jal to make function calls. jal overwrites ra so we need to save/restore our own return address around that. When the function is complete we can restore the things we saved, then … Read more