CodiodeCodiode
Home
Problem Solving
Skill Tracks
My Assignments
Contests
Leaderboard
Community
Settings
Codiode/Problems/Combinational Logic

Signed Arithmetic Operations

HardVerilog / SystemVerilogBuild

Digital signal processing blocks frequently receive raw, untyped bit vectors from memory or system buses. When performing arithmetic operations, the hardware must explicitly interpret these raw vectors as two's complement signed values to ensure proper sign extension and correct mathematical results. Without explicit casting, Verilog defaults to treating all standard vectors as unsigned, which results in zero-padding instead of sign-extension during bit-width expansion.

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 a real testbench — you get the waveform back, not a stored answer.

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

Sign in to solveSee what Pro unlocks

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.

Related problems

  • Single Continuous AssignmentEasy
  • Basic Vector ConcatenationEasy
  • Ternary Operator MuxEasy
  • Underscores for ReadabilityEasy
  • Left Hand Side ConcatenationEasy
  • Inout Port MechanicsEasy
  • Explicit Binary LiteralsEasy
  • Vector Port EndiannessEasy

Browse all problems · Learning tracks