Professional Documents
Culture Documents
Role of The Compiler - Take QUIZ 5 Before 11:59pm Today Over Chapter 3 Readings - Topics - Number Representations - Computer Arithmetic
Role of The Compiler - Take QUIZ 5 Before 11:59pm Today Over Chapter 3 Readings - Topics - Number Representations - Computer Arithmetic
Last Time
Role of the Compiler
Today
Take QUIZ 5 before 11:59pm today over
Chapter 3 readings
Topics
Number Representations
Computer Arithmetic
Computer Arithmetic
1
Unsigned Binary Integers
Given an n-bit number
Range: 0 to +2n 1
Example
0000 0000 0000 0000 0000 0000 0000 10112
= 0 + + 123 + 022 +121 +120
= 0 + + 8 + 0 + 2 + 1 = 1110
Using 32 bits
0 to +4,294,967,295
Overflow Detection
Overflow: the result is too large (or too small) to represent properly
Example: - 8 < = 4-bit binary number <= 7
When adding operands with different signs, overflow cannot occur!
Overflow occurs when adding:
2 positive numbers and the sum is negative
2 negative numbers and the sum is positive
0 1 1 1 1 0
0 1 1 1 7 1 1 0 0 4
+ 0 0 1 1 3 + 1 0 1 1 5
1 0 1 0 6 0 1 1 1 7
2
Dealing with Overflow
What is 1 - 1?
What is zero?
3
Signed Integers: 2s-Complement
Represents: 2N1 to +2N11
2s-Complement
Example values for 8-bit twos complement integers
(most-significant bit on left)
0111 1 1 1 1 = 127
0111 1 1 1 0 = 126
0000 0010=2
0000 0001=1
0000 0000=0
1111 1 1 1 1 = 1
1111 1 1 1 0 = 2
1000 0 0 0 1 = 127
1000 0 0 0 0 = 128
Now, What is 1 1?
UTCS 352 Lecture 8
8
4
Conversion of 16 bit immediates to 32 bits
for performing arithmatic
ADD R2, R1, -3
6 5 5 16
ADD R1 R2 -3
1111111111111101
replicate
-3 32 bits
3
11111111111111111111111111111101
0000000000000011
replicate
This is called sign extension 3
00000000000000000000000000000011
Integer Arithmetic
Predict carry
Guess carry and correct
5
Multiplication
multiplicand
1000
multiplier
1001
1000
0000
0000
1000
product 1001000
Multiplication Hardware
Initially 0
6
Optimized Multiplier
Perform steps in parallel: add/shift
Faster Multiplier
Can be pipelined
Several multiplications performed in parallel
UTCS 352 Lecture 8
14
7
Floating Point
+0.002 104
not normalized
+987.02 109
In binary
1.xxxxxxx2 2yyyy
IEEE Standard 754-1985
Developed in response to divergence of representations
Made scientific codes portable
8
Double-Precision Range
9
Computer Floating-Point Addition
FP Hardware
10
FP Adder Hardware
Step 1
Step 2
Step 3
Step 4
Floating-Point Precision
Relative precision
all fraction bits are significant
Single: approx 223
Equivalent to 23 log102 23 0.3 6 decimal digits
of precision
Double: approx 252
Equivalent to 52 log102 52 0.3 16 decimal digits
of precision
11
Summary
12