Components / Arithmetic
Subtractor Component in Logisim
Computes N-bit binary subtraction (A - B - bin), producing an N-bit Difference (Diff) and a 1-bit Borrow-Out (bout).
| Library | Arithmetic |
|---|---|
| Type name | Subtractor |
| Pins and defaults | a A (-40, -10), b B (-40, 10), cin bin (-20, -20), out0 Diff (0, 0), cout bout (-20, 20), width 1..32 |
How the Subtractor Works in Logisim
The Subtractor computes A - B - bin across 1 to 32 bits, where A is the minuend (upper-left pin), B is the subtrahend (lower-left pin), and bin is the 1-bit Borrow-In on the top edge.
Like the Adder’s cin, an unconnected Borrow-In (bin = Z) defaults to 0 so the component computes A - B directly. When the unsigned value of A is less than B + bin, the result wraps modulo 2^N (producing the two's complement difference) and the bottom Borrow-Out pin (bout) asserts 1.
Tip: In an ALU, you can either use a dedicated Subtractor component or share a single Adder by multiplexing B with ~B and setting cin = 1.
Subtractor Pins & Pinout
| Pin | Direction | Width | Location & Role |
|---|---|---|---|
| a (A) | Input (Upper-left) | 1–32 bits | Offset (-40, -10). Minuend operand A. |
| b (B) | Input (Lower-left) | 1–32 bits | Offset (-40, 10). Subtrahend operand B. |
| cin (bin) | Input (Top edge) | 1 bit | Offset (-20, -20). Borrow-In bit (defaults to 0 when unconnected/Z). |
| out0 (Diff) | Output (Right edge) | 1–32 bits | Offset (0, 0). N-bit difference (A - B - bin) mod 2^N. |
| cout (bout) | Output (Bottom edge) | 1 bit | Offset (-20, 20). Borrow-Out bit (1 when A < B + bin). |
Subtractor Truth Table & Behavior
| A | B | bin | Diff (A - B) | bout (Borrow) |
|---|---|---|---|---|
| 0 | 0 | 0 | 0 | 0 |
| 0 | 1 | 0 | 1 | 1 (borrowed) |
| 1 | 0 | 0 | 1 | 0 |
| 1 | 1 | 0 | 0 | 0 |