Exercise 50: A Tiny Virtual Machine – Part 3: Arithmetic & Branching

Goals:

  • Add arithmetic instructions.
  • Add branching/jump logic.

Topics Covered:

  • Instructions: ADD, SUB, JMP, JZ.
  • Zero flag handling.
  • Implementing conditional jumps.

Instruction Set Example:

nginxCopyEditLOAD R0, 10
LOAD R1, 10
SUB R0, R1
JZ 0x20  ; jump if zero
HLT