| | |
Flags used to test conditional jumps...
Please support our Assembly advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Oct 2009
Posts: 2
Reputation:
Solved Threads: 0
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
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.
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
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)
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
Assembly Syntax (Toggle Plain Text)
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
Last edited by wildgoose; Oct 28th, 2009 at 10:20 pm.
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.
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.
•
•
Join Date: Oct 2009
Posts: 2
Reputation:
Solved Threads: 0
0
#4 Oct 29th, 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
Assembly Syntax (Toggle Plain Text)
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 BelowAssembly Syntax (Toggle Plain Text)
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
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.
![]() |
Similar Threads
- jl and jg? (Assembly)
- Everything you wanted to know about undefined behaviour (but were afraid to ask) (C)
- Read a specific value from a file (C)
- Print without using any loop (C++)
- cmp instruction and conditional jumps (Assembly)
- tell is $something has value (Shell Scripting)
- how to create a zig zag encryption (C++)
Other Threads in the Assembly Forum
- Previous Thread: OS dev: Procedure that ends a task.
- Next Thread: x86 32-bit registers
Views: 493 | Replies: 3
| Thread Tools | Search this Thread |
Tag cloud for Assembly
3d 68hc11 6811 80386 :( adress array asm assembler assembly boot bootloader buffer compression cursor debug directory division docs dos draw emulator endtask error exceptions file int10h integer intel interrupt interrupts language loop newbie nohau osdevelopment print program range read remainder shape string text theory tsr x86





