I got told to try and use 'jmp rather than 'call', but 'jmp' is not liking me .. when I jump it doesn't return (so it never exits and not happy days ), but calling returns and exits as normal.
I am happy using 'call' but is there actually a reason I should try and overcome 'jmp' ?
This simple code just shows if when I jmp
it never returns and exits.
_start: jmp _Print jmp _Exit ret _Exit: ; normal exit ret _Print ; print something ret
also .. I'm running this all in a Linux terminal if that changes anything.
CALL instruction is used to call a subroutine. Subroutines are often used to perform tasks that need to be performed frequently. The JMP instruction is used to cause the PLC (Programmable Logic Control) to skip over rungs.
In the x86 assembly language, the JMP instruction performs an unconditional jump. Such an instruction transfers the flow of execution by changing the program counter.
At the time of RET instruction, the return address will be popped from the stack and added to the program counter. The JUMP instruction is not used to transfer the value of a program counter into the stack.
JMP . is essentially an infinite loop as the code will keep jumping back to itself infinitely until you get an interrupt . The JNZ statement is a conditional jump statement which will work as JMP when the zero flag is not set ( Z = 0 ).
Well, first of all, jmp
simply 'jumps' to the label that you give to it (which is a memory address as program instructions are stored in memory) while call
stores the location where it will return (below the call
instruction) in the stack, jmp
to the label, and then at the ret
instruction, jmp
back to what location was stored (as said above, below the call instruction). A bit of a difference there as you can see. IMHO, i believe it is fine to simply call
functions, as that is what the c++ compiler does with functions, but if you must jmp
, then alright then, just make sure to push
the return location or create another label to return to once done executing some code.
Here is an example of jumping to other label when done:
_start: jmp _Print; _start_label: jmp _Exit; _Exit: ; exit stuff goes here ret; _Print: ;print stuff goes here jmp _start_label;
or you could just use call :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With