`testl` eax against eax?
It tests whether eax is 0, or above, or below. In this case, the jump is taken if eax is 0.
It tests whether eax is 0, or above, or below. In this case, the jump is taken if eax is 0.
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
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
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
pop does add esp, 4 too, it simply saves whatever there is on the top of the stack in its operand before. If you need what’s on the stack probably pop is faster than mov wherever, [esp]; add esp, 4 but if you simply need to clear the stack add esp, 4 will be fine.
add adds the value in two registers addi adds an immediate value (constant) to the register This gives you some example.
(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
You didn’t store the numbers entered in the variables. Also, the print_int syscall expects number in $a0 so when you try to print the second number from $a1 it won’t work.
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
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