7/27/2019 CS F342-11.pdf
http://slidepdf.com/reader/full/cs-f342-11pdf 1/24
BITS PilaniHyderabad Campus
BITS Pilani presentation
D. PowarLecturer,
BITS-Pilani, Hyderabad Campus
7/27/2019 CS F342-11.pdf
http://slidepdf.com/reader/full/cs-f342-11pdf 2/24
BITS PilaniHyderabad Campus
CS F342
Computer Architecture
Lecture -11
7/27/2019 CS F342-11.pdf
http://slidepdf.com/reader/full/cs-f342-11pdf 3/24
BITS Pilani, Hyderabad Campus
Last lecture review
Computer Arithmetic
9/19/2013 3
7/27/2019 CS F342-11.pdf
http://slidepdf.com/reader/full/cs-f342-11pdf 4/24
BITS Pilani, Hyderabad Campus
Division
Unsigned division
Signed division
7/27/2019 CS F342-11.pdf
http://slidepdf.com/reader/full/cs-f342-11pdf 5/24
BITS Pilani, Hyderabad Campus
Division of Unsigned Binary Integers
7/27/2019 CS F342-11.pdf
http://slidepdf.com/reader/full/cs-f342-11pdf 6/24
BITS Pilani, Hyderabad Campus
Flowchart for Unsigned Binary Division
7/27/2019 CS F342-11.pdf
http://slidepdf.com/reader/full/cs-f342-11pdf 7/24BITS Pilani, Hyderabad Campus
Bits of dividend are examined from L to R until the set of
bits examined represents a number greater than or equal
to the divisor
Until this event occurs, 0s are placed in the quotient
When the event occurs, a 1 is placed in the quotient and the
divisor is subtracted from the partial dividend
This continues in cyclic pattern
The process stops when all the bits of dividend are exhausted
More complex than multiplication
Algorithm:
7/27/2019 CS F342-11.pdf
http://slidepdf.com/reader/full/cs-f342-11pdf 8/24BITS Pilani, Hyderabad Campus
Needs operations like Shift, subtract, restore
Positive numbers: Q = 0111 (Dividend)
M = 0011 (Divisor)
Examples:
7/27/2019 CS F342-11.pdf
http://slidepdf.com/reader/full/cs-f342-11pdf 9/24BITS Pilani, Hyderabad Campus
Example: Restoring Twos Complement Division (7/3)
7/27/2019 CS F342-11.pdf
http://slidepdf.com/reader/full/cs-f342-11pdf 10/24BITS Pilani, Hyderabad Campus
Signed division
7/27/2019 CS F342-11.pdf
http://slidepdf.com/reader/full/cs-f342-11pdf 11/24BITS Pilani, Hyderabad Campus
When performing (7)÷(-3), remainder is 0001,
But, when performing (-7)÷(3) and (-7)÷(-3) , remainder is 1111.
In general
The remainder is defined by
D=Q*V+R,
i.e., R = D - Q*V
Where
D = dividend
Q = quotient
V = divisor
R = remainder
How signed division is Different??
7/27/2019 CS F342-11.pdf
http://slidepdf.com/reader/full/cs-f342-11pdf 12/24BITS Pilani, Hyderabad Campus
1. Convert the operands into unsigned values
2. Compute unsigned division
3. Check the sign’s of reminder and quotient
4. If negative (reminder or quotient), take 2’s compliment of the same
Division Algorithm for Signed Integers
7/27/2019 CS F342-11.pdf
http://slidepdf.com/reader/full/cs-f342-11pdf 13/24BITS Pilani, Hyderabad Campus
Example : (7/-3)
7/27/2019 CS F342-11.pdf
http://slidepdf.com/reader/full/cs-f342-11pdf 14/24BITS Pilani, Hyderabad Campus
14
MIPS Division
• Use HI/LO registers for result – HI: 32-bit remainder
– LO: 32-bit quotient
• Instructions– div rs, rt / divu rs, rt
Ex: div $s0,$t0
– No overflow or divide-by-0 checking• Software must perform checks if required
– Use mfhi, mflo to access result
Ex: mfhi $t0 $t0 <- reminder
7/27/2019 CS F342-11.pdf
http://slidepdf.com/reader/full/cs-f342-11pdf 15/24BITS Pilani, Hyderabad Campus
Floating points arithmetic
7/27/2019 CS F342-11.pdf
http://slidepdf.com/reader/full/cs-f342-11pdf 16/24BITS Pilani, Hyderabad Campus
Numbers with fractions
Could be done in pure binary
1001.1010 = 24 + 20 + 2-3 +2-1 =9.625
We need a way to represent
– Numbers with fractions, e.g., 3.1416
– Very small numbers,• Mass of electron: 9.1 X 10-28 gm
– Very large numbers,• Distance (pluto – sun) : 5.9 X 1012 m
Floating points representation
7/27/2019 CS F342-11.pdf
http://slidepdf.com/reader/full/cs-f342-11pdf 17/24BITS Pilani, Hyderabad Campus
m x r em : mantissa
r : radix [ can be 2,8,16,10]
e : exponent
The number 537.25 is represented in a registerwith m = 53725 and e = 3
Interpreted as
Point is actually fixed between sign bit and bodyof mantissa
Exponent indicates place value (point position)
Floating Point
.53725x103
7/27/2019 CS F342-11.pdf
http://slidepdf.com/reader/full/cs-f342-11pdf 18/24BITS Pilani, Hyderabad Campus
Exponent can be represented in Signedmagnitude, Signed 2’s complement, Signed 1’s
complement or biased form.
Biased representation: In this representation the sign bit is removed from being
a separate entity.
Bias is a +ve number that is added to each exponent as
the floating point number is formed, so that internally allexponent are +ve.
Biased representation is used in many computers.
Exponent representation:
7/27/2019 CS F342-11.pdf
http://slidepdf.com/reader/full/cs-f342-11pdf 19/24BITS Pilani, Hyderabad Campus
Consider an exponent that ranges from -50 to 49.
Internally, it is represented by two digits (without sign) by
adding to it a bias of 50.
The exponent register contains the no. e+50, where ‘e’ is
the actual exponent.
7/27/2019 CS F342-11.pdf
http://slidepdf.com/reader/full/cs-f342-11pdf 20/24BITS Pilani, Hyderabad Campus
To simplify operations on floating-point numbers, it istypically required that they have to be normalized.
A normalized number is one in which the most
significant digit of the significand is nonzero
Floating Point numbers are usually normalizedi.e. exponent is adjusted so that leading bit(MSB) of mantissa is non zero.
Ex: .0001580x102 (Normalized number is : 0.1580x10-1)
Ex: 0.000123 (Normalized number is : 0.123x10-3),here ".123" is called a normalized mantissa, "-3"is called the exponent .
Normalization
7/27/2019 CS F342-11.pdf
http://slidepdf.com/reader/full/cs-f342-11pdf 21/24BITS Pilani, Hyderabad Campus
For binary numbers, a normalized number is thereforeone in which the most significant bit of the significand is
one.
The typical convention is that there is one bit to the left of
the radix point. Thus, a normalized nonzero number isone in the form:
Because the most significant bit is always one, it is
unnecessary to store this bit; rather, it is implicit
Zero cannot be normalized
Normalization
7/27/2019 CS F342-11.pdf
http://slidepdf.com/reader/full/cs-f342-11pdf 22/24BITS Pilani, Hyderabad Campus
The leftmost bit stores the sign of the number (1:negative, 0:positive)
IEEE-754 Floating Point Numbers
7/27/2019 CS F342-11.pdf
http://slidepdf.com/reader/full/cs-f342-11pdf 23/24
BITS Pilani, Hyderabad Campus
Bias equals, where k: no: of bits in exponent
The range of true exponent values are: -126 to 127
The final portion is significand /mantissa
Single precision