The COMPARE instruction would set the NZVC flags and the conditional branch instruction must decide whether the branch should be taken based on the setting of the NZVC flags.
CMP R1, R2
Bcc Label
ADD R2, R1, R2
ADD R3, R1, R3
ADD R4, R1, R4
...
Although out toy CPU does not have a subtract instruction, for the sake of discussion, we just assume that the CPU does have one (and it is quite easy to expand the CPU with subtraction capability).
Slideshow:
![]() |
Branch condition <-------------- branch offset -----------> +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+ | 1 | 1 | B | B | B | | | | | | | | | | | | +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+ B B B Branch condition --------------------------------------------------------------- 0 0 0 Branch always 0 0 1 BEQ 0 1 0 BNE 0 1 1 BLT 1 0 0 BLE 1 0 1 BGT 1 1 0 BGE 1 1 1 not used |
![]() |