Loading in 5 sec....

Vishwani D. Agrawal James J. Danaher Professor Department of Electrical and Computer EngineeringPowerPoint Presentation

Vishwani D. Agrawal James J. Danaher Professor Department of Electrical and Computer Engineering

- 73 Views
- Uploaded on

Download Presentation
## PowerPoint Slideshow about ' Vishwani D. Agrawal James J. Danaher Professor Department of Electrical and Computer Engineering' - xaviera-camacho

**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.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.

- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -

Presentation Transcript

### ELEC 5200-001/6200-001Computer Architecture and DesignFall 2008Symbol Representation and Floating Point Numbers (Chapters 2 and 3)

Vishwani D. Agrawal

James J. Danaher Professor

Department of Electrical and Computer Engineering

Auburn University, Auburn, AL 36849

http://www.eng.auburn.edu/~vagrawal

ELEC 5200-001/6200-001 Lecture 11

Symbol Representation Presently used –

- Early versions (60s and 70s)
- Six-bit binary code (CDC)
- EBCDIC – extended binary coded decimal interchange code (IBM)

- ASCII – American standard code for information interchange – byte (8 bit) code specified by American National Standards Institute (ANSI)
- Unicode – 16 bit code and an extended 32 bit version

ELEC 5200-001/6200-001 Lecture 11

ASCII

- Each byte pattern represents a character (symbol)
- Convenient to write in hexadecimal, e.g.,
- 00000000 0ten00hex null
- 01000001 65ten 41hex A
- 01100001 97ten 61hex a

- See Figure 2.21, page 91
- C program – string – terminating with a null byte
01000101 01000011 01000101 00000000

69ten or 45hex 67ten or43hex 69ten or 45hex 00ten or 00hex

E C E

- Convenient to write in hexadecimal, e.g.,

ELEC 5200-001/6200-001 Lecture 11

MIPS: load byte, store byte

- lb $t2, 0($t1) # read byte from memory and place in right-most 8 bits of $t2
- sb $t2, 0($t3) # write byte to memory from right-most 8 bits of $t2
- Examine the string copy procedure (C code) and the corresponding MIPS assembly code on pages 92-93.

ELEC 5200-001/6200-001 Lecture 11

Integers and Real Numbers

- Integers: the universe is infinite but discrete
- No fractions
- No numbers between consecutive integers, e.g., 5 and 6
- A countable (finite) number of items in a finite range
- Referred to as fixed-point numbers

- Real numbers – the universe is infinite and continuous
- Fractions represented by decimal notation
- Rational numbers, e.g., 5/2 = 2.5
- Irrational numbers, e.g., 22/7 = 3.14159265 . . .

- Infinite numbers exist even in the smallest range
- Referred to as floating-point numbers

- Fractions represented by decimal notation

ELEC 5200-001/6200-001 Lecture 11

Wide Range of Numbers

- A large number:
976,000,000,000,000 = 9.76 × 1014

- A small number:
0.0000000000000976 = 9.76 × 10 –14

ELEC 5200-001/6200-001 Lecture 11

Scientific Notation Binary numbers

- Decimal numbers
- 0.513×105, 5.13×104 and 51.3×103 are written in scientific notation.
- 5.13×104 is the normalized scientific notation.

- Base 2
- Binary point – multiplication by 2 moves the point to the right.
- Normalized scientific notation, e.g., 1.0two×2 –1

ELEC 5200-001/6200-001 Lecture 11

Floating Point Numbers

- General format
±1.bbbbbtwo×2eeee

or (-1)S × (1+F) × 2E

- Where
- S = sign, 0 for positive, 1 for negative
- F = fraction (or mantissa) as a binary integer, 1+F is called significand
- E = exponent as a binary integer, positive or negative (two’s complement)

ELEC 5200-001/6200-001 Lecture 11

Binary to Decimal Conversion

Binary (-1)S (1.b1b2b3b4) × 2E

Decimal (-1)S × (1 + b1×2-1 + b2×2-2 + b3×2-3 + b4×2-4) × 2E

Example: -1.1100 × 2-2 (binary) = - (1 + 2-1 + 2-2) ×2-2

= - (1 + 0.5 + 0.25)/4

= - 1.75/4

= - 0.4375 (decimal)

ELEC 5200-001/6200-001 Lecture 11

MIPS Single Precision

- – 128 ≤ E ≤ 127, Max |E| ~ 127, 2127 ~ 1038
- Range of magnitudes, 2×10-38 to 2×1038
- Overflow: Exponent requiring more than 8 bits. Number can be positive or negative.
- Underflow: Fraction requiring more than 23 bits. Number can be positive or negative.

S E: 8-bit Exponent F: 23-bit Fraction

bits 23-30

bits 0-22

bit 31

ELEC 5200-001/6200-001 Lecture 11

MIPS Double Precision

- Max |E| ~ 1023, 21023 ~ 10308
- Range of magnitudes, 2×10-308 to 2×10308
- Overflow: Exponent requiring more than 11 bits. Number can be positive or negative.
- Underflow: Fraction requiring more than 52 bits. Number can be positive or negative.

