QAH*_*QAH 16 assembly conditional-statements
我试图在网上找到汇编语言函数"je"的用法.我读到,如果相等,那意味着跳跃,这正是我想要的.这个函数的实际用法是什么,换句话说,如何输入这个函数来检查一个值,如果等于某个值就跳转?
请告诉我.
顺便说一下,如果有所作为,我正在使用NASM.
bca*_*cat 20
假设您要检查是否EAX
等于5
,并根据比较结果执行不同的操作.换句话说,if语句.
; ... some code ...
cmp eax, 5
je .if_true
; Code to run if comparison is false goes here.
jmp short .end_if
.if_true:
; Code to run if comparison is true goes here.
.end_if:
; ... some code ...
Run Code Online (Sandbox Code Playgroud)
asv*_*kau 13
如果FLAGS
设置了寄存器中的"相等标志"(也称为"零标志"),则会跳转.这是由算术运算或类似TEST
和的指令设置的CMP
.
例如:(如果记忆对我有用,这是正确的:-)
cmp eax, ebx ; Subtract EBX from EAX -- the result is discarded ; but the FLAGS register is set according to the result. je .SomeLabel ; Jump to some label if the result is zero (ie. they are equal). ; This is also the same instruction as "jz".
小智 8
我不得不说je func是测试是否设置了零标志,然后跳转到其他地方或继续执行下一条指令。
test cx, cx
je some_label
Run Code Online (Sandbox Code Playgroud)
测试指令只是对两个操作数进行按位“与”运算,并根据“与”运算结果设置标志。然后,je指令使用ZERO标志决定跳还是继续。
上面的代码用于检查cx是否为零。
注意:je并不是为了测试相等,而是测试在此之前由某些指令设置的零标志。