Arithmetic & Math
8-Bit Subtractor with Overflow Detection — L1 Upgrade — L2 Upgrade
8-bit saturating subtractor with sticky underflow flag, asynchronous reset, and synchronous clear.
About this block
Simulate it in the Verilog IDE
8-Bit Subtractor with Overflow Detection — L1 Upgrade — L2 Upgrade is a Verilog reference block in the Arithmetic & Math catalog. Adders, multipliers, dividers, ALUs, and arithmetic datapaths. Marked Easy: a small block you can read, simulate, and synthesize in one sitting.
This IP core implements an 8-bit unsigned saturating subtractor. It is designed for digital signal processing (DSP) applications where safe arithmetic is required without raising exceptions for underflow.
### Key Behavior
- Saturating Arithmetic: If
minuend < subtrahend, the result is clamped to0. - Sticky Flag: A
sat_flagis asserted when an underflow occurs and remains high until explicitly cleared. - Control: Supports asynchronous reset (
rst_n) and synchronous flag clear (clear_sat).
This IP core provides a reliable 8-bit unsigned saturating subtractor with a sticky underflow flag. It ensures that arithmetic operations do not wrap around or produce negative results, instead clamping to zero and signaling the event via sat_flag. This is ideal for DSP pipelines where underflow must be tracked but not interrupt the data flow. The design is fully verified and ready for integration into larger digital systems.
- Choose Open in IDE. RTL Studio loads the packaged workspace for 8-Bit Subtractor with Overflow Detection — L1 Upgrade — L2 Upgrade.
- Read the Verilog module in the editor. The catalog line for this block: 8-bit saturating subtractor with sticky underflow flag, asynchronous reset, and synchronous clear.
- Run the packaged testbench with the in-browser Verilator simulator, then open the VCD in the waveform viewer.
- Run Yosys in the same IDE for a generic netlist. Sky130 liberty mapping is a separate Pro library option.
RTL Studio is the Verilog simulator and IDE around this block: Slang lint, Verilator, VCD waveforms, and Yosys, in the browser. Simulation guide · Yosys guide.
Features
- 8-bit Unsigned Subtraction: Operands range from 0 to 255.
- Underflow Protection: Automatically clamps negative results to zero.
- Sticky Saturation Flag:
sat_flagpersists across clock cycles until cleared, allowing the system to detect past errors. - Robust Control: Asynchronous active-low reset and synchronous clear signal.
- Verified: Fully verified with Icarus Verilog simulations covering edge cases.
Ports
| Port Name | Direction | Width | Description |
|---|---|---|---|
clk | Input | 1 | Clock input |
rst_n | Input | 1 | Active-low asynchronous reset |
clear_sat | Input | 1 | Synchronous clear for saturation flag |
minuend | Input | 8 | Minuend operand |
subtrahend | Input | 8 | Subtrahend operand |
result | Output | 8 | Subtraction result (saturated) |
sat_flag | Output | 1 | Sticky saturation/underflow flag |
Architecture
The module uses a single clocked process to handle reset, clear, and arithmetic operations. It compares the minuend and subtrahend to detect underflow. If underflow occurs, the result is forced to zero and the flag is set. Otherwise, the standard subtraction result is stored. The saturation flag is sticky and only clears on clear_sat or rst_n.
Verification
The testbench (tb/tb_subtractor_saturate_overflow_8bit_sticky_sat_flag.v) covers:
- Basic subtraction (e.g., 10 - 5).
- Underflow saturation (e.g., 5 - 10).
- Sticky flag retention.
- Clear saturation flag functionality.
- Reset behavior.
- Zero and Max operand edge cases.
### Running Simulation
To verify the design, run the testbench using Icarus Verilog:
Expected output includes:
TC1 PASSthroughTC7 PASSINFO: PASS
More in Arithmetic & Math
- 1-Bit Full Adder
- 1-Bit Full Adder — L1 Upgrade — L2 Upgrade
- 1-Bit Half Adder
- 16-Bit Carry-Select Adder
- 16-Bit Signed Adder with Overflow
- 2-Bit Saturating Up/Down Counter — L2 Upgrade
- 32-Bit Count Leading Zeros
- 32-Bit Equality Comparator — L1 Upgrade — L2 Upgrade
- 32-Bit Population Count — L1 Upgrade — L2 Upgrade
- 4-bit Adder-Subtractor with Overflow
- 4-Digit BCD Adder with Carry Propagation — L2 Upgrade
- 4-Input 8-Bit Adder Tree — L2 Upgrade
- 8-Bit Absolute Value — L1 Upgrade
- 8-Bit ALU Slice with Add/Sub and Logic Ops — L2 Upgrade
- 8-Bit Carry-Save Adder (3:2) — L2 Upgrade
- 8-Bit Count Trailing Zeros — L1 Upgrade — L2 Upgrade