Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

COA Module 2

Download as pdf or txt
Download as pdf or txt
You are on page 1of 65

William Stallings

Computer Organization
and Architecture
6th Edition

Chapter 9
Computer Arithmetic
Arithmetic & Logic Unit

• Does the calculations

• Everything else in the computer is there to

service this unit

• Handles integers

• May handle floating point (real) numbers

• May be separate FPU (maths co-processor)


ALU Inputs and Outputs
Addition and Subtraction
• Normal binary addition
• Monitor sign bit for overflow
• Take twos compliment of substahend and add to
minuend
— i.e. a - b = a + (-b)

• So we only need addition and complement circuits


A B Sum
0 0 0
0 1 1
1 0 1
1 1 0, Carry 1

1 1 1,Carry 1
Example of 2’s Compliment
Find 2’s compliment

1000

0100

111001

101010

100000
Hardware for Addition and Subtraction
Booth’s Algorithm
Q0 Q-1 Result
0 0 Only shift

1 1
0 1 A=A + M ,then shift

1 0 A= A – M , then shift

M =7
Q =3
M=0111
Q=0011
-M=1001
Example of Booth’s Algorithm:7(M)*3(Q)

Answer is in A and Q0001 0101 =21


Examples-size of n determines answer
Solve using Booths Algorithm
A. M = 5 , Q=5

B. M = 12, Q = 11

C. M = 9, Q=-3

D. M = -13 ( 0011 ) , Q = 6
-M=13 (1101)

A. M = -19 , Q = -20
Division
• More complex than multiplication
• Negative numbers are really bad!
• Based on long division
Division of Unsigned Binary Integers

00001101 Quotient
Divisor 1011 10010011 Dividend
1011
001110
Partial 1011
Remainders
001111
1011
100 Remainder
Flowchart for Restoring Division
Solve using Restoring Division
A. M = 5 , Q = 5 , A=0000 , Q=0010

B. M = 12, Q = 26, A=00010 , Q= 00010

C. M = 9, Q = 19 , A=00001 , Q =00010

D. M = 32 , Q = 59, A=011011, Q=000001

E. M = 17 , Q = 42, A=001000 , Q=000010


Solve using Non Restoring
A. M = 5 , Q = 5,A=0000,Q=0001.

B. M = 12, Q = 26,A=000010, Q=000010.

C. M = 9, Q = 19,A=00001,Q=00010.

D. M = 32 , Q = 59,A=011011,Q=000001.

E. M = 17 , Q = 42,A=001000,Q=000010
Booths Recoding / Bit pair recording

STEPS
Solve using Booths Recoding

1. M= 5 , Q = 4 (4 bits)= 00010100 (20)

2. M=9 , Q = -6 (5 bits)=11110 01010 (-54)

3. M=15 , Q=-10 (5 bits)=11011 01010(-150)

4. M= -13 ,Q = -20 (6 bits )=000100000100(260)


Sample mix problems-Kindly refrain
referring to flowchart.
1. Booth’s Algorithm = 000 100 000 100(260)
A= 110011 (Multiplicand )
B= 101100 (Multiplier)
2. Booth’s Recoding = 0110 1010/11011 01010
M= ( 15 )
Q= ( -10 )
3. Non Restoring Division
M=11 , Q= 21 , A= 01010 , Q= 00001
4. Restoring Division
M=14 , Q= 15, A=00001 , Q = 00001
Floating Point
Sign bit

Biased Significand or Mantissa


Exponent

• +/- .significand x 2exponent


• Misnomer
• Point is actually fixed between sign bit and body
of mantissa
• Exponent indicates place value (point position)
Floating Point Examples
Signs for Floating Point
• Mantissa is stored in 2s compliment
• Exponent is in excess or biased notation
—e.g. Excess (bias) 128 means
—8 bit exponent field
—Pure value range 0-255
—Subtract 128 to get correct value
—Range -128 to +127
Expressible Numbers
IEEE 754
• Standard for floating point storage
• 32 and 64 bit standards
• 8 and 11 bit exponent respectively
• Extended formats (both mantissa and exponent)
for intermediate results
IEEE 754 Formats

(1.N)2E-127

32 BIT

64 BIT

(1.N)2E-1023
Steps
• 1. Convert Decimal to Binary

• 2. Normalization
— Rewriting Step 1 into (1.N) form

— Ex: 1 1 1 . 0 1 1 = 1 .11011X22 Exponent

— Ex: 0 . 0 0 0 1 0 = 0 0 0 0 1 . 0 X 2 -4

• 3.Biasing
— Applying Single Precision (E – 1 2 7) & Double Precision ( E – 1 0 2 3 )
on exponent from Step 2

• 4. Representation in Single (32 bit )and Double Precision (64 bit ) Format
Solved Example
Solve
25.44 SP- 0|100000|1001 0111 0000 1010 0011 110
DP- 0|10000000011|1001 0111 0000 1010 0011 110

0.00635 SP- 0|1110111|00000001101000…


DP- 0|1111110111|00000001101000…
-125.10 SP- 1 | 10000101| 1111 010001
DP- 1 | 10000000101| 1111 010001

-13.54 SP- 1|10000010|10110001010


DP- 1|10000000010|10110001010
Sample Problems to Solve
1) 178.1875
SP 0|10000110|01100100011
DP 0|10000000110|
1) 309.175
SP 0|10000111|01011101001011
DP 0|10000000111|
1) 1259.125
SP 0|10001001|0011101011001000…(9 zeroes)
DP 0|10000001001|010100111100
1) 0.0625
SP 0|01111011|0000000….
DP 0|01111111|00000…..
Division of signed numbers
Solve

a) 7 / -3

b) -7 (Q) / 3 (M)

c) -7 (Q) / -3 (M)
• Dividend negative  Remainder –ve
4 phases of FP Arithmetic +/-
• Check for zeros
• Align significands (adjusting exponents)
• Add or subtract significands
• Normalize result
Floating Point Addition

Add the following two decimal numbers in


scientific notation:

8.70 × 10-1 with 9.95 × 101

Rewrite the smaller number such that its


exponent matches with the exponent of the
larger number.

8.70 × 10-1 = 0.087 (Note ! ) × 101


Add the mantissas

9.95 + 0.087 = 10.037 and

write the sum 10.037 × 101

Put the result in Normalised Form

10.037 × 101 = 1.0037 × 102


(shift mantissa, adjust exponent)
Check for overflow/underflow of the exponent
after normalisation

• Overflow
The exponent is too large to be represented in
the Exponent field

• Underflow
The number is too small to be represented in
the Exponent field
Round the result
If the mantissa does not fit in the space
reserved for it, it has to be rounded off.

For Example: If only 4 digits are allowed for


mantissa

1.0037 × 102 ===> 1.004 × 102


FP Addition & Subtraction Flowchart
FP Arithmetic x/
• Check for zero
• Add/subtract exponents
• Multiply/divide significands (watch sign)
• Normalize
• Round
• All intermediate results should be in double
length storage
Floating Point Multiplication
Floating Point Division

You might also like