EEE120 Lab 4 Cheat Sheet

Mastering the Control ROM & Writing Test Programs

What does "Making a Test" mean?

You are building a programmable computer. To "test" it, you have to wear two different hats:

  • 1. The Architect (ROM)

    You teach the CPU how to do a task. You define the "AND" instruction by flipping bits in microprocessor.v (the ROM).

  • 2. The Programmer (RAM)

    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.

// The Workflow
Step 1: Modify ROM (Define Instruction)
-> Set control bits for 'AND' at address 12 (0xC)
Step 2: Modify RAM (Write Program)
-> 0 // Load
-> 3 // Value 3
-> C // Run the 'AND' instruction
-> ...
Step 3: Simulate (iverilog)

The Control Word Decoder

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)

Task 4-5 Solutions

Use these logic values to build your hex codes.

1. AND Instruction

ALU does "AND" when Arith=0, Pass=0.

Arith: 0 Invert: 0 Pass: 0
2. ZERO Instruction

Subtract Accum from itself. (A - A = 0)

Arith: 1 Invert: 1 Cin: 1 (via carry)
3. STORE Instruction

Needs 2 Steps!
1. Load address into MAR.
2. Write Accum to RAM.

How to write 'ram_vals.txt'

Task 4-5 Check

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.

The "AND" Test Logic

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
Expected Result: 3 AND 5 = 1 (Binary 0001)

The "STORE" Test Logic

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
Expected Result: Accumulator should end up back at 15 (F).