Skip to main content
@shmVirus

Computer Arithmetic

Build signed adders, sequential and array multipliers, Booth recoding, and restoring and non-restoring dividers from registers and microoperations.

Updated

Learning objectives

  • Distinguish sign-magnitude and two's-complement arithmetic
  • Trace sign-magnitude addition and subtraction through all sign cases
  • Explain add-and-shift, Booth, and array multiplication
  • Trace restoring and non-restoring binary division
  • Connect arithmetic algorithms to registers, control states, and flags

Prerequisites

  • Datapath and Microoperations
  • Instruction Set Design

Arithmetic hardware is an algorithm made physical: registers hold the current state, an adder performs one transformation, a shifter aligns partial results, and a controller repeats the correct microoperation. The same method explains addition, multiplication, and division.

TermDefinition
RepresentationA bit pattern convention used to encode a mathematical value.
Partial productOne intermediate contribution to a multiplication result.
Partial remainderThe evolving remainder held while division consumes dividend bits.
CarryA bit leaving an unsigned position or word boundary.
OverflowA signed result that lies outside the range of its representation.
Arithmetic shiftA shift whose inserted bit preserves the signed interpretation.

Signed Number Representations

For an nn-bit sign-magnitude number, the most significant bit is the sign and the remaining n1n-1 bits store the magnitude. Thus 0 0101 is +5+5 and 1 0101 is 5-5. There are two encodings of zero.

For an nn-bit two’s-complement number, the range is

2n1x2n11.-2^{n-1}\le x\le 2^{n-1}-1.

Negation means complementing every bit and adding one. In 8 bits, +13=00001101+13=\mathtt{00001101} and 13=11110011-13=\mathtt{11110011}. Two’s complement has one zero, uses the same adder for signed and unsigned addition, and is therefore the usual machine representation.

FlagMeaning after an nn-bit operation
CCarry out of the most significant bit; useful for unsigned arithmetic
VSigned overflow: two same-sign operands produced the wrong-sign result
ZEvery result bit is zero
NMost significant result bit is one

For addition, V=Cn1CnV=C_{n-1}\oplus C_n, the XOR of the carry into and out of the sign position. Carry and overflow answer different questions: 11111111 + 1 has unsigned carry, while 01111111 + 1 has signed overflow.

Sign-Magnitude Addition and Subtraction

Let As,BsA_s,B_s be the sign bits and Am,BmA_m,B_m the magnitudes. Convert subtraction into addition by toggling the sign of the second operand:

AB=A+(B),BsBsSUB.A-B=A+(-B),\qquad B_s\leftarrow B_s\oplus \text{SUB}.
Eight sign-magnitude addition and subtraction cases grouped by equal and unequal effective signs
After subtraction changes the effective sign of $B$, only two cases remain: equal signs add magnitudes; unequal signs subtract the smaller magnitude from the larger.
Effective signsMagnitude operationResult signOverflow
As=BsA_s=B_sAm+BmA_m+B_mAsA_sCarry from magnitude field
AsBs, Am>BmA_s\ne B_s,\ A_m>B_mAmBmA_m-B_mAsA_sNo
AsBs, Bm>AmA_s\ne B_s,\ B_m>A_mBmAmB_m-A_mBsB_sNo
Am=BmA_m=B_m with unequal signsZeroCanonical 0No

Example with one sign bit and four magnitude bits:

  • 0 1001 + 1 0101 means +9+(5)+9+(-5). Unequal signs select magnitude subtraction: 10010101=01001001-0101=0100, so the result is 0 0100 or +4+4.
  • 1 0111 - 0 0101 means 7+(5)-7+(-5). Equal effective signs select addition: 0111+0101=11000111+0101=1100, so the result is 1 1100 or 12-12.
Flowchart for sign-magnitude add and subtract including sign comparison, magnitude comparison, complement, add, overflow, and zero normalization
The flowchart is a control algorithm. Its comparisons and branches become status inputs and controller states in hardware.

Unsigned Add-and-Shift Multiplication

The pencil-and-paper product

          1011   (11)
        × 1101   (13)
        ------
          1011
         0000
        1011
       1011
       --------
       10001111  (143)

adds the multiplicand wherever a multiplier bit is one. Hardware reuses one adder:

  1. Clear accumulator AA and load multiplier QQ, multiplicand MM, and count nn.
  2. If Q0=1Q_0=1, perform AA+MA\leftarrow A+M.
  3. Shift the combined pair AQAQ right once.
  4. Decrement the count; repeat until zero.
Book-faithful add-and-shift binary multiplication flowchart with Q zero test, add, shift, and counter loop
The least-significant multiplier bit decides whether the current aligned multiplicand contributes to the product.
Accumulator and multiplier registers shifting together through one adder
After $n$ cycles, the high half of the $2n$-bit product is in $A$ and the low half is in $Q$.

For M=1011M=1011 and Q=1101Q=1101, the combined contents progress through four add/shift iterations and finish at AQ=100011112=14310AQ=1000\,1111_2=143_{10}.

Booth Multiplication

