Mastering the Control ROM & Writing Test Programs
You are building a programmable computer. To "test" it, you have to wear two different hats:
You teach the CPU how to do a task. You define the "AND" instruction by flipping bits in microprocessor.v (the ROM).
You ask the CPU to perform that task. You write a list of numbers in ram_vals.txt that forces the CPU to run your new instruction.
When editing my_rom[x] = 14'h...., you are setting these bits. This is Table 3 from your manual, visualized.
| Bit | Name | Function |
|---|---|---|
| 13:12 | Next Step | 01=Go to Step 1, 00=Done (Fetch Next) |
| 11:10 | Unused | Always 00 |
| 9 | use_pc | 1=Next Instruction, 0=Use MAR (Data) |
| 8 | load_mar | 1=Save Data Bus to Address Register |
| 7 | arith | 1=Add/Sub, 0=Logic |
| 6 | invert | 1=Invert Input A (for Subtract) |
| 5 | pass | 1=Pass Data (No math), 0=Do Math |
| 4 | load_acc | 1=Save result to Accumulator |
| 3 | acc_to_db | 1=Put Accumulator on Data Bus |
| 2 | read | 1=Read from RAM |
| 1 | write | 1=Write to RAM |
| 0 | load_ir | 1=Load New Instruction (Fetch) |
Use these logic values to build your hex codes.
ALU does "AND" when Arith=0, Pass=0.
Subtract Accum from itself. (A - A = 0)
Needs 2 Steps!
1. Load address into MAR.
2. Write Accum to RAM.
To prove your new instructions work, you need to write a program that uses them. Copy/Paste this logic into your ram_vals.txt file to test specific functions.
If your AND instruction is at ROM index 12 (Hex C):
0 // Load ACC 3 // with value 3 (Binary 0011) C // AND Instruction 5 // with value 5 (Binary 0101) 2 // STOP
Assume STORE is at ROM index ... (Let's say Hex E):
0 // Load ACC F // with value 15 (Binary 1111) E // STORE Instruction 8 // at RAM Address 8 0 // Load ACC (Overwrite it to prove we saved it) 0 // with value 0 1 // Add (Load from RAM) 8 // from Address 8 2 // STOP