Lab 9

Single-step a 16-bit processor

Follow one instruction from the input bus to a destination register. This processor has eight 16-bit registers, a shared bus, a saved first operand and an arithmetic result register. Sketch the path taken by the value in r1 during sub r1,r0. At which clock edge can another instruction safely read the new r1?

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 step_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

Decode the words

In bits 15–13 the opcodes for move, move-top, add and subtract are 0, 1, 2 and 3. Bit 12 selects an immediate operand. Bits 11–9 select the destination. A register operand uses bits 2–0 for its source. A signed immediate occupies bits 8–0. Move-top places the low eight immediate bits in the high byte and clears the low byte. Decode the five words in the table before running them.

Build

  1. In the LabsLand Online Editor, choose DE1-SoC for your HDL and the Standard interface.
  2. Create step_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.

The file contains both the processor and a board interface. The arithmetic unit is 16 bits wide. In the starter, using a negative nine-bit literal can give a surprising result. Run the simulation below with the starter. For the first failing instruction, compare the high byte of the destination with the high byte you predicted. Repair the operand conversion, rerun the test, then build your corrected design for the board.

Simulate

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

The test executes 512 instructions, checks the handshake at each phase and reads all eight registers after each write. Run the starter first and keep one mismatch for your report.

test_cpu.v

test_cpu.vhd

Verilog

iverilog -g2005 -s test_cpu -o bench starter/step_cpu.v simulation/test_cpu.v
vvp bench

SystemVerilog

iverilog -g2012 -s test_cpu -o bench starter/step_cpu.sv simulation/test_cpu.v
vvp bench

VHDL

nvc --std=2008 -a starter/step_cpu.vhd simulation/test_cpu.vhd
nvc --std=2008 -e test_cpu
nvc --std=2008 -r test_cpu

Single-step on the board

Press KEY3 to reset. For each instruction set SW7–0 to its high byte and press and release KEY1. Set the low byte and press and release KEY2. With the instruction latched, SW2–0 can select a register for inspection. Select the destination. Leave SW8 low to read its low byte on LED7–0. Raise SW8 to read the high byte.

Raise SW9 and press and release KEY0 once to fetch. Lower SW9. Each time you press and release KEY0, the processor advances on release. Use one more press and release for a move, or three for arithmetic. Watch LED8, which indicates an active instruction, and LED9, which tells you that the next edge will write the destination. Try an extra clock while SW9 is low and the processor is idle.

Word Instruction Prediction (hex) Camera (high/low) Write edge
11FD mv r0,#−3
5005 add r0,#5
3234 mvt r1,#0x34
6200 sub r1,r0
0E01 mv r7,r1

For 6200, select r1 and keep SW8 low. Raise SW9 for the first release only. Record the lamps after each release. After the last row, raise SW8 to read the high byte without clocking again.

KEY0 release LED9 LED8 LED7–0 (hex)
1 · Fetch
2 · Save operand
3 · Calculate
4 · Write r1

On which release does LED9 announce the write? On which release does the new low byte appear? Explain why a later switch change cannot replace an instruction that has already been fetched. Give a camera reading that distinguishes zero extension from sign extension.

Original LabsLand processor, board interface and exercise following FPGAcademy Digital Logic Lab 9, Part I. Verilog handout · VHDL handout · MIT