S E: 11-bit Exponent F: 52-bit Fraction +

bits 20-30

bits 0-19

bit 31

Continuation of 52-bit Fraction

bits 0-31

ELEC 5200-001/6200-001 Lecture 11

William Morton (Velvel) Kahan

Architect of the IEEE floating point standard

1989 Turing Award Citation:

For his fundamental contributions to numerical analysis. One of the foremost experts on floating-point computations. Kahan has dedicated himself to "making the world safe for numerical computations."

b. 1933, Canada

Professor of Computer Science, UC-Berkeley

ELEC 5200-001/6200-001 Lecture 11

Numbers in 32-bit Formats

- Two’s complement integers
- Floating point numbers
- Ref: W. Stallings, Computer Organization and Architecture, Sixth Edition, Upper Saddle River, NJ: Prentice-Hall.

Expressible numbers

-231

0

231-1

Positive underflow

Negative underflow

Positive zero

– ∞

Negative zero

+ ∞

Expressible positive

numbers

Expressible negative

numbers

Negative

Overflow

Positive

Overflow

-2-127

0

2-127

- (2 – 2-23)×2128

(2 – 2-23)×2128

ELEC 5200-001/6200-001 Lecture 11

IEEE 754 Floating Point Standard First bit of significand is always 1:

- Biased exponent: true exponent range
[-126,127] is changed to [1, 254]:

- Biased exponent is an 8-bit positive binary integer.
- True exponent obtained by subtracting 127ten or 01111111two

± 1.bbbb . . . b × 2E

- 1 before the binary point is implicitly assumed.
- Significand field represents 23 bit fraction after the binary point.
- Significand range is [1, 2), to be exact [1, 2 – 2-23]

ELEC 5200-001/6200-001 Lecture 11

IEEE 754 FP Standard (p. 194)

E: exponent, F: fraction, NaN: not a number, * see page 217

ELEC 5200-001/6200-001 Lecture 11

Examples

Biased exponent (0-255), bias 127 (01111111) to be subtracted

1.1010001 × 210100 = 0 10010011 10100010000000000000000 = 1.6328125 × 220

-1.1010001 × 210100 = 1 10010011 10100010000000000000000 = -1.6328125 × 220

1.1010001 × 2-10100 = 0 01101011 10100010000000000000000 = 1.6328125 × 2-20

-1.1010001 × 2-10100 = 1 01101011 10100010000000000000000 = -1.6328125 × 2-20

1.0

0.5

0.125

0.0078125

1.6328125

8-bit biased exponent

107 – 127

= – 20

23-bit Fraction (F)

of significand

Sign bit

ELEC 5200-001/6200-001 Lecture 11

Example: Conversion to Decimal

normalized E

F

- Sign bit is 1, number is negative
- Biased exponent is 27+20 = 129
- The number is

bits 23-30

bits 0-22

Sign bit S

1 10000001 01000000000000000000000

(-1)S × (1 + F) × 2(exponent – bias) = (-1)1 × (1 + F) × 2(129 – 127)

= - 1 × 1.25 × 22

= - 1.25 × 4

= - 5.0

ELEC 5200-001/6200-001 Lecture 11

IEEE 754 Floating Point Format

- Floating point numbers

Positive underflow

Negative underflow

– ∞

+ ∞

Expressible positive

numbers

Expressible negative

numbers

Negative

Overflow

Positive

Overflow

-2-126

0

2-126

- (2 – 2-23)×2127

(2 – 2-23)×2127

ELEC 5200-001/6200-001 Lecture 11

Positive Zero in IEEE 754

- + 1.0 × 2-127
- Smallest positive number in single-precision IEEE 754 standard.
- Interpreted as positive zero.
- True exponentless than -126 is positive underflow; can be regarded as zero.

00000000000000000000000000000000

Biased

exponent

Fraction

ELEC 5200-001/6200-001 Lecture 11

Negative Zero in IEEE 754

- - 1.0 × 2-127
- Smallest negative number in single-precision IEEE 754 standard.
- Interpreted as negative zero.
- True exponent less than -126 is negative underflow; may be regarded as 0.

10000000000000000000000000000000

Biased

exponent

Fraction

ELEC 5200-001/6200-001 Lecture 11

Positive Infinity in IEEE 754

- + 1.0 × 2128
- Largest positive number in single-precision IEEE 754 standard.
- Interpreted as + ∞
- If true exponent = 128 and fraction ≠ 0, then the number is greater than ∞. It is called “not a number” or NaN and may be interpreted as ∞.

01111111100000000000000000000000

Biased

exponent

Fraction

ELEC 5200-001/6200-001 Lecture 11

Negative Infinity in IEEE 754

- -1.0 × 2128
- Smallest negative number in single-precision IEEE 754 standard.
- Interpreted as - ∞
- If true exponent = 128 and fraction ≠ 0, then the number is less than - ∞. It is called “not a number” or NaN and may be interpreted as - ∞.

