Lets go back to an earlier day, when things were simple.
Lets go back to the days of the MOS 6502 that powered the Atari, Apple II, and several other systems from the late 70s. You can still find it in embedded systems and is apparently still produced in volumes of hundreds of millions (while this is old technology, its not outdated). By understanding how this system worked, it becomes easier to understand how more modern and complex systems worked.
The 6502 had only a few registers:
- Program counter
- Stack Pointer
- Accumulator (this is the 'important' one)
- X and Y 'index' registers
- Processor Status (this is the other 'important' one in this situation)
C Carry flag
Z Zero flag (set if the last operation had a result of
D Decimal mode
I Interput enable/disable
S Sign (set of the result of an operation is negative - sometimes that is designated the
N flag for negative)
When you did a
CMP #$44 this would compare the Accumulator with the value 0x44. In doing so, it would set the
ZCS flags appropriately.
C is set if the Accumulator is greater than or equal to value, and
Z is set if the two are equal. This was not too much more than doing
A - M where M is the value (read from memory, or a hard value), set the flags and throw away the result (compare with
SBC that would store the result in the Accumulator).
At this point, you've got the status register set, but you need to do something with it. There were two instructions for this.
BEQ (Branch if EQual) and
BNE (Branch if Not Equal). These two instructions would each test
Z of the status register -
BNE would branch if
Z was 0,
BEQ would branch if
Z was 1. While
CMP does set more flags,
BNE don't care about them - just
And really, thats how conditionals work when you are down to that level. There's a status register that is floating around somewhere many times. This register doesn't exist when you get into the pipelined, superscalar, and speculative processors. These tend to go for more explicit branching statements or use arbitrary registers for the status result rather than a dedicated register (see the MIPS instruction set and look at the
beqz and the like).
As an aside, if you are poking about virtual machines and assembly, delve a bit into Core War and the MARS virtual machine.