Booth’s algorithm multiplies signed two’s-complement numbers and compresses runs of ones. Append one bit Q1=0Q_{-1}=0, examine (Q0,Q1)(Q_0,Q_{-1}), then perform an arithmetic right shift of the combined AQQ1AQ Q_{-1}.

Q0Q1Q_0Q_{-1}Before the shiftInterpretation
00 or 11No addInside a constant run
01AA+MA\leftarrow A+MEnd of a run of ones
10AAMA\leftarrow A-MStart of a run of ones
Booth multiplier registers, add subtract unit, pair decoder, counter, and arithmetic shift path
The extra bit remembers the previous multiplier bit; the pair detects transitions at the edges of a run of ones.

Worked example: (9)(13)=117(-9)(-13)=117

Use five-bit two’s-complement operands: M=9=10111M=-9=\mathtt{10111} and initially A=00000A=\mathtt{00000}, Q=13=10011Q=-13=\mathtt{10011}, Q1=0Q_{-1}=0.

CyclePairOperation before ASRAfter arithmetic right shift: AA QQ Q1Q_{-1}
110AAM=01001A\leftarrow A-M=0100100100 11001 1
211No add00010 01100 1
301AA+M=11001A\leftarrow A+M=1100111100 10110 0
400No add11110 01011 0
510AAM=00111A\leftarrow A-M=0011100011 10101 1

The product is the ten-bit value AQ=00011101012=11710AQ=\mathtt{0001110101}_2=117_{10}. Arithmetic shift is essential because it replicates the sign of AA.

Combinational Array Multiplication

An array multiplier generates every partial product in parallel with AND gates and sums aligned columns with a regular adder array.

Two by two gate-level multiplier and generalized j by k array multiplier with partial products and adder rows
A regular layout is fast and easy to scale, but it uses much more hardware than a sequential add-and-shift multiplier.

A jj-bit by kk-bit unsigned array requires jkjk AND gates for partial products and can be organized with (j1)(j-1) kk-bit adders. The product width is j+kj+k bits. A 4×34\times3 array therefore uses 12 AND gates and two 4-bit adder rows, producing a seven-bit product.

Unsigned Division

For dividend QQ, divisor MM, quotient QoutQ_\text{out}, and remainder AA,

dividend=divisor×quotient+remainder,0remainder<divisor.\text{dividend}=\text{divisor}\times\text{quotient}+\text{remainder}, \qquad 0\le\text{remainder}<\text{divisor}.

Both standard algorithms align the next dividend bit by shifting the combined AQAQ register left.

Restoring division

Each cycle shifts left, tentatively subtracts MM, and restores the old remainder when the result is negative:

  1. (A,Q)shl(A,Q)(A,Q)\leftarrow\operatorname{shl}(A,Q).
  2. AAMA\leftarrow A-M.
  3. If A<0A<0, set Q00Q_0\leftarrow0 and restore AA+MA\leftarrow A+M; otherwise set Q01Q_0\leftarrow1.

Non-restoring division

Avoid the immediate restoration. If the previous partial remainder is nonnegative, shift and subtract; if it is negative, shift and add. Set the quotient bit from the new sign. After the final cycle, add MM once if A<0A<0.

Parallel restoring and non-restoring division flowcharts sharing A Q and divisor registers
Restoring corrects a failed subtraction immediately. Non-restoring carries the negative partial remainder into the next cycle and corrects it with addition.

Worked example: 11/311/3

Using Q=1011Q=\mathtt{1011} and M=0011M=\mathtt{0011}:

CycleRestoring result after decision: A,QA,QQuotient bit
Start00000 1011
100001 0110 (subtract was negative, restored)0
200010 1100 (subtract was negative, restored)0
300010 10011
400010 00111

Thus quotient Q=0011=3Q=\mathtt{0011}=3 and remainder A=00010=2A=\mathtt{00010}=2, confirming 11=3(3)+211=3(3)+2. Non-restoring division reaches the same result with partial remainders 11110, 11111, 00010, and 00010; the first two negative states avoid two immediate restore operations.

Choosing an Arithmetic Organization

OrganizationHardwareLatencyBest fit
Sequential add/shiftOne adder and registersAbout nn cyclesSmall, low-power datapath
Booth sequentialAdder/subtractor and transition logicnn cycles, fewer useful additionsSigned operands and long runs
Combinational arrayMany AND gates and addersOne long combinational pathHigh throughput
Pipelined arrayArray plus stage registersSeveral stages; one result/cycle after fillStreaming multiplication

Check Your Understanding

  1. Why can C=1 while V=0, and vice versa?
  2. Trace 0 0110 - 1 0011 in sign-magnitude representation.
  3. Which Booth action corresponds to pair 01?
  4. Why must the combined register shift left during division but right during add-and-shift multiplication?
  5. For 13/413/4, what quotient and remainder must a correct divider produce?
Answers
  1. Carry describes the unsigned range; overflow describes the signed two’s-complement range.
  2. It becomes +6+(+3)=+9+6+(+3)=+9, so the result is 0 1001.
  3. Add MM to AA, then arithmetic-shift right.
  4. Multiplication consumes low multiplier bits while accumulating high product bits; division brings high dividend bits into the partial remainder.
  5. Quotient 3 and remainder 1.