CH09 PC Math.


49 views
Uploaded on:
Description
Number juggling
Transcripts
Slide 1

CH09 Computer Arithmetic CPU consolidates of ALU and Control Unit, this part examines ALU The Arithmetic and Logic Unit (ALU) Number Systems Integer Representation Integer Arithmetic Floating-Point Representation Floating-Point Arithmetic TECH Computer Science CH08

Slide 2

Arithmetic & Logic Unit Does the counts Everything else in the PC is there to administration this unit Handles whole numbers May handle coasting point (genuine) numbers May be separate FPU (maths co-processor) May be on chip separate FPU (486DX +)

Slide 3

ALU Inputs and Outputs

Slide 4

Number Systems ALU does estimations with twofold numbers Decimal number framework Uses 10 digits (0,1,2,3,4,5,6,7,8,9) In decimal framework, a number 84, e.g., implies 84 = (8x10) + 3 4728 = (4x1000)+(7x100)+(2x10)+8 Base or radix of 10: every digit in the number is increased by 10 raised to a force comparing to that digit\'s position E.g. 83 = (8x10 1 )+ (3x10 0 ) 4728 = (4x10 3 )+(7x10 2 )+(2x10 1 )+(8x10 0 )

Slide 5

Decimal number framework… Fractional qualities, e.g. 472.83=(4x10 2 )+(7x10 1 )+(2x10 0 )+(8x10 - 1 )+(3x10 - 2 ) as a rule, for the decimal representation of X = {… x 2 x 1 x 0. x - 1 x - 2 x - 3 … } X =  i x i 10 i

Slide 6

Binary Number System Uses just two digits, 0 and 1 It is base or radix of 2 Each digit has a quality relying upon its position : 10 2 = (1x2 1 )+(0x2 0 ) = 2 10 11 2 = (1x2 1 )+(1x2 0 ) = 3 10 100 2 = (1x2 2 )+ (0x2 1 )+(0x2 0 ) = 4 10 1001.101 2 = (1x2 3 )+(0x2 2 )+ (0x2 1 )+(1x2 0 ) +(1x2 - 1 )+(0x2 - 2 )+(1x2 - 3 ) = 9.625 10

Slide 7

Decimal to Binary transformation Integer and fragmentary parts are taken care of independently, Integer part is taken care of by rehashing division by 2 Factional part is taken care of by rehashing increase by 2 E.g. change over decimal 11.81 to paired Integer section 11 Factional section .81

Slide 8

Decimal to Binary transformation, e.g. /e.g. 11.81 to 1011.11001 (approx) 11/2 = 5 leftover portion 1 5/2 = 2 remaining portion 1 2/2 = 1 remaining portion 0 1/2 = 0 remaining portion 1 Binary number 1 011 .81x2 = 1.62 essential section 1 .62x2 = 1.24 vital section 1 .24x2 = 0.48 fundamental section 0 .48x2 = 0.96 vital section 0 .96x2 = 1.92 vital section 1 Binary number . 1 1001 (surmised)

Slide 9

Hexadecimal Notation: charge ground amongst PC and Human Use 16 digits, (0,1,3,… 9,A,B,C,D,E,F) 1A 16 = (1 16 x 16 1 )+(A 16 x 16 o ) = (1 10 x 16 1 )+(10 10 x 16 0 )=26 10 Convert gathering of four paired digits to/from one hexadecimal digit, 0000=0; 0001=1; 0010=2; 0011=3; 0100=4; 0101=5; 0110=6; 0111=7; 1000=8; 1001=9; 1010=A; 1011=B; 1100=C; 1101=D; 1110=E; 1111=F; e.g. 1101 1110 0001 . 1110 1101 = DE1 . DE

Slide 10

Integer Representation (stockpiling) Only have 0 & 1 to speak to everything Positive numbers put away in double e.g. 41=00101001 No less sign No period How to speak to negative number Sign-Magnitude Two\'s compliment

Slide 11

Sign-Magnitude Left most piece is sign piece 0 implies positive 1 implies negative +18 = 0 0010010 - 18 = 1 0010010 Problems Need to consider both sign and size in number-crunching Two representations of zero (+0 and - 0)

Slide 12

Two\'s Compliment (representation) +3 = 00000011 +2 = 00000010 +1 = 00000001 +0 = 00000000 - 1 = 11111111 - 2 = 11111110 - 3 = 11111101

Slide 13

