Hi, I do not understand how the x86 processor chooses whether to not to jump for a conditional jump. My professor told me that conditional jumps are based on the OF, ZF, SF, and CF flags, but I do not understand which flags are checked under a given jump instruction...

For example, what flags are checked for a unsigned greater-than jump?

Thanks,
Tyler

(In other words, how do I determine the flags in the right column of this website?)
http://siyobik.info/index.php?module=x86&id=146

Edited by runtogetdone: n/a

3
Contributors
3
Replies
4
Views
8 Years
Discussion Span
Last Post by runtogetdone

You can download processor books but my favorite reference is the 32/64-bit 80x86 Assembly Language Architecture Book.

Your mathematical operation and/or compares will set conditional flags.
You then branch based upon those flags.

For math there is a signed result and an unsigned result.
That book pg. 292

``````Signed               Unsigned            Signed         Unsigned
op1 > op2    OF=SF, ZF=0      ZF=0,CF=0          Greater            Above
OP1>=op2    OF=SF               CF=0            GreaterEqual   AboveEqual
op1=op2      ZF=1                  ZF=1             Equal               Equal
op1<=op2    OF<>SF, ZF=1     ZF=1,CF=1               LessEqual        BelowEqual
op1<op2       OF<>SF            CF=1              Less                 Below``````
``````Unsigned
JA,JNBE >            <= JBE,JNA
JAE,JNB >=          <  JB,JNAE

Signed
JG,JNLE  >             <= JLE,JNG
JGE,JNL  >=            < JL,JNGE

the others are specific
JO   Jump if Overflow                 JNO
JP,JPE   Jump if Parity                      JNP,JPO
JS         Jump if sign                   JNS
JC        Jump if carry                  JNC
JZ,JE    Jump if zero                  JNZ,JNE``````

Edited by wildgoose: n/a

This also confused me at first but it's really pretty simple. In this example I will use the CMP (compare) instruction. This is the equivalent of subtracting two numbers without storing the result. This is very helpful even without storing the answer because it sets certain flags which can help you compare two numbers. For example: mov al,1
cmp al,1
In this example the result is obvious that they are the same. But remember that it's subtracting them (even though it doesn't store the result) so the answer is 0. The ZF (Zero Flag) is therefore set to 1.
So the instruction "JE wherever" will jump since the ZF is set to 1.
Similarly the OF flag is set to 1 when the MSB, Most significant digit, or leftmost bit is set or cleared. Otherwise it is set to 0. So if the OF is not set (meaning it's 0) then JO (jump if overflow=1) will not jump.
The NF is the same thing. If the first bit (MSB) was set to one in the an operation preceding it the NF is set to 1. Otherwise it is set to 0. To find out the negative of a number in "bit language" you must NOT it.

You can download processor books but my favorite reference is the 32/64-bit 80x86 Assembly Language Architecture Book.

Your mathematical operation and/or compares will set conditional flags.
You then branch based upon those flags.

For math there is a signed result and an unsigned result.
That book pg. 292

``````Signed               Unsigned            Signed         Unsigned
op1 > op2    OF=SF, ZF=0      ZF=0,CF=0          Greater            Above
OP1>=op2    OF=SF               CF=0            GreaterEqual   AboveEqual
op1=op2      ZF=1                  ZF=1             Equal               Equal
op1<=op2    OF<>SF, ZF=1     ZF=1,CF=1               LessEqual        BelowEqual
op1<op2       OF<>SF            CF=1              Less                 Below``````
``````Unsigned
JA,JNBE >            <= JBE,JNA
JAE,JNB >=          <  JB,JNAE

Signed
JG,JNLE  >             <= JLE,JNG
JGE,JNL  >=            < JL,JNGE

the others are specific
JO   Jump if Overflow                 JNO
JP,JPE   Jump if Parity                      JNP,JPO
JS         Jump if sign                   JNS
JC        Jump if carry                  JNC
JZ,JE    Jump if zero                  JNZ,JNE``````

Thanks wildgoose, this is the most concise thing I've seen...

cyb3rl0rd1867, thanks, that too makes sense. I know that the cmp instruction does a subtraction and doesn't store a result or anything, I was just wondering as to how people remember that for op1<op2, both op's signed, how you would know that the processor checks OF<>SF. After looking it kind of makes sense, but it looks like it's just easier to memory the values.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.