Computer Organisation and Architecture
Computer Organisation and Architecture
1
10/10/2011
5 6
2
10/10/2011
Scan the bit and right of the bit of the multiplier at the same
time by control logic
If two bits =00 =11 - right shift only (A,Q,Q-1)
=01 A A +M and right shift
=10 A A - M and right shift
To preserve the sign of the number in A and Q, arithmetic
shift is done (An-1 is not only shifted into A n-2 but also
remains in A n-1)
9 10
11 12
product product
3
10/10/2011
13 14
0 0 0 1 0 1 1 0 shift
Shift left A, Q A A–M A<0 1st cycle
0 0 0 1 0 1 1 0 restore A, Q0 0
A A-M
0 0 1 0 1 1 0 0 shift
A A–M A<0 2nd cycle
For A > 0 or A = 0 No Yes For A< 0
A< 0 ?
0 0 1 0 1 1 0 0 restore A, Q0 0
Q 0
Q
0
1
A
0
A + M ( restore A)
0 1 0 1 1 0 0 0 shift
– 0 1 0 0 A A–M A0 3rd cycle
Count Count - 1
0 0 0 1 1 0 0 1 Q0 1
0 0 1 1 0 0 1 0 shift
No Yes Slides adapted from tan wooi
Count = 0? End
haw’s lecture notes (FOE) Remainder in A Quotient in Q A A–M A<0 4th cycle
Quotient in Q 0 0 1 1 0 0 1 0 restore A, Q0 0
Remainder in A
15 16
4
10/10/2011
Twos complement Division - Restoring division approach Twos complement Division-Algorithm (3)…..
i. Expand dividend to 2n-bit. (For Ex. 4bit 0111 becomes 00000111, and
1001 becomes 11111001.
ii. Load divisor in M and dividend in A & Q.
iii. Shift left A & Q by 1 bit
iv. If M and A have the same sign, perform AAM, otherwise
AA+M
v. If the sign of A is the same before and after the operation or
(A=0 & remaining dividend=0), set Q0=1
vi. Otherwise, if the sign is different and (A0 or remaining
dividend0), set Q0=0 and restore A
vii. Negate Q if divisor and dividend have different sign
viii. Remainder in A, quotient in Q
0 0 0 1 1 0 0 0 Shift
1 1 1 0 0 1 0 0 Shift
+ 1 1 0 1 Add
+ 0 0 1 0 Add 2nd cycle
2nd cycle 1 1 1 0
0 0 0 0
0 0 0 1 1 0 0 0 Restore
1 1 1 0 0 1 0 0 Restore
1 1 0 0 1 0 0 0 Shift 0 0 1 1 0 0 0 0 Shift
+ 0 0 1 0 Add + 1 1 0 1 Add
3rd cycle 3rd cycle
1 1 1 0 0 0 0 0
1 1 1 0 1 0 0 1 Set Q 0 = 1 0 0 0 0 0 0 0 1 Set Q0 = 1
1 1 0 1 0 0 1 0 Shift 0 0 0 0 0 0 1 0 Shift
+ 0 0 1 0 Add Sign of dividend & divisor are different Sign of dividend & divisor are
4th cycle + 1 1 0 1 Add
1 1 1 1 negate Q 4th cycle differrent negate Q
1 1 0 1
1 1 1 1 0 0 1 1 Set Q 0 = 1 Quotient = -Q =11012 = -310 Quotient = -Q =11102 = -210
19 0 0 0 0 0 0 1 0 Restore 20
Remainder = 11112 = -110 Remainder = 0
5
10/10/2011
Star t
Expand dividend
to 2n bits
M D ivisor
A, Q D ividend
count n
shift left A, Q
yes no
A A – M A and M sam e sign? A A + M
Sign of A still
count count – 1
remainder of -2
yes
Quotient in Q
R em ainder in A
End
ents Q
6
10/10/2011
Real Numbers
Problem (3)
Numbers with fractions
Could be done in pure binary
Divide -145 by 13 in binary twos 1001.1010 = 24 + 20 +2-1 + 2-3 =9.625
complement notation, using 12-bit words. Radix point: Fixed or Moving?
Use the Restoring division approach. Fixed radix point: can’t represent very large or
very small numbers.
Dynamically sliding the radix point -
a range of very large and very small numbers
can be represented.
In mathematics, radix point refers to the symbol used in numerical representations to separate the integral part of the number (to the
left of the radix) from its fractional part (to the right of the radix). The radix point is usually a small dot, either placed on the baseline
or halfway between the baseline and the top of the numerals. In base 10, the radix point is more commonly called the decimal point.
... From en.wikipedia.org/wiki/Radix_point
27 28
7
10/10/2011
29 30
31 32
8
10/10/2011
Single precision
60 bits 12 bits
Extended formats (both mantissa and Mantissa Exponent
Exponent Mantissa
Exponent sign
Mantissa sign
33 34
9
10/10/2011
Example
Floating Point Examples Convert these number to IEEE single precision format:
(a) 199.95312510 = 1100 0111.1111012
= 1.100 0111 111101 x 27
stored
+ 7 + 127 = 13410 1 1 0 0 0 1 1 1 1 1 1 1 0 1
0 1 0 0 0 0 1 1 0 1 0 0 0 1 1 1 1 1 1 1 0 1 0 0 0 0 0 0 0 0 0 0
sign biased exponent significand
...
stored [23 bits]
normalized -20 127 - 20 = 107 – 6 + 127 = 13310 1 0 0 1 1 0 1 1 0 1 1 0 ...
1 1 0 0 0 0 1 0 1 0 0 1 1 0 1 1 0 1 1 0 0 1 1 0 0 1 1 0 0 1 1 0
sign biased exponent significand
The bias equals to (2K-1 – 1) 28-1 – 1 = 127 37 38
-1.11110011111112 x 29 = -1111100111.11112
= -999.937510
Slides adapted from tan
wooi haw’s lecture notes
(FOE)
39 40
10
10/10/2011
43 44
11
10/10/2011
1.1101 x 2 4
FP Arithmetic +/- (cont.) FP Arithmetic +/- (cont.) + 0.0101 x 2 4
10.0010 x 24 1.0001 x 2 5
• As the aligning operation may result in the loss of • After the numbers have been aligned, they are added
digits, it is the smaller number that is shifted so that together taking into account their signs
any loss will therefore be of relatively insignificant • There might be a possibility of significand overflow
8 bits remains
shift due to a carry out from the most significant bit
left
1.1001 x 29 110010000 x 21 1 x 29 is lost • If this occurs, the significand of the result if shifted
1.0111 x 21 1.0111000 x 21 right and the exponent is incremented
• Hence, the smaller number are shifted right by • As the exponents are incremented, it might overflows
increasing its exponent until the two exponents are the and the operation will stop
same • Lastly, the result if normalized by shifting significand
• If both numbers have exponents that differ digits left until the most significant digit is non-zero
significantly, the smaller number is lost as a result of • Each shift causes a decrement of the exponent and thus
shifting could cause an exponent underflow
1.1001001 x 29 1.1001001 x 29 • Finally, the result is rounded off and reported
1.0110001 x 21 shift
0.0000000 x 29
right 47 48
12
10/10/2011
13
10/10/2011
0.4 x 2 0.8
0.8 x 2 1.6 only 24 bits can be stored
0.6 x 2 1.2
1 1 0 0 0 0 1 1 0 0 1 1 0 0 1 1 0 0 1 1 0 0 1 1 0 0 1 1 0 0 1 1
...
55 56
14
10/10/2011
1.01000010000000000000000011 no
x 1.10012
Multiply
0 1 0 0 0 0 1 0 1 0 1 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 10.011100012 significands
57 Round RETURN 58
Floating-point Division
Floating Point Multiplication
X = 3.7510 = 11.112 = 1.111 x 21
YX= Z
DIVIDE Y = 95.62510 = 101 1111.101 2
= 1.011111101 x 26
E 1 = 127 + 1 = 128
X = 0?
no
Y = 0?
no Subtract E 2 = 127 + 6 = 133
exponents
E2 – E1 = 5
yes yes
E T = 127 + 5 = 132
Z 0 Z Add bias
no
no
0.110011
Divide
1.111 1.011111101 significands
0.110011 x 2 5
= 1.10011 x 24 Normalize
Round RETURN 59 60
15
10/10/2011
61 62
SOLUTION (1)…….
SOLUTION (1)….
Step 3: For the 8 bit biased exponent field, the
IEEE 32 BIT FLOATING POINT FORMAT bias used is
2k-1-1 = 28-1-1 = 127
MSB 8 bits 23 bits
Add the bias 127 to the exponent 9 and convert
sign Biased Mantissa/Significand it into binary in order to store for 8-bit biased
Exponent (Normalized)
exponent. 127 + 9
Step 1: Express the given number in binary form =136 ( 1000 1000)
(640.5) = 1010000000.1* 20 Step 4: Since the given number is negative, put
Step 2: Normalize the number into the form 1.bbbbbbb
MSB as 1
1010000000.1* 20 = 1. 0100000001* 29
Once Normalized, every number will have 1 at the leftmost bit. So IEEE notation is saying Step 5: Pack the result into proper format(IEEE
that there is no need to store this bit. Therefore significand to be stored is 0100 0000 0100
0000 0000 000 in the allotted 23 bits 32 bit)
1 1000 1000 0100 0000 0010 0000 0000 000
63 64
16
10/10/2011
17