Codiode

Signed Arithmetic Operations

HardVerilog / SystemVerilogBuild2 solved

Verilog treats a plain vector as unsigned. When the bits are really two's complement, widening them pads with zeros instead of copying the sign, and the arithmetic goes wrong. You have to say signed explicitly.

The module receives two 8-bit vectors, a and b. These inputs represent two's complement integers but are declared as standard unsigned ports. The circuit performs a signed addition of the two inputs and produces a 9-bit result, sum. The extra bit in the output accommodates the full range of possible values without overflow.

Signal Direction Width Description
a input 8 First operand, representing a two's complement integer
b input 8 Second operand, representing a two's complement integer
sum output 9 Result of the signed addition, fully sign-extended

Constraints

  • The circuit must be purely combinational.
  • The inputs a and b must be treated as signed two's complement values during the addition.
  • The output sum must accurately reflect the mathematical sum of the two signed inputs in a 9-bit two's complement format.
  • Unsigned addition will result in zero-extension and produce incorrect outputs for negative inputs.

Topics

CombinationalArithmeticData Types

Solve this problem

Write the module in Verilog, SystemVerilog or VHDL. Your submission is compiled and simulated against the problem's testbench. You get the waveform back, not a stored answer.

This problem is part of Codiode Pro. The statement above is free to read.

The circuit builder and code editor need a desktop screen. On a phone, read the problem here and open it on a laptop to solve.

Part of Verilog Syntax and Language Basics

Problem 15 of 25 in the Verilog Syntax and Language Basics track.

Related problems

Browse all problems · Verilog practice problems · Learning tracks

Solve this on a laptopSend yourself the link and continue there.