Exercise 52: A Tiny Virtual Machine – Part 5: Compiler for Bytecode

Goals:

  • Create a tiny “assembler” that emits bytecode for your VM.
  • Understand how compilers parse and emit instructions.

Topics Covered:

  • Create a basic script parser.
  • Map mnemonics like LOAD R0, 42 to machine code bytes.
  • Write programs like:
asmCopyEditLOAD R0, 5
LOAD R1, 10
ADD R0, R1
OUT R0
HLT
  • Output:
bashCopyEdit$ ./vm program.bin
15