VM Stack Machine Simulator
CSA-101 Ch 7 interactive · type Virtus VM commands · watch the stack and the 8 segments update · return to CSA-101
Stack (top ↑ highlighted)
Operand inspector
Program source
Trace log
Memory segments
What you are watching
The Virtus VM is a stack machine. Every command either pushes a value onto the stack, pops values off, or moves values between the stack and one of the eight memory segments. There are no registers in this notation; everything happens through the stack and named segment slots.
Each arithmetic command pops one or two values, computes a result, and pushes the result back. add reads a (under the top) and b (top), pushes a + b. The compiler in Ch 9 to Ch 11 will emit programs of these commands. The translator in this chapter compiles each command into a fixed RV32I-Lite instruction sequence; the cheat sheet at cross-chapter-vm-segment-cheat-sheet shows the emission pattern for each.
Comparison commands push -1 for true and 0 for false. The all-ones bit pattern is the Virtus convention (the Hack VM convention upstream of it); a single bitwise and can then test the result without a branch.
The constant segment is not memory. push constant 5 reads the literal 5 from source; there is no constant[0] slot to write to. pop constant n is rejected by the translator (and by this simulator).