11111111100000000000000000000000

Biased

exponent

Fraction

ELEC 5200-001/6200-001 Lecture 11

Addition and Subtraction

0. Zero check

- Change the sign of subtrahend, i.e., convert to summation

- If either operand is 0, the other is the result

1. Significand alignment: right shift significand of smaller exponent until two exponents match.

2. Addition: add significands and report exception if overflow occurs. If significand = 0, return result as 0.

3. Normalization

- Shift significand bits to normalize.

- report overflow or underflow if exponent goes out of range.

4. Rounding

ELEC 5200-001/6200-001 Lecture 11

Example (4 Significant Fraction Bits)

- Subtraction: 0.5ten – 0.4375ten
- Step 0: Floating point numbers to be added
1.000two× 2 –1 and –1.110two× 2 –2

- Step 1: Significand of lesser exponent is shifted right until exponents match
–1.110two× 2 –2 → – 0.111two× 2 –1

- Step 2: Add significands, 1.000two + ( – 0.111two)
Result is 0.001two× 2 –1

01000

+11001

00001

2’s complement addition, one bit added for sign

ELEC 5200-001/6200-001 Lecture 11

Example (Continued)

- Step 3: Normalize, 1.000two× 2– 4
No overflow/underflow since

127 ≥ exponent ≥ –126

- Step 4: Rounding, no change since the sum fits in 4 bits.
1.000two× 2– 4 = (1+0)/16 = 0.0625ten

ELEC 5200-001/6200-001 Lecture 11

IEEE 754 “guard” and “round” Bits

- Two extra bits, called guard and round, on the right are used for all intermediate additions.
- Illustration by decimal addition:
- Consider 3 significant digits
- Use one guard digit and one round digit

2.34 × 102 +2.56 × 100 = 2.3400 × 102 +0.0256 × 102

With guard/round digits Without guard/round digits

2.3400 2.34

+ 0.0256+ 0.02

2.3656 2.36

Result: 2.37 × 102 Result: 2.36 × 102

ELEC 5200-001/6200-001 Lecture 11

FP Multiplication: Basic Idea

- Separate sign
- Add exponents
- Multiply significands
- Normalize, round, check overflow/underflow
- Replace sign

ELEC 5200-001/6200-001 Lecture 11

FP Multiplication: Step 0

Multiply, X × Y

X = 0?

Y = 0?

no

no

Steps 1 - 5

yes

yes

Z = 0

Return

ELEC 5200-001/6200-001 Lecture 11

FP Multiplication Illustration

- Multiply 0.5ten and – 0.4375ten
(answer = – 0.21875ten) or

- Multiply 1.000two×2–1 and –1.110two×2–2
- Step 1: Add exponents
–1 + (–2) = – 3

- Step 2: Multiply significands
1.000

×1.110

0000

1000

1000

1000

1110000 Product is 1.110000

ELEC 5200-001/6200-001 Lecture 11

FP Mult. Illustration (Cont.)

- Step 3:
- Normalization: If necessary, shift significand right and increment exponent.
Normalized product is 1.110000 × 2 –3

- Check overflow/underflow: 127 ≥ exponent ≥ –126

- Normalization: If necessary, shift significand right and increment exponent.
- Step 4: Rounding: 1.110 × 2 –3
- Step 5: Sign: Operands have opposite signs,
Product is –1.110 × 2 –3

(Decimal value = – (1+0.5+0.25)/8 = – 0.21875ten)

ELEC 5200-001/6200-001 Lecture 11

FP Division: Basic Idea

- Separate sign.
- Check for zeros and infinity.
- Subtract exponents.
- Divide significands.
- Normalize and detect overflow/underflow.
- Perform rounding.
- Replace sign.

ELEC 5200-001/6200-001 Lecture 11

MIPS Floating Point Instructions Arithmetic instructions: (xxx=add, sub, mul, div)

- 32 floating point registers, $f0, . . . , $f31
- FP registers used in pairs for double precision; $f0 denotes double precision content of $f0,$f1
- Data transfer instructions:
- lwc1 $f1, 100($s2) # $f1←Mem[$s2+100]
- swc1 $f1, 100($s2) # Mem[$s2+100]←$f1

- xxx.s single precision
- xxx.d double precision

ELEC 5200-001/6200-001 Lecture 11

MIPS Floating Point Instructions

- Conditional branch instructions:
- bc1t cc offset # if(condition cc is true) go to PC + 4 + 4×offset
- bc1f cc offset # if(condition cc is false) go to PC + 4 + 4×offset
- c.xx.s cc $f2, $f4 # xx=eq, lt, le, gt, ge, neq
where cc = 0 or 1, is a condition flag

ELEC 5200-001/6200-001 Lecture 11

Recommended

- Visit www.computerhistory.org to learn about the developments in computers. Many names and events in your book and those discussed in the class appear there.
- When in Silicon Valley, visit the Computer History Museum (Route 101, Mountain View, CA).

ELEC 5200-001/6200-001 Lecture 11

Download Presentation

Connecting to Server..