Lab 10

Trace a load and a store through a processor

Your processor will read switches, save the input in RAM, read it back, mask it and drive the LEDs. In Lab 9 every result stayed in a processor register. Here the address, data and write signal travel outside the CPU. Draw two bus timelines, one for the store to RAM and one for the load from the same word. Mark when the address becomes stable, when RAM writes the data, and when the destination register captures the returned word.

Lab setup

Physical DE1-SoCCyclone V · 5CSEMA5F31C6 · camera, switches and buttons in the browser

Run the simulation on your computer with Icarus Verilog (Verilog or SystemVerilog) or NVC (VHDL). Then build your design and test it on the remote DE1-SoC.

  1. Get the starterDownload io_cpu.v
  2. Open the LabsLand Online EditorOpen the lab LabsLand asks you to sign in. Use the access your course or institution provides.
  3. Follow the worksheetPredict first, then build, read the board and hand in. The build steps are below.

Starter files · Verilog · VHDL · SystemVerilog

Follow the program

Open switch_mask.s. Register r7 is the program counter. RAM starts at 0x0000, the LED port is at 0x1000 and the switches are at 0x3000. RAM addresses select 16-bit words. Why is r0 cleared after the first store? Predict the result when SW8–0 contain 0x135.

Simulate and repair the load

Extract the worksheet ZIP and run these commands from the folder containing activity.md.

The bench runs the assembly program on your HDL processor for every one of the 512 switch words. It also checks halt, resume and reset. Find the first failing word. Inspect the address sent to RAM and the value on the bus when the load commits.

test_io.v

test_io.vhd

trace_io.v

trace_io.vhd

Verilog

iverilog -g2005 -s trace_io -o trace starter/io_cpu.v simulation/trace_io.v
vvp trace
iverilog -g2005 -s test_io -o bench starter/io_cpu.v simulation/test_io.v
vvp bench

SystemVerilog

iverilog -g2012 -s trace_io -o trace starter/io_cpu.sv simulation/trace_io.v
vvp trace
iverilog -g2012 -s test_io -o bench starter/io_cpu.sv simulation/test_io.v
vvp bench

VHDL

nvc --std=2008 -a starter/io_cpu.vhd simulation/test_io.vhd simulation/trace_io.vhd
nvc --std=2008 -e trace_io
nvc --std=2008 -r trace_io
nvc --std=2008 -e test_io
nvc --std=2008 -r test_io

The trace runs first and sets SW9 high and SW8–0 to hex 035. It prints a trace of three instructions: the switch load (IR = 8004), the RAM store (A005) and the RAM load (8205). Each row shows the signals after the numbered rising edge, once they have settled. The next rising edge uses those values. Gaps in the edge numbers skip other instructions.

Use W, ADDR and DOUT to mark the edge that writes RAM word 0030. For the load, mark when DIN changes and when r1 captures the value on BUS. Compare the switch load before and after the repair: does r0 capture the switch word? An idle BUS can appear as XXXX or 0000.

Run the starter first and record the first mismatch. In the last microstep of a load, the destination register receives an old arithmetic result. Trace the bus selector and compare it with the source used after an add. Repair the load in the starter file and rerun the same commands. Continue when you see PASS 512 switch words, run hold, resume and reset.

Build

  1. In the LabsLand Online Editor, choose DE1-SoC for your HDL and the Standard interface.
  2. Create io_cpu, paste the design and set it as the top level.
  3. Choose Synthesize → Upload to FPGA. After editing the design, synthesize and upload it again to test the change on the board.

Test the ports on the board

Run the rows in order. SW9 starts and stops the processor. SW8–0 supply a hexadecimal input word. Predict the LED word, set the switches, then read the lamps and record the word in hex. When a row changes SW9 from 1 to 0, lower only SW9 and wait before changing the data. Pulse KEY0 only in the two rows marked reset.

SW9 SW8–0 (hex) Prediction Board
0 (reset) 000
1 005
1 015
1 035
1 1E0
1 1FF
1 1DF
1 01A
0 01A
0 007
1 007
0 000
0 (reset) 000
1 009

Which action cleared the output register while the processor was stopped?

Describe one observation that distinguishes a masked input from a direct wire between the switches and lamps. Explain why changing the switches during a halt leaves the output register unchanged.

Assemble a change

Change and r1,#31 to and r1,#63 in simulation/switch_mask.s. Predict what will happen to LED5 when you change the input from 015 to 035 (hex). Use the included FPGAcademy assembler and the LabsLand RAM loader to regenerate the HDL. Keep the output in a new file.

If the assembler reports an error, correct the indicated line and assemble again before loading the memory image. A failed build leaves any previous .mif in place.

On Windows with the Python launcher, use py -3 wherever a command starts with python3.

Verilog

python3 simulation/sbasm.py simulation/switch_mask.s switch_mask.mif
python3 simulation/load_program.py switch_mask.mif starter/io_cpu.v --output my_io_cpu.v

SystemVerilog

python3 simulation/sbasm.py simulation/switch_mask.s switch_mask.mif
python3 simulation/load_program.py switch_mask.mif starter/io_cpu.sv --output my_io_cpu.sv

VHDL

python3 simulation/sbasm.py simulation/switch_mask.s switch_mask.mif
python3 simulation/load_program.py switch_mask.mif starter/io_cpu.vhd --output my_io_cpu.vhd

Use your repaired HDL as the input to the loader. In a second copy of the worksheet, replace the contents of the original HDL file with the generated file, keeping its name. Change EXPECTED_MASK from 31 to 63 in the testbench and rerun the simulation. Build the new design and program the board using the same workflow.

Start with SW9 low and pulse KEY0. Use the table to test your new program. Record just LED5 (0 or 1). When you halt, leave 035 on the switches until the lamps have settled.

SW9 SW8–0 (hex) Predicted LED5 Board LED5
0 000
1 015
1 035
0 035
0 015
0 (reset) 015

Hand in both bus timelines, your edited instruction and the two completed tables.

Adapted from the MIT-licensed FPGAcademy processor scaffold. The board interface, memory and exercise are by LabsLand. Verilog handout · VHDL handout · MIT