Classroom Public page

Lab Pack 7: VM I (Week 8)

415 words

The virtual machine. Five worksheets in worksheets/ch7/ build the VM translator that takes stack-based VM bytecode and emits RV32I-Lite assembly. One Tier-1 simulator-driven companion calibrates the stack-machine semantics before the four Tier-2 translator labs.


Anchors the week

Week 8: VM I. Stack arithmetic plus four memory segments. The intermediate layer between high-level Jack-like source (Ch 9-11) and RV32I-Lite assembly.

Concept the lab embodies

Layered translation. Each layer of the toolchain has a clear input contract and a clear output contract; the layers compose without leakage.

The five worksheets

Worksheet Tier Time Purpose
lab-7.5-vm-stack-machine.md T1 ~75 min Calibrate against the VM Stack Machine simulator (companion to 7.1 + 7.2; pure-browser)
lab-7.1-stack-arithmetic-translator.md T2 ~90 min push/pop/add/sub/and/or
lab-7.2-memory-segment-translator.md T2 ~90 min local/argument/this/that/static/constant/pointer/temp
lab-7.3-end-to-end-on-student-silicon.md T2 ~120 min VM output runs on your CPU
lab-7.4-hand-vs-translator-reconciliation.md T2 ~90 min Compare your translator's output to hand-written assembly

Lab 7.5 carries a sub-numbering slot ahead of 7.1-7.4 deliberately: the Tier-1 simulator-driven calibration is recommended before the Tier-2 translator labs so the stack-state contract is settled before any RV32I-Lite emission patterns get written. The 7.5 numbering keeps 7.1-7.4 as the canonical Tier-2 sequence.

Companion tool

VM Stack Machine Simulator (pure-browser; no install). Type Virtus VM commands one line at a time and watch the stack and the eight memory segments update with each Step click. Pre-loaded examples cover the canonical push 5, push 3, add sequence, an arithmetic chain (push / neg / sub), the comparison commands (eq / lt / gt with the -1-on-true convention), bitwise (and / or / not), and a segment push/pop round-trip. Lab 7.5 above is the structured worksheet that drives the tool; use the tool itself as a free-form sanity check while you are working through Lab 7.1 and Lab 7.2 (if your translator's output disagrees with the simulator's stack state, one of the two is wrong, and the simulator is the authoritative reference for the language's stack semantics).

Grading rubric

Per-worksheet rubrics. Week-level: translator handles all stack-arithmetic ops and all four working memory segments; output runs on silicon.

What's next

Lab pack 8: VM II. The function-call protocol completes the VM.