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.
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?
I initially thought it was based on cmp al, ah
, but jne
jumps if not equal anyway.
Am I missing something?
Conditional jump This is performed by a set of jump instructions j<condition> depending upon the condition. The conditional instructions transfer the control by breaking the sequential flow and they do it by changing the offset value in IP.
1.1 Jump Instruction. JMP (Jump) unconditionally transfers control to the target location. JMP is a one-way transfer of execution; it does not save a return address on the stack. The JMP instruction always performs the same basic function of transferring control from the current location to a new location.
Consider these 3 kinds of instructions:
jne
, jl
, and many more) will jump based on the current setting of one or more of the bits in the FLAGS register. cmp
instruction, there are many more instructions that will modify some of these bits in the FLAGS register (like test
, add
, and many more).mov
, push
, and many more). Examples
cmp al, ah
jne .ver_err
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
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
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With