7. Memory: The Computer’s Notebook
Store and actually retrieve a byte after overwriting R0.
1. Predict and trace
Before running the Try program, predict its output and trace the first three executed instructions. Track the relevant registers, flags or memory as needed. Then step the program to compare.
LOAD 42 STORE 0 LOAD 99 STORE 1 LOAD 0 LOAD [0] PRINT LOAD [1] PRINT HALT
Queue input: None
Initialize memory: All bytes initially zero
Try prediction key
Output: 42, 99
| Instruction | PC before | PC after | R0 before | R0 after | Relevant state | Output |
|---|---|---|---|---|---|---|
| LOAD | 0 | 1 | 0 | 42 | {"registers":[42,0,0,0,0,0,0,0],"flags":{"zero":false,"negative":false,"overflow":false},"sp":255,"stack":[],"callStack":[],"loopStack":[],"memoryReads":[],"memoryWrites":[]} | None |
| STORE | 1 | 2 | 42 | 42 | {"registers":[42,0,0,0,0,0,0,0],"flags":{"zero":false,"negative":false,"overflow":false},"sp":255,"stack":[],"callStack":[],"loopStack":[],"memoryReads":[],"memoryWrites":[0]} | None |
| LOAD | 2 | 3 | 42 | 99 | {"registers":[99,0,0,0,0,0,0,0],"flags":{"zero":false,"negative":false,"overflow":false},"sp":255,"stack":[],"callStack":[],"loopStack":[],"memoryReads":[],"memoryWrites":[]} | None |
2. Build and check
Read a byte-valued input (0–255), save it at memory address 10, clear R0, then retrieve it from memory and print it.
Required instruction types: INPUT, STORE, LOAD
Example challenge solution
INPUT STORE 10 LOAD 0 LOAD [10] PRINT HALT
Actual checker fixtures
Case 1
- Input
9- Initial memory
All bytes initially zero- Expected output
9- Expected final memory
10: 9- Required memory reads
10
Case 2
- Input
42- Initial memory
All bytes initially zero- Expected output
42- Expected final memory
10: 42- Required memory reads
10
Case 3
- Input
127- Initial memory
All bytes initially zero- Expected output
127- Expected final memory
10: 127- Required memory reads
10
3. Explain the machine
Which code reads memory 10, and which loads the number10?
Reasoning and teaching note
LOAD [10] reads the byte; LOAD 10 is literal. STORE and later retrieval preserve the byte beyond R0 overwrite.