EMBEDDED SYSTEMS & MICROCONTROLLERS · PAGE 27
Assembly: Registers and Status Flags
The CPU's tiny workbench.
Registers are the CPU's fastest storage. Instructions typically load a value into a register, operate on it, then store the result.
A status register holds flags set by operations: zero (result was 0), carry (an addition overflowed), and negative. Conditional jumps read these flags to make decisions.
Learning flags explains how a C if statement becomes machine code.
EXAMPLE
; generic teaching syntax
LOAD R0, 10
SUB R0, 10 ; result is 0, so the zero flag is set
JZ done ; jump taken because zero flag is set
...
done: HALT