I just started with assembly and it’s going great, but there’s 1 thing that I just don’t understand.
How do conditional jumps work?
I have a sample of assembly code here.
TEST EAX, EAX
FCLEX
JGE SHORT 004022B1
I see that when a certain condition is greater or equal, a jump will be made to 004022B1.
But what is that condition and where is it checked?
I assume the condition must be TEST EAX,EAX. But I’m not sure what it does.
Can anyone explain to me how conditional jumps work and where the condition is checked/stored?
Conditional jumps (and some other instructions) use flags. These flags are bits in the (E/R)FLAGS register.
test a, bsets the flags according to the result ofand a, b, without updatingawith the result.fclexdoes not change any normal flags (it changes FPU flags of course).jgetests* whether the value of the sign flag is equal to the overflow flag.test a, bsets the overflow flag to zero and the sign flag to the signbit of the result ofand a, b. So the jump will be taken ifeaxis positive.*: note that it does not test for “greater or equal”. That interpretation is valid when the flags are checked after a
cmp(and some other instructions). It really just looks at the flags.