Tell signed overflow from unsigned carry
Online version: https://fpga.labsland.com/altera/digital-logic/lab-06/part-01/
An eight-bit sum has two interpretations. After adding 1 to 7F hexadecimal, what would an unsigned observer say happened? What would someone reading signed two’s-complement numbers say? Build an accumulator that reports both answers.
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/signed_accumulator.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
signed_accumulator. 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/signed_accumulator.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 starter wires the same flag into carry and overflow. Derive when two positive operands can produce a negative result and when two negative operands can produce a positive result. Correct the overflow register.
- Get the starterDownload
signed_accumulator.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 Trace the registers in the worksheet below, then complete the design as its build steps describe. Open
signed_accumulator.qpfand choose Processing → Start Compilation. Quartus writesoutput_files/signed_accumulator.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
Trace the registers
HEX3…2 shows the captured operand A. HEX1…0 shows the accumulated value S. The eight rightmost red LEDs preview the sum of those two registers. When you release KEY1, the board saves that sum into S and samples SW7…0 as the next A. At the same instant, LEDR8 remembers the carry and LEDR9 remembers the signed overflow from the sum just saved.
Build
- In the LabsLand Online Editor, choose DE1-SoC for your HDL and the Standard interface.
- Create
signed_accumulator, 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 starter wires the same flag into carry and overflow. Derive when two positive operands can produce a negative result and when two negative operands can produce a positive result. Correct the overflow register.
Simulate
Extract the worksheet ZIP and run these commands from the folder containing activity.md.
The testbench tries every pair of eight-bit values. It checks carry using the unsigned sum, then checks whether the signed sum fits in eight bits. It also checks all four display digits. Run the starter, record the first pair that fails, and repeat after your correction.
Verilog
iverilog -g2005 -s test_accumulator -o bench starter/signed_accumulator.v simulation/test_accumulator.v
vvp bench
SystemVerilog
iverilog -g2012 -s test_accumulator -o bench starter/signed_accumulator.sv simulation/test_accumulator.v
vvp bench
VHDL
nvc --std=2008 -a starter/signed_accumulator.vhd simulation/test_accumulator.vhd
nvc --std=2008 -e test_accumulator
nvc --std=2008 -r test_accumulator
Work through two sums on the board
Synthesize and upload. Press and release KEY0 to reset both registers and flags. Enter 7F on the switches. Before touching KEY1, check whether either register changed. For each row below, set the switches, press and release KEY1 once, then read the board. Record A, S and the preview on LEDR7–0 in hexadecimal. For carry (C, LEDR8) and signed overflow (V, LEDR9), write 1 for lit or 0 for dark.
| SW7–0 | A | S | LEDR7–0 | C | V |
|---|---|---|---|---|---|
| 7F | |||||
| 01 | |||||
| FF | |||||
| 80 | |||||
| 00 |
Reset again with KEY0. Set the switches to each value below and release KEY1 once per row.
| SW7–0 | A | S | LEDR7–0 | C | V |
|---|---|---|---|---|---|
| FF | |||||
| 01 | |||||
| 00 |
On which release does unsigned addition wrap to zero without signed overflow? Hand in both traces and explain why the preview LEDs sometimes disagree with the stored sum.
Original LabsLand activity following FPGAcademy Digital Logic Lab 6, Part I. Verilog PDF · VHDL PDF · MIT
