1 / 17

Review - Outline

Dr. Alaaeldin A. Amin Computer Engineering Department E-mail: amin@ccse.kfupm.edu.sa http://www.ccse.kfupm.edu.sa/~amin. Review - Outline. Machine Number Systems (Fixed radix Positional) Fixed Point Number Representation Base Conversion Representation of Signed Numbers

ezra-wynn
Download Presentation

Review - Outline

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Dr. Alaaeldin A. Amin Computer Engineering Department E-mail: amin@ccse.kfupm.edu.sa http://www.ccse.kfupm.edu.sa/~amin Review - Outline • Machine Number Systems (Fixed radix Positional) • Fixed Point Number Representation • Base Conversion • Representation of Signed Numbers • Signed Magnitude (Sign and Magnitude) • Complement Representation * Radix Complement (2`s Complement) * Diminished Radix Complement • Precision Extension • Arithmetic Shifts COE 522 Dr. A. Amin

  2. Machine Number Systems? X = xk-1 xk-2 ... x1 x0 .x-1 x-2 ... x-m = • Since Numbers Are Stored in Registers of Fixed Length • There is a Finite Number of Distinct Values that Can be Represented in a Register • Let Xmax & Xmin Denote The Largest & Smallest Representable Numbers • Xmax= rk-1For an Integral # of k-Digits • Xmax= 1-r-mFor a Fractional # of m-Digits • Xmax= rk-r-mFor a # of k- Integral Digits and m- FractionalDigits • Xmin = 0 • Number of Possible Distinct Values = rk+m Fractional Part Integral Part COE 522 Dr. A. Amin

  3. Number Radix Conversion • Let X be an Integer  XB in Radix B System •  XA in Radix A System Assumptions • XB has n digits XB = (bn-1………..b2 b1 b0)B , where bi is a digit in radix B system, i.e. bi {0, 1, ….. , “B-1”} • XA has m digits XA =(am-1………..a2 a1 a0)A where ai is a digit in radix A system, i.e. ai {0, 1, ….., “A-1”} Problem Statement XB =(bn-1………..b2 b1 b0)B (am-1………..a2 a1 a0)A Unknowns Knowns COE 522 Dr. A. Amin

  4. Not Divisible by A Not Divisible by A Divisible by A Divisible by A XB = am-1*Am-1+……+ a2*A2 + a1*A1 + a0*A0 • Where ai {0-(A-1)} • Accordingly, dividing XB by A, the remainder will be a0. XB = Q0.A+a0 Where, Q0 = am-1*Am-2+…+ a2*A1 + a1*A0 Likewise  Q0 = Q1A+a1 Get a1 Q1 = Q2A+a2 Get a2 ………………………………… Qm-3 = Qm-2A+am-2 Get am-2 Qm-2 = Qm-1A+am-1 Get am-1 Where Qm-1= 0  Stopping Criteria COE 522 Dr. A. Amin

  5. Sign Digit 0 +ive 1 -ive Representation of Signed Numbers Three Main Systems 1. Signed Magnitude (Sign and Magnitude) 2. Complement Representation • Radix Complement (2`s Complement) • Diminished Radix Complement Signed Magnitude • Independent Representation of The Sign and The Magnitude • Symmetric Range of Representation { -(2n-1 -1) :+(2n-1 -1) } • Two Representations for 0  {+0 , -0}  Nuisance for Implementation • Addition/Subtraction Harder To Implement • Multiplication & Division Less Problematic • For Base R Sign Digit May Be • 0  +ive Numbers • R-1  -ive Numbers {Inefficient Space Utilization} COE 522 Dr. A. Amin

  6. Representation of Signed Numbers • Alternatively • 0, 1, …, (R/2 - 1)  +ive Numbers • R/2, R/2+1, …., (R-1)  -ive Numbers  More Complex Sign Detection if r not power of 2 COE 522 Dr. A. Amin

  7. Representation of Signed Numbers Complement Representation • Positive Numbers (+N) Are Represented in Exactly the Same Way as in Signed Magnitude System • Negative Numbers (-N) Are Represented by the Complement of N (N`) Define the Complement of a number N (N`) as: N` = M -N Where M= Some Constant • This representation satisfies the Basic Requirement That: -(-N ) = ( N` )` = M- (M-N) = N Adding 2 Numbers; X (+ive) and Y (-ive) : IF Y > X • Result Z is -ive, i.e. Complement Represented: Z = X + (M-Y) = = M -(Y-X) = Correct Answer in Complement Form +ive COE 522 Dr. A. Amin

  8. M Chosen To Eliminate/Simplify Correction Step +ive +ive Representation of Signed Numbers IF Y < X • Result Z is +ive: Z = X + (M-Y) = M +(X-Y) Correct Answer = X - Y Requirements of M: 1- Simple Complement Calculations 2- Simplify/Eliminate Addition Correction Steps • Let xi be the Complement of a single Digit xi • IF X = xk-1xk-2 ... x1 x0 .x-1 x-2 ... x-m • Define X = xk-1xk-2 ... x1 x0 .x-1 x-2 ... x-m IF Y < X • Result Z is +ive: Z = X + (M-Y) = M +(X-Y) Correct Answer = X - Y Requirements of M: 1- Simple Complement Calculations 2- Simplify/Eliminate Addition Correction Steps • Let xi be the Complement of a single Digit xi • IF X = xk-1xk-2 ... x1 x0 .x-1 x-2 ... x-m • Define X = xk-1xk-2 ... x1 x0 .x-1 x-2 ... x-m M Chosen To Eliminate/Simplify Correction Step COE 522 Dr. A. Amin

  9. Representation of Signed Numbers X xk-1xk-2 ... x1 x0 .x-1 x-2 ... x-m + X xk-1xk-2 ... x1 x0 .x-1 x-2 ... x-m (r-1) (r-1) …….. . ………. (r-1) + ulp1 10 0 … 0 0 . 0 0 .….. 0 = r k Thus, X + X + ulp = r k …………... (1) where ulp = unit in least position = r -m(for #`s with m Fractional digits) = 1(for INTEGERS, i.e when m=0) Eqn. (1) Can Be ReWritten As r k - X = X + ulp …… (2) COE 522 Dr. A. Amin

  10. DiscardEnd Carry (Beyond Word Size) Representation of Signed Numbers Radix Complement: M= r k N ` = r k - N = N + ulp (Simple Computation) • Computing N ` is independent of k • Computing the Previous Addition Requires No Corrections Z = M + (X-Y) = r k+ (X-Y) Diminished Radix Complement: M= r k-ulp N ` = r k - ulp - N = N (Simplest Computation) • Computing the Previous Addition Requires Simple Correction of Addingulp Z = M + (X-Y) = r k+ (X-Y) -ulp End Around Carry Discarded & Added as ulp Should Add ulp forCorrection COE 522 Dr. A. Amin

  11. Sign Digit 0 +ive 1 -ive Representation of Signed Numbers 2`s Complement • Asymmetric Range of Representation { -(2k-1) :+(2k-1 -ulp) } - Negation Can Lead to OverFlow COE 522 Dr. A. Amin

  12. Integral Part Fractional Part Sign Bit 2`s Complement Numbers System X = xk-1 xk-2 ... x1 x0 .x-1 x-2 ... x-m = = Xif X is +ive = -2k-1+(2k-1 - X )= Xif X is -ive Precision/Range Extension of 2`s Comp #`s • Extending # N from n-bits to k`-bits (k`> k) • +ive N Pad with 0`s to the Left of the integral part And/Or to the right of Fractional Part. • -ive N Pad with 0`s to the right of Fractional Part And/Or Extend Sign Bit to the Left of the integral part. • In General • Pad with 0`s to the right of Fractional Part And/Or Extend Sign Bit to the Left of the integral part. ...xk-1 xk-1xk-1 xk-2 ... x1 x0 .x-1 x-2 .... x-m000….. COE 522 Dr. A. Amin

  13. -ive N N`k = 2k - N N`k` = 2k` - N N`k` - N`k = 2k` - 2k = 2k (2k`-k - 1 ) Shift Left k-bits (k`-k) 1`s 1111..111000..0 Sign Extension (k`-k) 1`s k 0`s 2`s Complement System Features • Leftmost Bit indicates Sign • The Sign Bit is Part of a Truncated -String • Asymetric Range(-2k-1:+(2k-1 -ulp)) • Overflow may result on Complementing • Single Zero Representation 0000000 (+0) COE 522 Dr. A. Amin

  14. Sign Digit 0 +ive 1 -ive Representation of Signed Numbers 1`s Complement • Symmetric Range of Representation { -(2k-1 -ulp) :+(2k-1 -ulp) } - 2 Representations of 0 (+0 = 0000000and-0 = 1111111) COE 522 Dr. A. Amin

  15. Integral Part Fractional Part Sign Bit 1`s Complement Numbers System X = xk-1 xk-2 ... x1 x0 .x-1 x-2 ... x-m = = Xfor +ive X = -(2k-1-ulp) + X ) = X` for -ive X Precision/Range Extension of 2`s Comp #`s • Extending # N from n-bits to k`-bits (k`> k) • +ive N Pad with 0`s to the Left of the integral part And/Or to the right of Fractional Part. • -ive N Pad with Sign Bit to the right of Fractional Part And/Or to the Left of the integral part. • In General • Pad with Sign Bit to the right of Fractional Part And/Or to the Left of the integral part. ..xk-1 xk-1xk-1 xk-2 .. x1 x0 .x-1 x-2 .. x-mxk-1 xk-1 ….. COE 522 Dr. A. Amin

  16. 1`s Complement Numbers System Features • Leftmost Bit indicates Sign • The Sign Bit is Part of a Truncated -String • Symetric Range(-(2k-1 -ulp) :+(2k-1 -ulp)) • Two Zero Representation (+0 , -0 ) Arithmetic Shifts Effect • Left Shift Multiply Number by radix r • Right Shift Divide Number by radix r (a) Shifting Unsigned or +ive Numbers • Shift-In 0`s (for both Left & Right Shifts) (b) Shifting -ive Numbers • Depends on the Representation Method Signed Magnitude: • Sign Bit is maintained (Unchanged) • Only The Magnitude is shifted and 0`s are Shifted-In for both Directions (Left & Right) COE 522 Dr. A. Amin

  17. Arithmetic Shifts 2`s Complement: • Left Shifts:0`s are Shifted-In • Right Shifts:Sign Bit Extended (Shifted Right) 1`s Complement: • Left & Right Shifts:Sign Bit is Shifted-In Right Shifts Left Shifts COE 522 Dr. A. Amin

More Related