Master the fundamental concepts of build a bytecode vm through this focused micro-challenge.
Every virtual machine, from CPython to the JVM to Lua, executes a stream of small integers called opcodes. Opcode 100 might mean `LOAD_CONST`; opcode 23 might mean `BINARY_ADD`. The VM's inner loop reads one number and dispatches to the handler that implements it.
The mapping from number to behavior lives in a table or a giant `switch`. Disassemblers like Python's `dis` module do the reverse mapping so humans can read compiled bytecode. You are building that reverse mapping for a five-instruction VM you will grow throughout this track.
Your tiny ISA for now:
For example, reading opcode `2` should print `ADD`, and reading `99` should print `UNKNOWN`.
Keep opcode numbering stable once you assign it. Production VMs rarely renumber existing instructions because every compiled artifact in the wild depends on the old mapping. Treat your five-opcode table as a contract you will extend, not replace.
This exercise asks you to map integers to mnemonic names before you implement the stack machine behind them. You will implement a simple `switch` dispatch table that every later VM task extends with real behavior.
Read one integer opcode from stdin.
Print its mnemonic: 1 -> PUSH, 2 -> ADD, 3 -> SUB, 4 -> PRINT, 5 -> HALT
For any other number print "UNKNOWN".
Three hints are available for this task, revealed one at a time inside the code workspace so you can struggle productively before seeing them.
All starter code and reference implementations are available for your local setup.
View on Github