Lecture6 - CIS 450 Computer Architecture and Organization Lecture 6 Machine-Level Programming I Mitch Neilsen [email protected] 219D Nichols Hall

Info iconThis preview shows pages 1–12. Sign up to view the full content.

View Full Document Right Arrow Icon
CIS 450 Computer Architecture and Organization Lecture 6: Machine-Level Programming I Mitch Neilsen Mitch Neilsen [email protected] [email protected] 219D Nichols Hall 219D Nichols Hall
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
–2– Topics Topics ± Creating Floating Point Numbers ± Assembly Programmer’s Execution Model ± Accessing Information z Registers z Memory ± Arithmetic Operations
Background image of page 2
–3– Creating Floating Point Number Creating Floating Point Number Steps Steps ± Normalize to have leading 1 ± Round to fit within fraction ± Postnormalize to deal with effects of rounding Case Study Case Study ± Convert 8-bit unsigned numbers to tiny floating point format ± Example Numbers 128 10000000 15 00001101 33 00010001 35 00010011 138 10001010 63 00111111 s exp frac 0 2 3 6 7
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
–4– Normalize Normalize Requirement Requirement ± Set binary point so that numbers of form 1.xxxxx ± Adjust all to have leading one z Decrement exponent as shift left Value Binary Fraction Exponent 128 10000000 1.0000000 7 13 00001101 1.1010000 3 17 00010001 1.0001000 4 19 00010011 1.0011000 4 138 10001010 1.0001010 7 63 00111111 1.1111100 5 s exp frac 0 2 3 6 7
Background image of page 4
–5– Rounding Rounding 1.BBG RXXX Round up conditions Round up conditions ± Round = 1, Sticky = 1 Î > 0.5 ± Guard = 1, Round = 1, Sticky = 0 Î Round to even Value Fraction GRS Incr? Rounded 128 1.000 0000 000 N 1.000 13 1.101 0000 100 N 1.101 17 1.000 1000 010 N 1.000 19 1.001 1000 110 Y 1.010 138 1.000 1010 011 Y 1.001 63 1.111 1100 111 Y 10.000 Guard bit: LSB of result Round bit: 1 bit removed st Sticky bit: OR of remaining bits
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
–6– Postnormalize Postnormalize Issue Issue ± Rounding may have caused overflow ± Handle by shifting right once & incrementing exponent Value Rounded Exp Adjusted Result 128 1.000 7 128 13 1.101 3 13 17 1.000 4 16 19 1.010 4 20 138 1.001 7 144 63 10.000 5 1.000/6 64
Background image of page 6
–7– Floating Point in C Floating Point in C C Guarantees Two Levels C Guarantees Two Levels float single precision double double precision Conversions Conversions ± Casting between int , float , and double changes numeric values ± Double or float to int z Truncates fractional part z Like rounding toward zero z Not defined when out of range or NaN » Generally sets to TMin ± int to double z Exact conversion, as long as int has 53 bit word size ± int to float z Will round according to rounding mode
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
–8– Curious Excel Behavior Curious Excel Behavior ± Spreadsheets use floating point for all computations ± Some imprecision for decimal arithmetic ± Can yield non-intuitive results to an accountant! Number Subtract 16 Subtract .3 Subtract .01 Default Format 16.31 0.31 0.01 -1.2681E-15 Currency Format $16.31 $0.31 $0.01 ($0.00) Subtract .3 0.01
Background image of page 8
–9– Floating Point Summary Floating Point Summary IEEE Floating Point Has Clear Mathematical IEEE Floating Point Has Clear Mathematical Properties Properties ± Represents numbers of form M X 2 E ± Can reason about operations independent of implementation z As if computed with perfect precision and then rounded ± Not the same as real arithmetic z Violates associativity/distributivity z Makes life difficult for compilers & serious numerical applications programmers
Background image of page 9

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
–10– Floating Point Quiz Floating Point Quiz
Background image of page 10
–11– Solution Solution Description | Binary | M | E | Value Description | Binary | M | E | Value ---------------------------------------------------------------- ---------------------------------------------------------------- -- -- Minus Zero | 1 000 0000 | 0 | Minus Zero | 1 000 0000 | 0 -2 | 2 | -0.0 0.0 ---------------------------------------------------------------- ---------------------------------------------------------------- -- -- --- --- | 0 100 0101 | 21/16 | 1 |
Background image of page 11

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 12
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 04/09/2008 for the course CIS 450 taught by Professor Neilsen,mitch during the Spring '08 term at Kansas State University.

Page1 / 42

Lecture6 - CIS 450 Computer Architecture and Organization Lecture 6 Machine-Level Programming I Mitch Neilsen [email protected] 219D Nichols Hall

This preview shows document pages 1 - 12. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online