Figure 1.1 Block diagram of a digital computer. Functional Units
REPRESENTATION OF NUMBERS - POSITIONAL NUMBERS Decimal Binary Octal Hexadecimal A B C D E F Binary, octal, and hexadecimal conversion A F 6 3 Octal Binary Hexa
CONVERSION OF BASES Decimal to Base R number Base R to Decimal Conversion V(A) = a k R k A = a n-1 a n-2 a n-3 … a 0. a -1 … a -m (736.4) 8 = 7 x x x x 8 -1 = 7 x x x 1 + 4/8 = (478.5) 10 (110110) 2 =... = (54) 10 ( ) 2 =... = (6.785) 10 (F3) 16 =... = (243) 10 (0.325) 6 =... = ( ) 10 - Separate the number into its integer and fraction parts and convert each part separately. - Convert integer part into the base R number → successive divisions by R and accumulation of the remainders. - Convert fraction part into the base R number → successive multiplications by R and accumulation of integer digits
EXAMPLE Convert to base 2. Integer = Fraction = x x x x (41) 10 = (101001) 2 (0.6875) 10 = (0.1011) 2 ( ) 10 = ( ) 2 Convert (63) 10 to base 5: (223) 5 Convert (1863) 10 to base 8: (3507) 8 Convert ( ) 10 to hexadecimal: (0.A3) 16 Exercise
COMPLEMENT OF NUMBERS Two types of complements for base R number system: - R's complement and (R-1)'s complement The (R-1)'s Complement Subtract each digit of a number from (R-1) Example - 9's complement of is 's complement of is (bit by bit complement operation) The R's Complement Add 1 to the low-order digit of its (R-1)'s complement Example - 10's complement of is = 's complement of is =
FIXED POINT NUMBERS Binary Fixed-Point Representation X = x n x n-1 x n-2... x 1 x 0. x -1 x x -m Sign Bit(x n ): 0 for positive - 1 for negative Remaining Bits(x n-1 x n-2... x 1 x 0. x -1 x x -m ) Numbers:Fixed Point Numbers and Floating Point Numbers
SIGNED NUMBERS Signed magnitude representation Signed 1's complement representation Signed 2's complement representation Example: Represent +9 and -9 in 7 bit-binary number Only one way to represent +9 ==> Three different ways to represent -9: In signed-magnitude: In signed-1's complement: In signed-2's complement: In general, in computers, fixed point numbers are represented either integer part only or fractional part only. Need to be able to represent both positive and negative numbers - Following 3 representations
ARITHMETIC ADDITION: SIGNED MAGNITUDE [1] Compare their signs [2] If two signs are the same, ADD the two magnitudes - Look out for an overflow [3] If not the same, compare the relative magnitudes of the numbers and then SUBTRACT the smaller from the larger --> need a subtractor to add [4] Determine the sign of the result ) > ) > ) > ) > (- 9) -6 + (-9) Overflow or (-9) + (-9) ) (1)0010 overflow Fixed Point Representations
ARITHMETIC ADDITION: SIGNED 2’s COMPLEMENT Example (1) Add the two numbers, including their sign bit, and discard any carry out of leftmost (sign) bit - Look out for an overflow overflow ) operands have the same sign and the result sign changes x n-1 y n-1 s’ n-1 + x’ n-1 y’ n-1 s n-1 = c n-1 c n x’ n-1 y’ n-1 s n-1 (c n-1 c n ) x n-1 y n s’ n-1 (c n-1 c n ) Fixed Point Representations
ARITHMETIC ADDITION: SIGNED 1’s COMPLEMENT Add the two numbers, including their sign bits. - If there is a carry out of the most significant (sign) bit, the result is incremented by 1 and the carry is discarded (1) 0(1) ) end-around carry (1) ) (1)0010 +) overflow Example not overflow (c n-1 c n ) = 0 (c n-1 c n ) Fixed Point Representations
FLOATING POINT NUMBER REPRESENTATION * The location of the fractional point is not fixed to a certain location * The range of the representable numbers is wide F = EM m n e k e k-1... e 0 m n-1 m n-2 … m 0. m -1 … m -m sign exponent mantissa - Mantissa Signed fixed point number, either an integer or a fractional number - Exponent Designates the position of the radix point Decimal Value V(F) = V(M) * R V(E) M: Mantissa E: Exponent R: Radix Floating Point Representation
FLOATING POINT NUMBERS sign mantissaexponent ==> x Example A binary number in 16-bit floating point number representation (6-bit exponent and 10-bit fractional mantissa) Example Note: In Floating Point Number representation, only Mantissa(M) and Exponent(E) are explicitly represented. The Radix(R) and the position of the Radix Point are implied. ExponentMantissaSign or Floating Point Representation
IEEE Standard for FLOATING POINT NUMBERS To represent IEEE standard for floating-point numbers is called IEEE floating-point. This standard specifies how single precision (32 bit) and double precision (64 bit) floating point numbers are to be represented. It is divided in two formats as follows: 1. Single Precision: The IEEE single precision floating point standard representation requires a 32 bit word, which may be represented as numbered from 0 to 31, left to right. The first bit is the sign bit, S, the next eight bits are the exponent bits, 'E', and the final 23 bits are the fraction 'F': S EEEEEEEE FFFFFFFFFFFFFFFFFFFFFFF
The value V represented by the word may be determined as follows: If E=255 and F is nonzero, then V=NaN ("Not a number") If E=255 and F is zero and S is 1, then V=-Infinity If E=255 and F is zero and S is 0, then V=Infinity If 0<E<255 then V=(-1)**S * 2 ** (E-127) * (1.F) where "1.F" is intended to represent the binary number created by prefixing F with an implicit leading 1 and a binary point. If E=0 and F is nonzero, then V=(-1)**S * 2 ** (-126) * (0.F) These are "unnormalized" values. If E=0 and F is zero and S is 1, then V=-0 If E=0 and F is zero and S is 0, then V=0 In particular, = = = Infinity = -Infinity = NaN = NaN = +1 * 2**( ) * 1.0 = = +1 * 2**( ) * = = -1 * 2**( ) * = = +1 * 2**(1-127) * 1.0 = 2**(-126) = +1 * 2**(-126) * 0.1 = 2**(-127) = +1 * 2**(-126) * = 2**(- 149) (Smallest positive value)
Double Precision The IEEE double precision floating point standard representation requires a 64 bit word, which may be represented as numbered from 0 to 63, left to right. The first bit is the sign bit, S, the next eleven bits are the exponent bits, 'E', and the final 52 bits are the fraction 'F': S EEEEEEEEEEE FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF The value V represented by the word may be determined as follows: If E=2047 and F is nonzero, then V=NaN ("Not a number") If E=2047 and F is zero and S is 1, then V=-Infinity If E=2047 and F is zero and S is 0, then V=Infinity If 0<E<2047 then V=(-1)**S * 2 ** (E-1023) * (1.F) where "1.F" is intended to represent the binary number created by prefixing F with an implicit leading 1 and a binary point. If E=0 and F is nonzero, then V=(-1)**S * 2 ** (-1022) * (0.F) These are "unnormalized" values. If E=0 and F is zero and S is 1, then V=-0 If E=0 and F is zero and S is 0, then V=0
Example of Single Precision Format Ex-1 Represent a binary positive number in the IEEE aingle-precision format. The binary positive number = X 2^6 The 23-bit mantissa M= The biased exponent E’= E+ 127 = 6+127=133 = The sign bit S=0, since the number is positive. So 32-bit representation is Ex-2 Represent the decimal number in the IEEE single-precision format. The decimal number -0.75= in binary= - 1.1X2^(-1) The 23-bit mantissa M= The biased exponent E’= E+127= =126= Since the number is negative, the sign bit S=
17 Algorithms for Multiplication (Manual Method) 1101 Multiplicand M X 1011 Multiplier Q ____ Product P Partial product
18 4) Algorithms for Multiplication Multiplicand Multiplier Product
Sequential Multiplication Method for Unsigned Number START A=0; F=0, Q= Multiplier M=Multiplicand, size=n Q[0]=1? A=A+M Right Shift(FAQ) Size=size-1 Size=0? Product=AQ End Yes No F=flip-flop holds the end carry generated in the addition
Illustration of Sequential Multiplication Method Multiplier Q=14=1110 and multiplicand M=6=0110 Initial Config M F A Q Size Step 1,Q[0] = R.S(FAQ) Step 2,Q[0] = A=A+M, R.S(FAQ) Step3,Q[0] =1 A=A+M, R.S(FAQ) Step4,Q[0] = A=A+M, R.S(FAQ) Product= AQ= =84
Booth’s Multiplication Method (for signed numbers) START A=0; Q[-1]=0, Q= Multiplier M=Multiplicand, size=n Q[0]=0? and Q[- 1]=1 A=A-M Right Shift(AQ) Size=size-1 Size=0? Product=AQ End No Q[0]=1 and Q[- 1]=0 A=A+M Yes No
Illustration of Booth’s Algorithm Multiplier Q=7=0111 and multiplicand M= --6 = 1010(as negetive results are automatically in 2’s complement form). [A flip-flop (a fictitious bit position)is used to the right of lsb of the multiplier and it is initialized to 0] Initial Config M A Q Size Step 1,Q[0] = R.S(FAQ) Step 2,Q[0] =1,Q[-1] = A=A-M, R.S(AQ) Step3,Q[0] =1 A=A+M, R.S(AQ) Step4,Q[0] = A=A+M, R.S(AQ) Step5,Q[0] = A=A+M, R.S(AQ) Product= AQ= , it shows that the product is negative number so to get the number in familiar form we take 2’s complement of magnitude. The result is -42
Division Algorithm START A=0; F=0, Q= Dividend M=Divisor, size=n Sign of A=0? A=A+M Q[0] =1 Size=size-1 Size=0? quotient=Q, Remainder=A End No Left shift(AQ) A=A-M Q[0]=0 No Yes
Illustration of Restoring division Algorithm dividend Q=7=0111 and divisor M= 3 =0011 Initial Config M A Q Size Step 1 LS(AQ) __ A=A-M __ Sign of A=-ve Set Q[0]=0 & Restore A by (A+M) Step 2 LS(AQ) __ A=A-M, __ As sign of A=-ve Set Q[0]=0 Restore A Step3 LS(AQ) __ A=A-M, __ As sign of A=+ve Set Q[0]=
Restoring Division Algorithm M A Q Size Step4 LS(AQ) __ A=A-M, __ As sign of A=+ve Set Q[0]=0 Restore A RESULT : Quotient = Q = 0010 Remainder = A = = 1
Illustration of Non-Restoring division Algorithm dividend Q=7=0111 and divisor M= 3 =0011 Initial Config M A Q Size Step 1 As sign of A=+ve LS(AQ) __ A=A-M __ As sign of A=-ve Set Q[0]= Step 2 As sign of A=-ve LS(AQ) __ A=A+M, __ As sign of A=-ve Set Q[0]=
Non-restoring Division Algorithm M A Q Size Step3 As sign of A=-ve LS(AQ) __ A=A+M, __ As sign of A=+ve Set Q[0]= Step4 As sign of A=+ve LS(AQ) __ A=A-M, __ As sign of A=-ve Set Q[0]= RESULT : Quotient = Q = 0010 Remainder = A = = 1