The subtract function operates on a 2-byte array. It sets the first byte to the difference of the first byte and the second byte:
f( [ A, B ] ) = [ Q, B ], where A,B,Q ∈ ℤ
Q = A − B
B passes through, unchanged.
The subtraction is transformed into a sum by taking advantage of the fact that A, B, and Q are two’s complement numbers:
A − B = A + -B = A + ~B + 1, where ~ means bitwise inversion.
Its circuit is a modification of the add circuit:
The initial carry-in (far right) serves as the + 1 term of the sum.
The circuit bitwise inverts B twice to retain its value.
The Tetris realization follows.
© 2023 meatfighter.com |