是否可以先在没有 `cmp` 的情况下在汇编中使用条件跳转? [英] Is it possible to use a conditional jump in assembly without a `cmp` first?
问题描述
所以我正在阅读一些汇编源代码 出于学习目的,遇到了一些非常奇怪的事情(或者我可能只是一个新手):
So I'm reading through some assembly source code for learning purposes and came across something very strange (or I may just be a newb):
.ver:
mov al, [redoxfs.header + Header.version + bx]
mov ah, [.version + bx]
cmp al, ah
jne .ver_err
inc bx
jl .ver
所以在这个子标签中我们有两个跳转指令.
So in this sub-label we have two jump instructions.
然而,关于最后一条跳转指令jl
.如果我错了,请纠正我,但是在跳转之前不应该有一个 cmp
因为它是有条件的吗?
However, about the last jump instruction jl
. Correct me if I'm wrong, but shouldn't there be a cmp
before the jump since it's conditional?
我一开始以为是基于cmp al, ah
,但是jne
还是不相等就跳转.
I initially thought it was based on cmp al, ah
, but jne
jumps if not equal anyway.
我错过了什么吗?
推荐答案
考虑这 3 种指令:
- 所有条件跳转(如
jne
、jl
等)都将根据 FLAGS 寄存器中一位或多位的当前设置进行跳转. - 除了
cmp
指令之外,还有更多指令会修改 FLAGS 寄存器中的某些位(例如test
、add
,等等). - 还有很多指令不会修改任何标志(例如
mov
、push
等等).
- All of the conditional jumps (like
jne
,jl
, and many more) will jump based on the current setting of one or more of the bits in the FLAGS register. - Besides the
cmp
instruction, there are many more instructions that will modify some of these bits in the FLAGS register (liketest
,add
, and many more). - And then there are lots of instructions that don't modify any of the flags (like
mov
,push
, and many more).
示例
cmp al, ah
jne .ver_err
jne .ver_err
根据最近的标志修改指令设置的标志位跳转,在这种情况下是cmp al, ah
.
The jne .ver_err
jumps based on the flagbits set by the most recent flags modifying instruction which is cmp al, ah
in this case.
inc bx
jl .ver
jl .ver
根据最近的标志修改指令设置的标志位跳转,在这种情况下是 inc bx
.
The jl .ver
jumps based on the flagbits set by the most recent flags modifying instruction which is inc bx
in this case.
inc bx
lea si, [si+1]
jl .ver
由于这个插入的lea
指令没有修改任何标志,jl .ver
指令仍然根据inc bx
指令,因为那仍然是最近的标志修改指令.
Since this interjected lea
instruction does not modify any flags, the jl .ver
instruction still jumps based on the flagbits set by the inc bx
instruction because that's still the most recent flags modifying instruction.
这篇关于是否可以先在没有 `cmp` 的情况下在汇编中使用条件跳转?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!