943,983 Members | Top Members by Rank

Ad:
  • Assembly Discussion Thread
  • Unsolved
  • Views: 1272
  • Assembly RSS
Oct 28th, 2009
0

Flags used to test conditional jumps...

Expand Post »
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
Last edited by runtogetdone; Oct 28th, 2009 at 12:29 am.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
runtogetdone is offline Offline
2 posts
since Oct 2009
Oct 28th, 2009
0
Re: Flags used to test conditional jumps...
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
Assembly Syntax (Toggle Plain Text)
  1. Signed Unsigned Signed Unsigned
  2. op1 > op2 OF=SF, ZF=0 ZF=0,CF=0 Greater Above
  3. OP1>=op2 OF=SF CF=0 GreaterEqual AboveEqual
  4. op1=op2 ZF=1 ZF=1 Equal Equal
  5. op1<=op2 OF<>SF, ZF=1 ZF=1,CF=1 LessEqual BelowEqual
  6. op1<op2 OF<>SF CF=1 Less Below
Assembly Syntax (Toggle Plain Text)
  1. Unsigned
  2. JA,JNBE > <= JBE,JNA
  3. JAE,JNB >= < JB,JNAE
  4.  
  5. Signed
  6. JG,JNLE > <= JLE,JNG
  7. JGE,JNL >= < JL,JNGE
  8.  
  9. the others are specific
  10. JO Jump if Overflow JNO
  11. JP,JPE Jump if Parity JNP,JPO
  12. JS Jump if sign JNS
  13. JC Jump if carry JNC
  14. JZ,JE Jump if zero JNZ,JNE
Last edited by wildgoose; Oct 28th, 2009 at 10:20 pm.
Reputation Points: 546
Solved Threads: 99
Practically a Posting Shark
wildgoose is offline Offline
891 posts
since Jun 2009
Oct 28th, 2009
0
Re: Flags used to test conditional jumps...
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.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
cyb3rl0rd1867 is offline Offline
6 posts
since Oct 2009
Oct 29th, 2009
0
Re: Flags used to test conditional jumps...
Click to Expand / Collapse  Quote originally posted by wildgoose ...
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
Assembly Syntax (Toggle Plain Text)
  1. Signed Unsigned Signed Unsigned
  2. op1 > op2 OF=SF, ZF=0 ZF=0,CF=0 Greater Above
  3. OP1>=op2 OF=SF CF=0 GreaterEqual AboveEqual
  4. op1=op2 ZF=1 ZF=1 Equal Equal
  5. op1<=op2 OF<>SF, ZF=1 ZF=1,CF=1 LessEqual BelowEqual
  6. op1<op2 OF<>SF CF=1 Less Below
Assembly Syntax (Toggle Plain Text)
  1. Unsigned
  2. JA,JNBE > <= JBE,JNA
  3. JAE,JNB >= < JB,JNAE
  4.  
  5. Signed
  6. JG,JNLE > <= JLE,JNG
  7. JGE,JNL >= < JL,JNGE
  8.  
  9. the others are specific
  10. JO Jump if Overflow JNO
  11. JP,JPE Jump if Parity JNP,JPO
  12. JS Jump if sign JNS
  13. JC Jump if carry JNC
  14. 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.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
runtogetdone is offline Offline
2 posts
since Oct 2009

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Assembly Forum Timeline: OS dev: Procedure that ends a task.
Next Thread in Assembly Forum Timeline: x86 32-bit registers





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC