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

MIPS Address out of range (MARS)

2 I’m trying to write a simple code which save string and integer input into an array and then prints them (i will also later add another part which sorts them,but i have to get this to work first). With MARS i get this: line 75: Runtime exception at 0x004000e4: address out of range 0x00000008. … Read more

What is the difference between MOV and LEA?

LEA means Load Effective Address MOV means Load Value In short, LEA loads a pointer to the item you’re addressing whereas MOV loads the actual value at that address. The purpose of LEA is to allow one to perform a non-trivial address calculation and store the result [for later usage] Where there are just constants … 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

How do AX, AH, AL map onto EAX?

No, that’s not quite right. So AX is composed of AH:AL halves, and is itself the low half of EAX. (The upper half of EAX isn’t directly accessible as a 16-bit register; you can shift or rotate EAX if you want to get at it.) For completeness, in addition to the above, which was based … 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