Prev Problem
Next Problem

69. Binary Subtractor

Compute a − b by adding a + (~b + 1) (two’s complement of b). Also report borrow-out (bout) for unsigned subtraction.

Requirements

  • Module: sub4_2c
  • Inputs: a[3:0], b[3:0]
  • Outputs: diff[3:0], bout
  • Keep it fully combinational (no clocks, no delays).
  • You may implement with a single assign, or structurally via a 4-bit adder (with cin=1, b inverted).

Behavior

  • Inputs: a[3:0], b[3:0]
  • Outputs: diff[3:0] = a − b (mod 16) bout = 1 iff borrow occurs (i.e., a < b)
  • Relationship: Let {cout, diff} = a + (~b) + 1. Then bout = ~cout.