Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

This sits between From Gates to an ALU and the Bit Lab. It answers the question the lab’s CMP raises the first time you see it: how does 3 − 5 come out as 0xFE, why is that the right answer, and where is the subtractor? Every section shows the same A − B, which you can change at the top or by tapping bits.

What it covers

  1. A byte wraps around. A 16-position wheel at 4 bits with unsigned labels outside and signed labels inside. Subtracting steps back around the wheel, and when the steps pass zero the register lands near the top of the range. The same pattern is 14 to one reading and −2 to the other.

  2. Negating: NOT, then add 1. Stepping back B places is stepping forward 16 − B. Inverting every bit of B gives 15 − B, so NOT B + 1 is 16 − B, which is −B. Shown as bit rows for the current B.

  3. The adder does it. Feed NOT B into the adder with the carry-in set to 1 and it computes A − B. Tap bits in A or B and watch the carries; the carry out of the top bit is the borrow signal inverted, which is why ARM’s C = 1 means no borrow.

  4. The same subtraction on paper. The method for working in decimal: compute, fit the answer into the width on a number line that shows the wrap as a shift of one wheel size, then convert with the top bit worth minus its place value. It always agrees with the adder, and says which flag an ALU would raise when the answer did not fit.

Next