Module 4 Coa
Module 4 Coa
Arithmetic unit
Basic Processing Unit
Module 4
Text book 1: Chapter 2- 2.1,
Chapter 6 – 6.3 to 6.6,
Chapter 7- 7.1 to 7.3
Outline
Integer arithmetic:
• Numbers
• Arithmetic operations and characters
• Overflow in integer arithmetic
Arithmetic unit:
• Multiplication of two numbers
• A signed operand multiplication
• Booth algorithm
• Fast Multiplication-Bit pair recoding and CSA – integer division
Basic Processing Unit:
• Fundamental concepts
• Execution of complete instruction
• Multiple bus organization
2
Number, Arithmetic Operations
• Signed Integer
• 3 major representations:
Sign and magnitude
One’s complement
Two’s complement
• Assumptions:
4-bit machine word
16 different values can be represented
Roughly half are positive, half are negative
3
Binary, Signed-Integer Representations
B Values represented
Sign and
b3 b2b1b0 magnitude 1's complement 2's complement
0 1 1 1 +7 +7 +7
0 1 1 0 +6 +6 +6
0 1 0 1 +5 +5 +5
0 1 0 0 +4 +4 +4
0 0 1 1 +3 +3 +3
0 0 1 0 +2 +2 +2
0 0 0 1 +1 +1 +1
0 0 0 0 +0 +0 +0
1 0 0 0 -0 -7 -8
1 0 0 1 -1 -6 -7
1 0 1 0 -2 -5 -6
1 0 1 1 -3 -4 -5
1 1 0 0 -4 -3 -4
1 1 0 1 -5 -2 -3
1 1 1 0 -6 -1 -2
1 1 1 1 -7 -0 -1
4
Addition and Subtraction – 2’s Complement
4 0100 -4 1100
The technique works for the computation of (a+b) mod N for any
positive numbers a and b to perform addition, locate A nd move b in
clockwise direction to arrive at (a+b) mod 16 6
Two’s Complement Representation
-1 +0
-2 1111 0000 +1
1110 0001
-3 +2 +
1101 0010
-4 1100 0011 +3 0 100 = + 4
Ignoring the carry out is the natural result of using Mod N arithmetic
7
Addition and Subtraction of signed numbers
8
9
Overflow in Integer arithmetic
• When the result of the arithmetic operation is outside the representable range,
an arithmetic overflow occurs.
• When adding unsigned numbers the carry out Cn from the MSB position serves as
the overflow indicator.
• Ex : adding +7 and +4 output is 1011, which is the code for -5
• -4 and -6 addition result is 0110=+6
• 2 conclusions:
• Overflow can occur only when adding two numbers that have the same
sign.
• Carryout signal from the sign bit position is not a sufficient indicator of
overflow when adding signed numbers.
• When both the operands X and Y have the same sign, overflow occurs when
the sign S is not the same as the signs X and Y.
10
Perform the following operation on 5 bit signed numbers using
2’s complement system. Also indicate whether overflow has
occurred.
1) -9+(-7)
2) +7-(-8)
3) -10+(-13)
4) -10-(-13)
11
Multiplication of unsigned numbers
12
Multiplication of unsigned numbers
13
Multiplication of unsigned numbers
Typical multiplication cell
14
Multiplication of unsigned numbers
Multiplicand
Combinatorial array multiplier
0 m 0 m 0 m
3 2 1 0 m 0
(PP0)
q
0
0
PP1 p
0
q
1
0
r
lie
PP2
tip
p
1
ul
q
M
2
0
PP3 p
2
q
3
0
,
p p p p p
7 6 5 4 3
15
Multiplication of unsigned numbers
16
Multiplication of Positive (unsigned) numbers
17
Multiplication of Positive (unsigned) numbers
Sequential Circuit Multiplier
Register A (initially 0)
Shift right
a a q q
C n - 1 0 n - 1 0
Multiplier Q
Add/Noadd
control
n-bit
Adder
MUX Control
sequencer
0 0
m m
n - 1 0
Multiplicand M
18
19
Sequential multiplication
13 *11 = 143
M
1 1 0 1
Initial configuration
0 0 0 0 0 1 0 1 1
C A Q
0 1 1 0 1 1 0 1 1 Add First cycle
0 0 1 1 0 1 1 0 1 Shift
0 1 0 0 1 1 1 1 0 No add
Shift Third cycle
0 0 1 0 0 1 1 1 1
1 0 0 0 1 1 1 1 1 Add
0 1 0 0 0 1 1 1 1 Shift Fourth cycle
Product
20
• Perform sequential multiplication : 12 *15 (=180)
21
Signed-operand Multiplication
22
Signed-operand Multiplication
23
Booth Algorithm Steps
24
Booth Algorithm
0 0 0 xM
0 1 +1 xM
1 0 -1 x M
1 1 0 xM
25
Booth Algorithm
0 1 1 0 1 (+13 ) 01101
X 1 1 0 1 0 (-6 ) 0-1+1-1 0
0000000000
111110011
00001101
1110011
000000
1 1 1 0 1 1 0 0 1 0 (-78 )
26
• Multiply each of the following pairs of signed 2’s complement
number using the Booths algorithm. (A=Multiplicand and
B=Multiplier)
• A=010111 and B=110110
• A=110011 and B=101100
• A=110101 and B=011011
• A=001111 and B=001111
27
Fast Multiplication
28
29
Fast Multiplication
Bit-Pair Recoding of Multipliers
30
Fast Multiplication
Bit-Pair Recoding of Multipliers
0 1 1 0 1
0 - 1 +1 - 1 0
0 0 0 0 0 0 0 0 0 0
1 1 1 1 1 0 0 1 1
0 0 0 0 1 1 0 1
1 1 1 0 0 1 1
0 1 1 0 1 ( + 13) 0 0 0 0 0 0
´ 1 1 0 1 0 (- 6) 1 1 1 0 1 1 0 0 1 0 ( - 78)
0 1 1 0 1
0 -1 - 2
1 1 1 1 1 0 0 1 1 0
1 1 1 1 0 0 1 1
0 0 0 0 0 0
1 1 1 0 1 1 0 0 1 0
31
Fast Multiplication
Carry-Save Addition of Summands
• Ripple carry array
P P P P P P P P
7 6 5 4 3 2 1 0
32
Fast Multiplication
Carry-Save Addition of Summands
1 0 1 1 0 1 (45) M
X 1 1 1 1 1 1 (63) Q
1 0 1 1 0 1 A
1 0 1 1 0 1 B
1 0 1 1 0 1 C
1 0 1 1 0 1 D
1 0 1 1 0 1 E
1 0 1 1 0 1 F
1 0 1 1 0 0 0 1 0 0 1 1 (2,835) Product
Figure 6.17. A multiplication example used to illustrate carry-save addition as shown in Figure 6.18.
33
Fast Multiplication
Carry-Save Addition of Summands
• Carry-save array
P P P P P P P P
7 6 5 4 3 2 1 0
34
Fast Multiplication
Carry-Save Addition of Summands
1 0 1 1 0 1 A
1 0 1 1 0 1 B
1 0 1 1 0 1 C
1 1 0 0 0 0 1 1 S1
0 0 1 1 1 1 0 0 C1
1 0 1 1 0 1 D
1 0 1 1 0 1 E
1 0 1 1 0 1 F
1 1 0 0 0 0 1 1 S2
0 0 1 1 1 1 0 0 C2
1 1 0 0 0 0 1 1 S1
0 0 1 1 1 1 0 0 C1
1 1 0 0 0 0 1 1 S2
1 1 0 1 0 1 0 0 0 1 1 S3
0 0 0 0 1 0 1 1 0 0 0 C3
0 0 1 1 1 1 0 0 C2
0 1 0 1 1 1 0 1 0 0 1 1 S4
+ 0 1 0 1 0 1 0 0 0 0 0 C4
1 0 1 1 0 0 0 1 0 0 1 1 Product
Figure 6.18. The multiplication example from Figure 6.17 performed using carry-save addition.
36
Integer Division
Manual Division
21 10101
13 274 1101 100010010
26 1101
14 10000
13 1101
1 1110
1101
1
37
Integer Division
Longhand Division Steps
38
Integer Division
Circuit Arrangement
Shift left
an an-1 a0 qn-1 q0
Dividend Q
A Quotient
Setting
0 mn-1 m0
Divisor M
39
Integer Division
Restoring Division
1. Initialize registers for two n-bit division operation, register M with
divisor, register Q with dividend, n+1(sign bit) bits register A with zero
2. Repeat n times
i. Left shift Q to A by one binary position.
ii. Subtract M from A, and place the answer back in A i,e., A=A-M
iii. If the sign of A is 1, set q0=0 and add M back to A (A=A+M -restore A);
otherwise, set q0 to 1 (no restore)
iv. Repeat these steps n times
3. After n cycles, A will contain remainder and Q contains Quotient
40
Restoring Division Example
Initially 0 0 0 0 0 1 0 0 0
0 0 0 1 1
Shift 0 0 0 0 1 0 0 0
Subtract 1 1 1 0 1 First cycle
Set q0 1 1 1 1 0
Restore 1 1
0 0 0 0 1 0 0 0 0
1 0
Shift 0 0 0 1 0 0 0 0
1 1 10 0 0 Subtract 1 1 1 0 1
1 1 Set q0 1 1 1 1 1 Second cycle
Restore 1 1
1 0 0 0 0 1 0 0 0 0 0
Shift 0 0 1 0 0 0 0 0
Subtract 1 1 1 0 1
Set q0 0 0 0 0 1 Third cycle
Shift 0 0 0 1 0 0 0 0 1
Subtract 1 1 1 0 1 0 0 1
Set q0 1 1 1 1 1 Fourth cycle
Restore 1 1
0 0 0 1 0 0 0 1 0
Remainder Quotient
Figure 6.22. A restoring-division example.
41
Integer Division
Nonrestoring Division
42
Nonrestoring Division Examples
Initially 0 0 0 0 0 1 0 0 0
0 0 0 1 1
Shift 0 0 0 0 1 0 0 0 First cycle
Subtract 1 1 1 0 1
Set q 0 1 1 1 1 0 0 0 0 0
Shift 1 1 1 0 0 0 0 0
Add 0 0 0 1 1 Second cycle
Set q 1 1 1 1 1 0 0 0 0
0
Shift 1 1 1 1 0 0 0 0
1 1 1 1 1 Add 0 0 0 1 1 Third cycle
Restore
0 0 0 1 1 Set q 0 0 0 0 1 0 0 0 1
remainder 0
Add 0 0 0 1 0
Remainder Shift 0 0 0 1 0 0 0 1
Subtract 1 1 1 0 1 Fourth cycle
Set q 1 1 1 1 1 0 0 1 0
0
Quotient
A nonrestoring-division example.
43
Outline: Basic Processing Unit
• Some Fundamental concepts
• Execution of a Complete Instruction
• Multiple bus organization
44
Fundamental Concepts
• Processor fetches one instruction at a time and perform the operation
specified.
• Instructions are fetched from successive memory locations until a branch
or a jump instruction is encountered.
• Processor keeps track of the address of the memory location containing
the next instruction to be fetched using Program Counter (PC).
• Instruction Register (IR)
46
Executing an Instruction
• Fetch the contents of the memory location pointed to by the PC.
The contents of this location are loaded into the IR (fetch phase).
IR ← [[PC]]
• Assuming that the memory is byte addressable, increment the
contents of the PC by 4 (fetch phase).
PC ← [PC] + 4
• Carry out the actions specified by the instruction in the IR
(execution phase).
47
Processor Organization – Single Bus Structure
48
49
50
Executing an Instruction
• Transfer a word of data from one processor register to another or to
the ALU.
• Perform an arithmetic or a logic operation and store the result in a
processor register.
• Fetch the contents of a given memory location and load them into a
processor register.
• Store a word of data from a processor register into a given memory
location.
51
Internal processor
b us
R i in
Register Transfers
R i
R i out
Y in
Constant 4
Select MUX
A B
ALU
Z in
Z out
52
Figure 7.2. Input and output gating for the registers in Figure 7.1.
Performing an Arithmetic or Logic Operation
53
Control Sequence for the Instruction
54
Processor Organization – Single Bus Structure
56
Fetching a Word from Memory
57
Fetching a Word from Memory
• The response time of each memory access varies (cache miss, memory-mapped
I/O,…).
• To accommodate this, the processor waits until it receives an indication that the
requested operation has been completed (MFC).
• Move (R1), R2
58
59
Storing A Word to Memory
60
Execution of a Complete Instruction
Add (R3), R1
1. Fetch the instruction
2. Fetch the first operand (the contents of the memory location
pointed to by R3)
3. Perform the addition
4. Load the result into R1
61
Execution of a Complete Instruction
Add (R3), R1
62
Execution of Branch Instructions
63
Execution of Branch Instructions
64
Multiple-Bus Organization
• While the steps still have to be performed by sequentially changing
from one step to another, the number of independent steps can be
clubbed into single step in a multiple bus organization.
• Improvement in performance in a multiple bus organization
65
Multiple-Bus Organization
66
Multiple-Bus Organization
Add R4, R5, R6
67