Single-step a 16-bit processor
Online version: https://fpga.labsland.com/altera/digital-logic/lab-09/part-01/
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
LabsLand Online Editor · DE1-SoC
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.
Build
- From the extracted worksheet folder, open
starter/step_cpu.qpfin the selected release of Quartus Prime Lite with Cyclone V support. The project-only download has the QPF at its root. - Edit the HDL file for
step_cpu. If the exercise generates a new HDL file, copy its contents into that same project file. - Choose Processing → Start Compilation. Check the Fitter report for device 5CSEMA5F31C6.
- In the LabsLand bitstream upload lab, choose Standard and upload
output_files/step_cpu.sof. Wait for programming confirmation before using the controls. - If your course uses a LabsLand classroom, the upload opens a firmware library instead: check that your SOF is selected and choose Enter board with selected firmware.
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.
- Get the starterDownload
step_cpu.v - Open the LabsLand Online EditorOpen the lab Choose DE1-SoC · Verilog when you open the lab. LabsLand asks you to sign in. Use the access your course or institution provides.
- Follow the worksheetPredict first, then build, read the board and hand in. The build steps are below.
- Install Quartus Prime Lite with Cyclone V supportSkip this if it is already installed.
- Download the activityDownload worksheet and Quartus project Includes the worksheet, the Quartus project and the simulation files.
- Complete the design and compileStart with Decode the words in the worksheet below, then complete the design as its build steps describe. Open
step_cpu.qpfand choose Processing → Start Compilation. Quartus writesoutput_files/step_cpu.sof. - Upload the bitstream to LabsLandUpload bitstream LabsLand asks you to sign in. Use the access your course or institution provides.
Already compiled? Upload your .sof directly
Starter files · Verilog · VHDL · SystemVerilog
Worksheet and starter (.zip) for offline work or printing
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
- In the LabsLand Online Editor, choose DE1-SoC for your HDL and the Standard interface.
- Create
step_cpu, paste the design and set it as the top level. - 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.
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
