如何跳转到保存在英特尔汇编寄存器中的地址?

How to jump to an address saved in a register in intel assembly?

如果我计算一个标签的地址并将其存储在eax寄存器中,我如何有条件地跳转(使用JE)到eax

jmp eax

编译,但我没有检查它是否有效。

je eax

无法编译(操作码和操作数的组合无效)。 为什么不同?如果等于 eax 怎么跳转?

je根本就没有这种形式。你可以做的是根据相反的条件进行相对条件跳转,然后进行无条件寄存器间接跳转:

jne skip
jmp eax
skip:

你可以用这个做一个宏来避免你一遍又一遍地写同样的东西。例如,在 NASM 语法中,宏可能如下所示:

%macro je_reg 1 
    jne %%skip 
    jmp %1 
    %%skip: 
%endmacro

并且可以这样使用:

je_reg eax
je_reg ebx

宏可以泛化为适用于任何条件代码:

%macro jcc_reg 2 
    j%-1 %%skip   ; %-1 expands to the inverse of the condition in the first macro argument
    jmp %2 
    %%skip: 
%endmacro

; Example usage
jcc_reg e,eax
jcc_reg no,ebx