Flags used to test conditional jumps...

Please support our Assembly advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Oct 2009
Posts: 2
Reputation: runtogetdone is an unknown quantity at this point 
Solved Threads: 0
runtogetdone runtogetdone is offline Offline
Newbie Poster

Flags used to test conditional jumps...

 
0
  #1
Oct 28th, 2009
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.
Reply With Quote Quick reply to this message  
Join Date: Jun 2009
Posts: 830
Reputation: wildgoose is a name known to all wildgoose is a name known to all wildgoose is a name known to all wildgoose is a name known to all wildgoose is a name known to all wildgoose is a name known to all 
Solved Threads: 94
wildgoose's Avatar
wildgoose wildgoose is offline Offline
Practically a Posting Shark
 
0
  #2
Oct 28th, 2009
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
  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
  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.
Reply With Quote Quick reply to this message  
Join Date: Oct 2009
Posts: 6
Reputation: cyb3rl0rd1867 is an unknown quantity at this point 
Solved Threads: 0
cyb3rl0rd1867's Avatar
cyb3rl0rd1867 cyb3rl0rd1867 is offline Offline
Newbie Poster
 
0
  #3
Oct 28th, 2009
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.
Reply With Quote Quick reply to this message  
Join Date: Oct 2009
Posts: 2
Reputation: runtogetdone is an unknown quantity at this point 
Solved Threads: 0
runtogetdone runtogetdone is offline Offline
Newbie Poster
 
0
  #4
Oct 29th, 2009
Originally Posted by wildgoose View Post
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
  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
  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.
Reply With Quote Quick reply to this message  
Reply

Message:




Views: 494 | Replies: 3
Thread Tools Search this Thread



Tag cloud for Assembly
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC