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.
| Term | Definition |
|---|---|
| Representation | A bit pattern convention used to encode a mathematical value. |
| Partial product | One intermediate contribution to a multiplication result. |
| Partial remainder | The evolving remainder held while division consumes dividend bits. |
| Carry | A bit leaving an unsigned position or word boundary. |
| Overflow | A signed result that lies outside the range of its representation. |
| Arithmetic shift | A shift whose inserted bit preserves the signed interpretation. |
Signed Number Representations
For an -bit sign-magnitude number, the most significant bit is the sign and the remaining bits store the magnitude. Thus 0 0101 is and 1 0101 is . There are two encodings of zero.
For an -bit two’s-complement number, the range is
Negation means complementing every bit and adding one. In 8 bits, and . Two’s complement has one zero, uses the same adder for signed and unsigned addition, and is therefore the usual machine representation.
| Flag | Meaning after an -bit operation |
|---|---|
C | Carry out of the most significant bit; useful for unsigned arithmetic |
V | Signed overflow: two same-sign operands produced the wrong-sign result |
Z | Every result bit is zero |
N | Most significant result bit is one |
For addition, , 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 be the sign bits and the magnitudes. Convert subtraction into addition by toggling the sign of the second operand:
| Effective signs | Magnitude operation | Result sign | Overflow |
|---|---|---|---|
| Carry from magnitude field | |||
| No | |||
| No | |||
| with unequal signs | Zero | Canonical 0 | No |
Example with one sign bit and four magnitude bits:
0 1001 + 1 0101means . Unequal signs select magnitude subtraction: , so the result is0 0100or .1 0111 - 0 0101means . Equal effective signs select addition: , so the result is1 1100or .
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:
- Clear accumulator and load multiplier , multiplicand , and count .
- If , perform .
- Shift the combined pair right once.
- Decrement the count; repeat until zero.
For and , the combined contents progress through four add/shift iterations and finish at .
Booth Multiplication
Booth’s algorithm multiplies signed two’s-complement numbers and compresses runs of ones. Append one bit , examine , then perform an arithmetic right shift of the combined .
| Before the shift | Interpretation | |
|---|---|---|
00 or 11 | No add | Inside a constant run |
01 | End of a run of ones | |
10 | Start of a run of ones |
Worked example:
Use five-bit two’s-complement operands: and initially , , .
| Cycle | Pair | Operation before ASR | After arithmetic right shift: |
|---|---|---|---|
| 1 | 10 | 00100 11001 1 | |
| 2 | 11 | No add | 00010 01100 1 |
| 3 | 01 | 11100 10110 0 | |
| 4 | 00 | No add | 11110 01011 0 |
| 5 | 10 | 00011 10101 1 |
The product is the ten-bit value . Arithmetic shift is essential because it replicates the sign of .
Combinational Array Multiplication
An array multiplier generates every partial product in parallel with AND gates and sums aligned columns with a regular adder array.
A -bit by -bit unsigned array requires AND gates for partial products and can be organized with -bit adders. The product width is bits. A array therefore uses 12 AND gates and two 4-bit adder rows, producing a seven-bit product.
Unsigned Division
For dividend , divisor , quotient , and remainder ,
Both standard algorithms align the next dividend bit by shifting the combined register left.
Restoring division
Each cycle shifts left, tentatively subtracts , and restores the old remainder when the result is negative:
- .
- .
- If , set and restore ; otherwise set .
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 once if .
Worked example:
Using and :
| Cycle | Restoring result after decision: | Quotient bit |
|---|---|---|
| Start | 00000 1011 | — |
| 1 | 00001 0110 (subtract was negative, restored) | 0 |
| 2 | 00010 1100 (subtract was negative, restored) | 0 |
| 3 | 00010 1001 | 1 |
| 4 | 00010 0011 | 1 |
Thus quotient and remainder , confirming . 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
| Organization | Hardware | Latency | Best fit |
|---|---|---|---|
| Sequential add/shift | One adder and registers | About cycles | Small, low-power datapath |
| Booth sequential | Adder/subtractor and transition logic | cycles, fewer useful additions | Signed operands and long runs |
| Combinational array | Many AND gates and adders | One long combinational path | High throughput |
| Pipelined array | Array plus stage registers | Several stages; one result/cycle after fill | Streaming multiplication |
Check Your Understanding
- Why can
C=1whileV=0, and vice versa? - Trace
0 0110 - 1 0011in sign-magnitude representation. - Which Booth action corresponds to pair
01? - Why must the combined register shift left during division but right during add-and-shift multiplication?
- For , what quotient and remainder must a correct divider produce?
Answers
- Carry describes the unsigned range; overflow describes the signed two’s-complement range.
- It becomes , so the result is
0 1001. - Add to , then arithmetic-shift right.
- Multiplication consumes low multiplier bits while accumulating high product bits; division brings high dividend bits into the partial remainder.
- Quotient 3 and remainder 1.