Reputation: 11966
As I understand, conditional jumps check the status of a flag set after the CMP
instruction. For example:
CMP AX,DX ; Set compare flags
JGE DONE ; Go to DONE label if AX >= DX
...
DONE:
...
How are the flags actually checked in this situation? If I'm not mistaken, the flags are individual bits in a special register; so are the bits checked one at a time, or all at once? In C pseudocode:
unsigned flags = 0; /* reset all flags */
/* define the flags */
const unsigned GREATER = 1<<1;
const unsigned EQUAL = 1<<2;
const unsigned LESS = 1<<3;
unsigned AX = 4; /* initialize AX */
unsigned DX = 3; /* initialize DX */
/* CMP AX,DX */
int result = AX - DX;
if(result > 0){
flags |= GREATER;
}else if(result == 0){
flags |= EQUAL;
}else if(result < 0){
flags |= LESS;
}
/* -------------------------------- */
/* JGE Method 1 */
if(flags & GREATER){
goto DONE;
}
if(flags & EQUAL){
goto DONE;
}
/* or JGE Method 2 */
if(flags & (GREATER|EQUAL)){
goto DONE;
}
Don't look to deeply into the flag-setting code -- I know actual x86 processors flags are naturally filled rather than explicitly set -- my concern is how those flags are actually checked: bit by bit, or an encompassing bitmask.
Upvotes: 1
Views: 787
Reputation: 40659
Well, it depends, on how the machine is built.
Let me point you to a PDF of Harry Porter's Relay Computer, a particularly simple example of a computer. Look on slide 115, where he's showing how the instructions are processed. Basically there's a big blob of combinational logic implementing a Finite State Machine that controls how each instruction is executed. Most of the stepping in the FSM is concerned with moving data and addresses between registers, using the address and data busses.
If you're wondering what combinational logic is, it is a blob having a bunch of boolean inputs, and a bunch of boolean outputs, and each output is a boolean function of some of the inputs. The blob has no memory. The way it gets memory is by feeding some of the outputs back to the inputs.
So to answer your question, in the context of that computer, it probably tests all the condition bits at the same time, in a boolean expression.
Upvotes: 3