If I calculate an address of a label and store it in the eax
register, how can I conditionally jump (using JE
) to eax
?
jmp eax
compiles, but I didn't check if it works.
je eax
doesn't compile (invalid combination of opcode and operands).
Why the difference? And how can I jump if equal to eax
?
There simply is no such form of
je
. What you can do is put a relative conditional jump based on the opposite condition, followed by an unconditional register-indirect jump:You could make a macro out of this to save you from writing the same thing over and over. For example, in NASM syntax that macro could look like this:
And could be used like this:
The macro could be generalized to work with any condition code: