Lab 6

Tell signed overflow from unsigned carry

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

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 signed_accumulator.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

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

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

test_accumulator.v

test_accumulator.vhd

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