I have a trace instruction and want to extract function calls and returns.
I found that except call
instruction, push
+jmp
and push
+ret
can be used for function call? At first I want to be sure is that correct? and if yes what are the differences between them?
Also if push
+ret
is kind of call so what would be the end or return of a function? Seeing only ret
without push
instruction before it?
In simplified terms:
call address
This will push the updated program counter (which points to the instruction after the
call
) onto the stack then jump to the address indicated (addressing modes may apply).ret
This instruction internally pops and address off the stack and jumps to it. This is nicely matched with
call
so it can return to the instruction after the priorcall
.jmp address
This simply jumps to the given address (addressing modes may apply). It doesn't do anything with the stack at all.
So, you can also do this:
Which will pop and jump to the address that was pushed onto the stack as described above. It's a clever way to do an indirect jump in a microprocessor that doesn't support indirect addressing modes in their jump instructions.
The sequence:
Will simply jump to someplace and not affect the stack or use the address that was pushed onto the stack. If address is the instruction after the
jmp
, this is roughly equivalent tocall someplace
.For instruction sets that don't support an indirect addressing jump, I've seen this nice little work-around:
Which will jump to whatever
address
is.