Module 1a Slides
Module 1a Slides
Topics
Arithmetic
Signed and unsigned numbers
Addition and Subtraction
Logical operations
ALU: arithmetic and logic unit
Multiply
Divide
Floating Point
notation
add
multiply
32 ALU
result
32
32
TU/e Processor Design 5Z032 3
Binary numbers (1)
Bits have no inherent meaning (no semantics)
Decimal number system, e.g.:
4382 = 4x103 + 3x102 + 8x101 + 2x100
Can use arbitrary base g; value of digit c at position i:
c x gi
Binary numbers (base 2)
n-1 n-2 … 1 0 position
1100 -4 12 positive
4 0100
negative
11
-5 5
1011 0101
10
-6 9 6
1010 8 0110
-7 7
-8
1001 0111
1000
1100 -4 12 positive
4 0100
negative
11
-5 5
1011 0101
10
-6 9 6
1010 8 0110
-7 7
-8
1001 0111
1000
1100 -4 12 positive
4 0100
negative
11
-5 5
1011 0101
10
-6 9 6
1010 8 0110
-7 7
-8
1001 0111
1000
1100 -4 12 positive
4 0100
negative
11
-5 5
1011 0101
10
-6 9 6
1010 8 0110
-7 7
-8
1001 0111
1000
1100 -4 12 positive
4 0100
negative
11
-5 5
1011 0101
10
-6 9 6
1010 8 0110
-7 7
-8
1001 0111
1000
Proof:
a + a = 1111.1111b = -1 d =>
-a = a + 1
Give truth-table
operation
a result
b
CarryOut
How could we build a 1-bit ALU for add, and, and or?
How could we build a 32-bit ALU?
TU/e Processor Design 5Z032 23
Building a 32 bit ALU
CarryIn Operation
a0 CarryIn
Operation ALU0
Result0
b0
CarryIn CarryOut
a a1 CarryIn
0 ALU1
Result1
b1
CarryOut
1
Result
a2 CarryIn
Result2
ALU2
b2
2 CarryOut
b
CarryOut
a31 CarryIn
Result31
ALU31
b31
a
0
1
Result
b 0 2
CarryOut
TU/e Processor Design 5Z032 25
ALU symbol
operation
32
a
zero
32
ALU result
overflow
32
b
carry-out
0010 (multiplicand)
__*_1011 (multiplier)
First implementation
Product initialized to 0 Multiplier0 = 1 1. Test Multiplier0 = 0
Multiplier0
64 bits
Yes: 32 repetitions
Done
32 bits
2. Shift the Product register right 1 bit
Multiplier
32-bit ALU Shift right
3. Shift the Multiplier register right 1 bit
32 bits
Shift right
Product Control test No: < 32 repetitions
Write 32nd repetition?
64 bits
Yes: 32 repetitions
Done
Final version
Product initialized with multiplier Product0 = 1 1. Test Product0 = 0
Product0
Multiplicand
1a. Add multiplicand to the left half of
the product and place the result in
32 bits the left half of the Product register
32-bit ALU
2. Shift the Product register right 1 bit
Yes: 32 repetitions
Done
Booth’s algorithm is a powerful algorithm that is used for signed multiplication. It generates a 2n bit product
for two n bit signed numbers.
35
Booth’s Algorithm (2)
Booth’s algorithm works for signed 2’s complement as
well (without any modification)
Proof: let’s multiply b * a
(ai-1 - ai ) indicates what to do: 0 : do nothing
+1: add b
-1 : subtract
31
We get b*a = i−1 i
( a
i =0
− a ) b 2 i
=
30
i
b a31 −2 + ai 2
31
i =0
37
Booth’s algorithm
Set the Multiplicand and Multiplier binary bits as M and Q, respectively.
Initially, we set the AC and Qn + 1 registers value to 0.
SC represents the number of Multiplier bits (Q), and it is a sequence counter that is
continuously decremented till equal to the number of bits (n) or reached to 0.
A Qn represents the last bit of the Q, and the Qn+1 shows the incremented bit of Qn
by 1.
On each cycle of the booth algorithm, Qn and Qn + 1 bits will be checked on the
following parameters as follows:
When two bits Qn and Qn + 1 are 00 or 11, we simply perform the arithmetic shift
right operation (ashr) to the partial product AC. And the bits of Qn and Qn + 1 is
incremented by 1 bit.
If the bits of Qn and Qn + 1 is shows to 01, the multiplicand bits (M) will be added
to the AC (Accumulator register). After that, we perform the right shift operation to
the AC and QR bits by 1.
If the bits of Qn and Qn + 1 is shows to 10, the multiplicand bits (M) will be
subtracted from the AC (Accumulator register). After that, we perform the right
shift operation to the AC and QR bits by 1.
The operation continuously works till we reached n - 1 bit in the booth algorithm.
Results of the Multiplication binary bits will be stored in the AC and QR registers.
38
Shift operation
1. RSC (Right Shift Circular)
It shifts the right-most bit of the binary number, and then
it is added to the beginning of the binary bits.
0 1 End of 1s Add
multiplicand
0 0 Middle of 0s nothing
Dividend
Divisor 1000/1001010\1001 Quotient
-1000
10
101
1010
-1000
10 Remainder
Division (2)
1. Substract the Divisor register from the
Remainder register and place the
result in the Remainder register
Implementation:
>= 0 <0
Test Remainder
2.a Shift the Quotient register 2.b Restore the original value by
to the left, setting the adding the Divisor register. Also,
rightmost bit to 1 shift a 1 into the Quotient register
Divisor
Shift right Shift Divisor Register right 1 bit
64 bits
Quotient no
64-bit ALU
Shift left 33rd repetition?
32 bits
55
Non –Restoring Division algorithm
Dividend = 11
Divisor = 3
-M = 11101
Example:
decimal: -.75 = -3/4 = -3/22
binary : -.11 = -1.1 x 2-1
floating point: exponent = -1+bias = 126 = 01111110
IEEE single precision:
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
1 0 1 1 1 1 1 1 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0000000000