![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Game engine designer
Join Date: May 2005
Location: Sweden
Posts: 301
Rep Power: 4
![]() |
jne without cmp
I am little bit curious about the compare and jump instructions. First the cmp instruction; I read about this one on wikibooks.org which says: "cmp performs a subtraction between the two operands and sets the flags". What flags do they mean? Is it a register? Which one, if that is the case?
And so the jump instruction. For example if I use the jne instruction; where does it look for the value that is "not equal"? It must be the flags that cmp sets. But where is the flags stored? Thanks for answears! /Klarre |
|
|
|
|
|
#2 |
|
The Supreme Ruler
![]() Join Date: May 2004
Location: Houston
Posts: 1,476
Rep Power: 6
![]() |
Yes, there is a flag register where this stuff is stored.
__________________
"Every gun that is made, every warship launched, every rocket signifies, in the final sense, a theft from those who hunger and are not fed, from those who are cold and are not clothed. The world in arms is not spending money alone. It is spending the sweat of its laborers, the genius of its scientists, the hopes of its children." - Dwight D. Eisenhower |
|
|
|
|
|
#3 |
|
Game engine designer
Join Date: May 2005
Location: Sweden
Posts: 301
Rep Power: 4
![]() |
I found some documents about how the flags on the processor works. So now I pretty much understands how it works.
|
|
|
|
|
|
#4 |
|
Resident Grouch
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jun 2005
Posts: 6,453
Rep Power: 10
![]() |
Think of it like this: if you want 'jne', what isn't equal to what? You have to set up some equality test somewhere and store the result somewhere. In assembly language this is in the nuts and bolts part of the processor. Many instructions include the states of the flag register as part of the conditions for their execution. Some that you might think should do so, do not. This can bite you in the butt. In the 8080, incrementing a register and adding 1 to a register were the same operation, and set the zero flag according to the result. The Z80, which was SUPPOSED to be perfectly downward-compatible with the 8080 missed a beat. Adding 1 to a register set the zero flag appropriately; incrementing the register didn't touch the flag.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code. Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|