Benefits One representation of zero Arithmetic works effortlessly (see later) Negating is genuinely simple (2\'s compliment operation) 3 = 00000011 Boolean supplement gives 11111100 Add 1 to LSB 11111101

Slide 14

Geometric Depiction of Twos Complement Integers

Slide 15

Range of Numbers 8 bit 2s compliment +127 = 01111111 = 2 7 - 1 - 128 = 10000000 = - 2 7 16 bit 2s compliment +32767 = 011111111 11111111 = 2 15 - 1 - 32768 = 100000000 00000000 = - 2 15

Slide 16

Conversion Between Lengths Positive number pack with driving zeros +18 = 00010010 +18 = 00000000 00010010 Negative numbers pack with driving ones - 18 = 10010010 - 18 = 11111111 10010010 i.e. pack with MSB (sign piece)

Slide 17

Integer Arithmetic: Negation Take Boolean supplement of every piece, I.e. every 1 to 0, and every 0 to 1. Add 1 to the outcome E.g. +3 = 011 Bitwise supplement = 100 Add 1 = 101 = - 3

Slide 18

Negation Special Case 1 0 = 00000000 Bitwise not 11111111 Add 1 to LSB +1 Result 1 00000000 Overflow is disregarded, so: - 0 = 0 OK!

Slide 19

Negation Special Case 2 - 128 = 10000000 bitwise not 01111111 Add 1 to LSB +1 Result 10000000 So: - (- 128) = - 128 NO OK! Screen MSB (sign piece) It ought to change amid refutation >> There is no representation of +128 for this situation. (no +2 n )

Slide 20

Addition and Subtraction Normal double option 0011 0101 1100 +0100 +1111 - - 0111 1 001 = flood 1 1011 Monitor sign piece for flood (sign piece change as including two positive numbers or two negative numbers.) Subtraction: Take twos compliment of subtrahend then add to minuend i.e. a - b = a + (- b) So we just need option and supplement circuits

Slide 21

Hardware for Addition and Subtraction

Slide 22

Multiplication Complex Work out fractional item for every digit Take care with spot esteem (section) Add halfway items

Slide 23

Multiplication Example (unsigned numbers e.g.) 1011 Multiplicand (11 dec) x 1101 Multiplier (13 dec) 1011 Partial items 0000 Note: if multiplier bit is 1 duplicate 1011 multiplicand (place esteem) 1011 generally zero 10001111 Product (143 dec) Note: require twofold length result

Slide 24

Unsigned Binary Multiplication

Slide 25

Flowchart for Unsigned Binary Multiplication

Slide 26

Execution of Example

Slide 27

Multiplying Negative Numbers The past technique does not work! Arrangement 1 Convert to positive if required Multiply as above If indications of the first two numbers were distinctive, refute answer Solution 2 Booth\'s calculation

Slide 28

Booth\'s Algorithm

Slide 29

Example of Booth\'s Algorithm

Slide 30

Division More perplexing than increase However, can use the greater part of the same equipment. In view of long division

Slide 31

Division of Unsigned Binary Integers Quotient 00001101 Divisor 1011 10010011 Dividend 1011 001110 Partial Remainders 1011 001111 1011 Remainder 100

Slide 32

Flowchart for Unsigned Binary division

Slide 33

Real Numbers with portions Could be done in immaculate parallel 1001.1010 = 2 4 + 2 0 +2 - 1 + 2 - 3 =9.625 Where is the twofold point? Settled? Exceptionally restricted Moving? How would you demonstrate where it is?

Slide 34

Floating Point +/ - .significand x 2 type Point is really settled between sign piece and group of mantissa Exponent shows place esteem (point position) Biased Exponent Significand or Mantissa Sign piece

Slide 35

Floating Point Examples

Slide 36

Signs for Floating Point Exponent is in abundance or one-sided documentation e.g. Overabundance (predisposition) 127 means 8 bit type field Pure quality reach 0-255 Subtract 127 to get right esteem Range - 127 to +128 The relative extents (request) of the numbers don\'t change. Can be dealt with as numbers for examination.

Slide 37

Normalization/FP numbers are typically standardized i.e. example is balanced so driving piece (MSB) of mantissa is 1 Since it is dependably 1 there is no compelling reason to store it (c.f. Logical documentation where numbers are standardized to give a solitary digit before the decimal point e.g. 3.123 x 10 3 )

Slide 38

FP Ranges For a 32 bit number 8 bit type +/ - 2 256  1.5 x 10 77 Accuracy The impact of changing lsb of mantissa 23 bit mantissa 2 - 23  1.2 x 10 - 7 About 6 decimal spots

Slide 39

Expressible Numbers

Slide 40

IEEE 754 Standard for gliding point stockpiling 32 and 64 bit norms 8 and 11 bit example separately Extended arrangements (both mantissa and type) for middle of the road comes about Representation: sign, type, group 0: 0, 0, 0 - 0: 1, 0, 0 Plus unendingness: 0, all 1s, 0 Minus boundlessness: 1, all 1s, 0 NaN; 0 or 1, all 1s, =! 0

Slide 41

FP Arithmetic +/ - Check for zeros Align significands (changing types) Add or subtract significands Normalize result

Slide 42

FP Arithmetic x/ Check for zero Add/subtract examples Multiply/separate significands (watch sign) Normalize Round All middle of the road results ought to be in twofold length stockpiling

Slide 43

Floating Point Multiplication

Slide 44

Floating Point Division

Slide 45

Exercises Read CH 8, IEEE 754 on IEEE Web website Email to: choi@laTech.edu Class notes (slides) online at: www.laTech.edu/~choi

Recommended
View more...