Signed versus Unsigned Comparison ALU
The bit pattern 8'hFF is 255 unsigned and -1 signed. Compare signed data with an unsigned comparator and a negative offset looks like a huge positive number.
This module computes greater than and equality comparisons for both signed and unsigned 8-bit integers. To minimize silicon area, the design must compute these comparisons using only a single subtractor and logical flag checks (Zero, Negative, Overflow, and Borrow). The module takes two 8-bit operands, a and b, and produces three boolean flags: sgt (signed greater than), ugt (unsigned greater than), and eq (equal).
The circuit is purely combinational. There is no clock or reset signal. Output ports must reflect the current inputs immediately and must not be registered.
| Signal | Direction | Width | Description |
|---|---|---|---|
a |
input | 8 | First operand; purely combinational |
b |
input | 8 | Second operand; purely combinational |
sgt |
output | 1 | Active-high signed greater than flag; 1 if a > b |
ugt |
output | 1 | Active-high unsigned greater than flag; 1 if a > b |
eq |
output | 1 | Active-high equality flag; 1 if a == b |
Constraints
- The circuit is purely combinational; outputs must not be registered.
- Input bit widths are exactly 8 bits; output bit widths are exactly 1 bit.
- The design must derive all outputs from a single subtraction operation.
- Do not use the built-in Verilog comparison operators to solve the core logic; construct the outputs using the subtractor condition flags.
Topics
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.
Free to solve. A Codiode account keeps your progress.
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 Datapath Design
Problem 2 of 27 in the Datapath Design track.
Related problems
Browse all problems · Verilog practice problems · Learning tracks