Lecture4
Lecture4
Announcement
• Programming Assignment 1 is out
• Details:
https://www.cs.rochester.edu/courses/252/fall2024/labs/
assignment1.html
• Due on Sep. 16th, 11:59 PM
• You have 3 slip days
• Office Hour Location Has Changed
• For office hours on Thursday and Friday
• Check course website
2
Fractional Binary Numbers
2i
2i-1
4
••• 2
1
2-j
3
Fixed-Point Representation
• Binary point stays fixed
• Fixed interval between representable
numbers
• The interval in this example is 0.2510
4
Fixed-Point Representation
Decimal Binary
• Binary point stays fixed 0 0000.
• Fixed interval between representable 1
2
0001.
0010.
numbers 3 0011.
• The interval in this example is 0.2510 4 0100.
5 0101.
6 0110.
7 0111.
8 1000.
9 1001.
10 1010.
11 1011.
12 1100.
13 1101.
14 1110.
15 1111.
4
Fixed-Point Representation
Decimal Binary
• Binary point stays fixed 0 0000.
• Fixed interval between representable 1
2
0001.
0010.
numbers 3 0011.
• The interval in this example is 0.2510 4 0100.
5 0101.
6 0110.
0 1 2 3 4 5 6 7 …. 15 7 0111.
8 1000.
9 1001.
10 1010.
11 1011.
12 1100.
13 1101.
14 1110.
15 1111.
4
Fixed-Point Representation
Decimal Binary
• Binary point stays fixed 0 00.00
• Fixed interval between representable 0.25
0.5
00.01
00.10
numbers 0.75 00.11
• The interval in this example is 0.2510 1 01.00
1.25 01.01
1.5 01.10
0 1 2 3 4 5 6 7 …. 15 1.75 01.11
2 10.00
2.25 10.01
2.5 10.10
2.75 10.11
3 11.00
3.25 11.01
3.5 11.10
3.75 11.11
4
Fixed-Point Representation
Decimal Binary
• Binary point stays fixed 0 00.00
• Fixed interval between representable 0.25
0.5
00.01
00.10
numbers 0.75 00.11
• The interval in this example is 0.2510 1 01.00
1.25 01.01
1.5 01.10
0 1 2 3 1.75 01.11
2 10.00
2.25 10.01
2.5 10.10
2.75 10.11
3 11.00
3.25 11.01
3.5 11.10
3.75 11.11
4
Carnegie Mellon
b3b2.b1b0
0 1/4 1/2 3/4 5/4 3/2 7/4 2 …. 15/4
5
Limitations of Fixed-Point (#2)
• Can’t represent very small and very large numbers at
the same time
• To represent very large numbers, the (fixed) interval needs
to be large, making it hard to represent small numbers
• To represent very small numbers, the (fixed) interval needs
to be small, making it hard to represent large numbers
….
+∞
0
6
Limitations of Fixed-Point (#2)
• Can’t represent very small and very large numbers at
the same time
• To represent very large numbers, the (fixed) interval needs
to be large, making it hard to represent small numbers
• To represent very small numbers, the (fixed) interval needs
to be small, making it hard to represent large numbers
Unrepresentable
small numbers
….
+∞
0
A Large
Number
6
Limitations of Fixed-Point (#2)
• Can’t represent very small and very large numbers at
the same time
• To represent very large numbers, the (fixed) interval needs
to be large, making it hard to represent small numbers
• To represent very small numbers, the (fixed) interval needs
to be small, making it hard to represent large numbers
….
+∞
0
A Small
Number
6
Limitations of Fixed-Point (#2)
• Can’t represent very small and very large numbers at
the same time
• To represent very large numbers, the (fixed) interval needs
to be large, making it hard to represent small numbers
• To represent very small numbers, the (fixed) interval needs
to be small, making it hard to represent large numbers
Unrepresentable
large numbers
….
+∞
0
A Small
Number
6
Primer: Floating Point Representation
• In binary: (–1)s M 2E Sign Exponent
• Normalized form:
• 1<= M < 2
• M = 1.b0b1b2b3… (-1)s M × 2E
Fraction
• Encoding Significand Base
• MSB s is sign bit s
• exp field encodes Exponent (but not exactly the same, more later)
• frac field encodes Fraction (but not exactly the same, more later)
s exp frac
7
Carnegie Mellon
1 3 2
• exp has 3 bits, interpreted as an unsigned value
• If exp were E, we could represent exponents from 0 to 7
• How about negative exponent?
• Subtract a bias term: E = exp - bias (i.e., exp = E + bias)
• bias is always 2k-1 - 1, where k is number of exponent bits
8
Carnegie Mellon
1 3 2
• exp has 3 bits, interpreted as an unsigned value E exp
• If exp were E, we could represent exponents from 0 to 7 -3 000
• How about negative exponent? -2 001
• Subtract a bias term: E = exp - bias (i.e., exp = E + bias)
-1 010
0 011
• bias is always 2k-1 - 1, where k is number of exponent bits
1 100
• Example when we use 3 bits for exp (i.e., k = 3): 23 101
110
• bias = 3 4 111
• If E = -2, exp is 1 (0012)
• Reserve 000 and 111 for other purposes (more on this later)
• We can now represent exponents from -2 (exp 001) to 3 (exp 110)
8
Carnegie
Carnegie Mellon
Mello
1 3 2
• frac has 2 bits, append them after “1.” to form M E exp
• frac = 10 implies M = 1.10 -3 000
• Putting it Together: An Example: -2 001
-1 010
0 011
1 100
9
Carnegie
Carnegie Mellon
Mello
1 3 2
• frac has 2 bits, append them after “1.” to form M E exp
• frac = 10 implies M = 1.10 -3 000
• Putting it Together: An Example: -2 001
-1 010
0 011
1 100
9
Carnegie
Carnegie Mellon
Mello
1 3 2
• frac has 2 bits, append them after “1.” to form M E exp
• frac = 10 implies M = 1.10 -3 000
• Putting it Together: An Example: -2 001
-1 010
0 011
1 100
9
Carnegie
Carnegie Mellon
Mello
1 3 2
• frac has 2 bits, append them after “1.” to form M E exp
• frac = 10 implies M = 1.10 -3 000
• Putting it Together: An Example: -2 001
-1 010
0 011
1 100
9
Carnegie
Carnegie Mellon
Mello
1 3 2
• frac has 2 bits, append them after “1.” to form M E exp
• frac = 10 implies M = 1.10 -3 000
• Putting it Together: An Example: -2 001
-1 010
0 011
1 100
9
Carnegie
Carnegie Mellon
Mello
1 3 2
• frac has 2 bits, append them after “1.” to form M E exp
• frac = 10 implies M = 1.10 -3 000
• Putting it Together: An Example: -2 001
-1 010
0 011
1 100
9
Carnegie
Carnegie Mellon
Mello
1 3 2
• frac has 2 bits, append them after “1.” to form M E exp
• frac = 10 implies M = 1.10 -3 000
• Putting it Together: An Example: -2 001
-1 010
0 011
1 100
9
Carnegie
Carnegie Mellon
Mello
0 +∞
10
Carnegie
Carnegie Mellon
Mello
0 +∞
10
Carnegie
Carnegie Mellon
Mello
0 +∞
1/4
10
Carnegie
Carnegie Mellon
Mello
1/2
0 +∞
1/4
11
Carnegie
Carnegie Mellon
Mello
1/2
0 1 +∞
1/4
12
Carnegie
Carnegie Mellon
Mello
1/2
0 1 2 +∞
1/4
13
Carnegie
Carnegie Mellon
Mello
1/2
0 1 2 4 +∞
1/4
14
Carnegie
Carnegie Mellon
Mello
1/2
0 1 2 4 8 +∞
1/4
15
Carnegie
Carnegie Mellon
Mello
1/2
0 1 2 4 8 1.01 x 23 +∞
1/4
16
Carnegie
Carnegie Mellon
Mello
1/2
0 1 2 4 8 10 +∞
1/4
17
Carnegie
Carnegie Mellon
Mello
1/2 1.10 x 23
0 1 2 4 8 10 +∞
1/4
18
Carnegie
Carnegie Mellon
Mello
1/2 12
0 1 2 4 8 10 +∞
1/4
19
Carnegie
Carnegie Mellon
Mello
1/2 12
0 1 2 4 8 10 14 +∞
1/4
20
Carnegie
Carnegie Mellon
Mello
1/2 1.11 x 22 12
0 1 2 4 8 10 14 +∞
1/4
21
Carnegie
Carnegie Mellon
Mello
1/2 7 12
0 1 2 4 8 10 14 +∞
1/4
22
Carnegie
Carnegie Mellon
Mello
1/2 7 12
0 1 2 4 1.10 x 22 8 10 14 +∞
1/4
23
Carnegie
Carnegie Mellon
Mello
1/2 7 12
0 1 2 4 6 8 10 14 +∞
1/4
24
Carnegie
Carnegie Mellon
Mello
1/2 1.01 x 22 7 12
0 1 2 4 6 8 10 14 +∞
1/4
25
Carnegie
Carnegie Mellon
Mello
1/2 5 7 12
0 1 2 4 6 8 10 14 +∞
1/4
26
Carnegie
Carnegie Mellon
Mello
1/2 5 7 12
0 1 2 4 6 8 10 14 +∞
1/4
27
Carnegie
Carnegie Mellon
Mello
1/2 5 7 12
0 1 2 4 6 8 10 14 +∞
1/4
28
Carnegie
Carnegie Mellon
Mello
1/2 5 7 12
0 1 2 4 6 8 10 14 +∞
1/4
29
Carnegie
Carnegie Mellon
Mello
1/2 5 7 12
0 1 2 4 6 8 10 14 +∞
1/4
30
Carnegie
Carnegie Mellon
Mello
1/2 5 7 12
0 1 2 4 6 8 10 14 +∞
1/4
31
Carnegie
Carnegie Mellon
Mello
1/2 5 7 12
0 1 2 4 6 8 10 14 +∞
1/4
31
Carnegie
Carnegie Mellon
Mello
1/2 5 7 12
0 1 2 4 6 8 10 14 +∞
1/4
31
Carnegie
CarnegieMellon
Mellon
0 5/16 7/16 1
32
Carnegie
CarnegieMellon
Mellon
Unrepresented
small numbers 1/4 3/8 1/2
0 5/16 7/16 1
32
Carnegie
CarnegieMellon
Mellon
Unrepresented
small numbers 1/4 3/8 1/2
0 5/16 7/16 1
32
Carnegie
CarnegieMellon
Mellon
Unrepresented
small numbers 1/4 3/8 1/2
0 5/16 7/16 1
32
Carnegie
CarnegieMellon
Mellon
Unrepresented
small numbers 1/4 3/8 1/2
32
Carnegie
CarnegieMellon
Mellon
Unrepresented
small numbers 1/4 3/8 1/2
32
Carnegie
CarnegieMellon
Mellon
0 5/16 7/16 1
33
Carnegie
CarnegieMellon
Mellon
33
Carnegie
CarnegieMellon
Mellon
33
Carnegie
CarnegieMellon
Mellon
Special Values
E exp E exp
v = (–1)s M 2E s exp frac -2 000 1 100
-2 001 2 101
-1 010 3 110
0 011 4 111
34
Carnegie Mellon
Special Values
E exp E exp
v = (–1)s M 2E s exp frac -2 000 1 100
-2 001 2 101
-1 010 3 110
0 011 4 111
34
Carnegie Mellon
Special Values
E exp E exp
v = (–1)s M 2E s exp frac -2 000 1 100
-2 001 2 101
-1 010 3 110
0 011 4 111
34
Carnegie Mellon
Special Values
E exp E exp
v = (–1)s M 2E s exp frac -2 000 1 100
-2 001 2 101
-1 010 3 110
0 011 4 111
34
Carnegie Mellon
Special Values
E exp E exp
v = (–1)s M 2E s exp frac -2 000 1 100
-2 001 2 101
-1 010 3 110
0 011 4 111
34
Carnegie Mellon
Special Values
E exp E exp
v = (–1)s M 2E s exp frac -2 000 1 100
-2 001 2 101
-1 010 3 110
0 011 4 111
NaN NaN
-0 +0
35
Visualization: Floating Point Encodings
−¥ −Normalized −Subnorm +Subnorm +Normalized +∞
NaN NaN
-0 +0
35
Visualization: Floating Point Encodings
−¥ −Normalized −Subnorm +Subnorm +Normalized +∞
NaN NaN
-0 +0
NaN NaN
-0 +0
Sparse Sparse
NaN NaN
-0 +0
36
Carnegie Mellon
1 8-bit 23-bit
1 11-bit 52-bit
37
Carnegie Mellon
38
Carnegie Mellon
39
Carnegie Mellon
1521310 = 111011011011012
= (-1)0 1.11011011011012 x 213
39
Carnegie Mellon
1521310 = 111011011011012
= (-1)0 1.11011011011012 x 213
39
Carnegie Mellon
1521310 = 111011011011012
= (-1)0 1.11011011011012 x 213
39
Carnegie Mellon
1521310 = 111011011011012
= (-1)0 1.11011011011012 x 213
exp = E + bias = 14010
39
Carnegie Mellon
1521310 = 111011011011012
= (-1)0 1.11011011011012 x 213
exp = E + bias = 14010
39
Carnegie Mellon
1521310 = 111011011011012
= (-1)0 1.11011011011012 x 213
exp = E + bias = 14010
39
Carnegie Mellon
1 8-bit 23-bit
1521310 = 111011011011012
= (-1)0 1.11011011011012 x 213
exp = E + bias = 14010
39
Carnegie Mellon
40
Carnegie Mellon
41
Carnegie Mellon
42
Carnegie Mellon
42
Carnegie Mellon
42
Carnegie Mellon
43
Carnegie Mellon
43
Carnegie Mellon
43
Carnegie Mellon
1.000011
43
Carnegie Mellon
1.000110
43
Carnegie Mellon
1.000100
43
Carnegie Mellon
1.001100
43
Floating Point Addition
44
Floating Point Addition
• (–1)s1 M1 2E1 + (-1)s2 M2 2E2 1.000 x 2-1 + 1.101 x 2-3
44
Floating Point Addition
• (–1)s1 M1 2E1 + (-1)s2 M2 2E2 1.000 x 2-1 + 1.101 x 2-3
•
align 1.000 x 2-1 + 0.1101 x 2-1
44
Floating Point Addition
• (–1)s1 M1 2E1 + (-1)s2 M2 2E2 1.000 x 2-1 + 1.101 x 2-3
•
1.000 x 2-1 + 0.1101 x 2-1
44
Floating Point Addition
• (–1)s1 M1 2E1 + (-1)s2 M2 2E2 1.000 x 2-1 + 1.101 x 2-3
• Exact Result: (–1)s M 2E
• Sign s, significand M:
• Result of signed align & add 1.000 x 2-1 + 0.1101 x 2-1
• Exponent E: E1
• Assume E1 > E2
1.1101 x 2-1
44
Floating Point Addition
• (–1)s1 M1 2E1 + (-1)s2 M2 2E2 1.000 x 2-1 + 1.101 x 2-3
• Exact Result: (–1)s M 2E
• Sign s, significand M:
• Result of signed align & add 1.000 x 2-1 + 0.1101 x 2-1
• Exponent E: E1
• Assume E1 > E2
44
Floating Point Addition
• (–1)s1 M1 2E1 + (-1)s2 M2 2E2 1.000 x 2-1 + 1.101 x 2-3
• Exact Result: (–1)s M 2E
• Sign s, significand M:
• Result of signed align & add 1.000 x 2-1 + 0.1101 x 2-1
• Exponent E: E1
• Assume E1 > E2
44
Mathematical Properties of FP Add
45
Mathematical Properties of FP Add
• Commutative? a+b =b+a
45
Mathematical Properties of FP Add
• Commutative? a+b =b+a Yes
45
Mathematical Properties of FP Add
• Commutative? a+b =b+a Yes
• Associative? a+b+c = a+(b+c)
•
45
Mathematical Properties of FP Add
• Commutative? a+b =b+a Yes
• Associative? a+b+c = a+(b+c) No
• Overflow and inexactness of rounding
• (3.14+1e10)-1e10 = 0, 3.14+(1e10-1e10) = 3.14
45
Mathematical Properties of FP Add
• Commutative? a+b =b+a Yes
• Associative? a+b+c = a+(b+c) No
• Overflow and inexactness of rounding
• (3.14+1e10)-1e10 = 0, 3.14+(1e10-1e10) = 3.14
1.000 x 25 + 1.101 x 2-3
45
Mathematical Properties of FP Add
• Commutative? a+b =b+a Yes
• Associative? a+b+c = a+(b+c) No
• Overflow and inexactness of rounding
• (3.14+1e10)-1e10 = 0, 3.14+(1e10-1e10) = 3.14
1.000 x 25 + 1.101 x 2-3
1.000 x 25 + 0.00000001101x 25
45
Mathematical Properties of FP Add
• Commutative? a+b =b+a Yes
• Associative? a+b+c = a+(b+c) No
• Overflow and inexactness of rounding
• (3.14+1e10)-1e10 = 0, 3.14+(1e10-1e10) = 3.14
1.000 x 25 + 1.101 x 2-3
1.000 x 25 + 0.00000001101x 25
1. 00000001101 x 25
45
Mathematical Properties of FP Add
• Commutative? a+b =b+a Yes
• Associative? a+b+c = a+(b+c) No
• Overflow and inexactness of rounding
• (3.14+1e10)-1e10 = 0, 3.14+(1e10-1e10) = 3.14
1.000 x 25 + 1.101 x 2-3
1.000 x 25 + 0.00000001101x 25
1. 00000001101 x 25
1.000 x 25 45
Mathematical Properties of FP Add
• Commutative? a+b =b+a Yes
• Associative? a+b+c = a+(b+c) No
• Overflow and inexactness of rounding
• (3.14+1e10)-1e10 = 0, 3.14+(1e10-1e10) = 3.14
46
Mathematical Properties of FP Add
• Commutative? a+b =b+a Yes
• Associative? a+b+c = a+(b+c) No
• Overflow and inexactness of rounding
• (3.14+1e10)-1e10 = 0, 3.14+(1e10-1e10) = 3.14
• 0 is additive identity?
46
Mathematical Properties of FP Add
• Commutative? a+b =b+a Yes
• Associative? a+b+c = a+(b+c) No
• Overflow and inexactness of rounding
• (3.14+1e10)-1e10 = 0, 3.14+(1e10-1e10) = 3.14
• 0 is additive identity? Yes
46
Mathematical Properties of FP Add
• Commutative? a+b =b+a Yes
• Associative? a+b+c = a+(b+c) No
• Overflow and inexactness of rounding
• (3.14+1e10)-1e10 = 0, 3.14+(1e10-1e10) = 3.14
• 0 is additive identity? Yes
• Every element has additive inverse (negation)?
•
46
Mathematical Properties of FP Add
• Commutative? a+b =b+a Yes
• Associative? a+b+c = a+(b+c) No
• Overflow and inexactness of rounding
• (3.14+1e10)-1e10 = 0, 3.14+(1e10-1e10) = 3.14
• 0 is additive identity? Yes
• Every element has additive inverse (negation)? Almost
• Except for infinities & NaNs
•
46
Mathematical Properties of FP Add
• Commutative? a+b =b+a Yes
• Associative? a+b+c = a+(b+c) No
• Overflow and inexactness of rounding
• (3.14+1e10)-1e10 = 0, 3.14+(1e10-1e10) = 3.14
• 0 is additive identity? Yes
• Every element has additive inverse (negation)? Almost
• Except for infinities & NaNs
• Monotonicity: a ≥ b ⇒ a+c ≥ b+c?
•
46
Mathematical Properties of FP Add
• Commutative? a+b =b+a Yes
• Associative? a+b+c = a+(b+c) No
• Overflow and inexactness of rounding
• (3.14+1e10)-1e10 = 0, 3.14+(1e10-1e10) = 3.14
• 0 is additive identity? Yes
• Every element has additive inverse (negation)? Almost
• Except for infinities & NaNs
• Monotonicity: a ≥ b ⇒ a+c ≥ b+c? Almost
• Except for infinities & NaNs
46
Carnegie Mellon
47
Carnegie Mellon
47
Carnegie Mellon
47
Carnegie Mellon
47
Carnegie Mellon
47
Mathematical Properties of FP Mult
48
Mathematical Properties of FP Mult
• Multiplication Commutative?
48
Mathematical Properties of FP Mult
• Multiplication Commutative? Yes
48
Mathematical Properties of FP Mult
• Multiplication Commutative? Yes
• Multiplication is Associative?
•
48
Mathematical Properties of FP Mult
• Multiplication Commutative? Yes
• Multiplication is Associative? No
• Possibility of overflow, inexactness of rounding
• Ex: (1e20*1e20)*1e-20= inf, 1e20*(1e20*1e-20)= 1e20
48
Mathematical Properties of FP Mult
• Multiplication Commutative? Yes
• Multiplication is Associative? No
• Possibility of overflow, inexactness of rounding
• Ex: (1e20*1e20)*1e-20= inf, 1e20*(1e20*1e-20)= 1e20
• 1 is multiplicative identity?
48
Mathematical Properties of FP Mult
• Multiplication Commutative? Yes
• Multiplication is Associative? No
• Possibility of overflow, inexactness of rounding
• Ex: (1e20*1e20)*1e-20= inf, 1e20*(1e20*1e-20)= 1e20
• 1 is multiplicative identity? Yes
48
Mathematical Properties of FP Mult
• Multiplication Commutative? Yes
• Multiplication is Associative? No
• Possibility of overflow, inexactness of rounding
• Ex: (1e20*1e20)*1e-20= inf, 1e20*(1e20*1e-20)= 1e20
• 1 is multiplicative identity? Yes
• Multiplication distributes over addition?
• a*(b+c) = a*b+a*c?
•
48
Mathematical Properties of FP Mult
• Multiplication Commutative? Yes
• Multiplication is Associative? No
• Possibility of overflow, inexactness of rounding
• Ex: (1e20*1e20)*1e-20= inf, 1e20*(1e20*1e-20)= 1e20
• 1 is multiplicative identity? Yes
• Multiplication distributes over addition? No
• a*(b+c) = a*b+a*c?
• Possibility of overflow, inexactness of rounding
• 1e20*(1e20-1e20)= 0.0, 1e20*1e20 – 1e20*1e20 = NaN
•
48
Mathematical Properties of FP Mult
• Multiplication Commutative? Yes
• Multiplication is Associative? No
• Possibility of overflow, inexactness of rounding
• Ex: (1e20*1e20)*1e-20= inf, 1e20*(1e20*1e-20)= 1e20
• 1 is multiplicative identity? Yes
• Multiplication distributes over addition? No
• a*(b+c) = a*b+a*c?
• Possibility of overflow, inexactness of rounding
• 1e20*(1e20-1e20)= 0.0, 1e20*1e20 – 1e20*1e20 = NaN
• Monotonicity: a ≥ b & c ≥ 0 ⇒ a * c ≥ b *c?
•
48
Mathematical Properties of FP Mult
• Multiplication Commutative? Yes
• Multiplication is Associative? No
• Possibility of overflow, inexactness of rounding
• Ex: (1e20*1e20)*1e-20= inf, 1e20*(1e20*1e-20)= 1e20
• 1 is multiplicative identity? Yes
• Multiplication distributes over addition? No
• a*(b+c) = a*b+a*c?
• Possibility of overflow, inexactness of rounding
• 1e20*(1e20-1e20)= 0.0, 1e20*1e20 – 1e20*1e20 = NaN
• Monotonicity: a ≥ b & c ≥ 0 ⇒ a * c ≥ b *c? Almost
• Except for infinities & NaNs
48
Floating Point in C
C Data Max Value
Bits Max Value
Type (Decimal)
{
char 8 27 - 1 127
short 16 215 - 1 32767
Fixed point
int 32 231 - 1 2147483647
(implicit binary point)
long 64 263 - 1 ~9.2 × 1018
49
Floating Point in C
C Data Max Value
Bits Max Value
Type (Decimal)
{
char 8 27 - 1 127
short 16 215 - 1 32767
Fixed point
int 32 231 - 1 2147483647
(implicit binary point)
long 64 263 - 1 ~9.2 × 1018
49
Floating Point in C
C Data Max Value
Bits Max Value
Type (Decimal)
{
char 8 27 - 1 127
short 16 215 - 1 32767
Fixed point
int 32 231 - 1 2147483647
(implicit binary point)
long 64 263 - 1 ~9.2 × 1018
49
Floating Point in C
• double/float → int
• Truncates fractional part
• Like rounding toward zero
• Not defined when out of range or NaN
50
Floating Point in C
• double/float → int
• Truncates fractional part
• Like rounding toward zero
• Not defined when out of range or NaN
• int → float
• Can’t guarantee exact casting. Will round according to rounding mode
s exp frac
1 8-bit 23-bit
• int → double
s exp frac
1 11-bit 52-bit
50
Carnegie Mellon
s exp frac
51
Carnegie Mellon
51
Carnegie Mellon
51
Carnegie Mellon
51
Carnegie Mellon
52
Carnegie Mellon
52
Carnegie Mellon
52
So far in 252…
int, float
C Program if, else
+, -, >>
53
So far in 252…
int, float
C Program if, else
+, -, >>
Compiler
Equivalent ret, call
Assembly fadd, add
Program jmp, jne
Semantically
Assembler
Equivalent
00001111
Machine 01010101
Code 11110000
Fixed-point adder
Processor (e.g., ripple carry),
Floating-point adder
NAND Gate
Transistor
NOR Gate
54
So far in 252…
int, float
High-Level C Program if, else
Language +, -, >>
ret, call
Assembly fadd, add
Program jmp, jne
Instruction Set
Architecture (ISA)
00001111
Machine 01010101
Code 11110000
Fixed-point adder
Microarchitecture Processor (e.g., ripple carry),
Floating-point adder
NAND Gate
Circuit Transistor
NOR Gate
55
So far in 252…
High-Level C Program
Language
Assembly
Program
Instruction Set
Architecture (ISA)
Machine
Code
Microarchitecture Processor
Circuit Transistor
56
So far in 252…
High-Level
• ISA: Software programmers’
C Program view of a computer
Language
• Provide all info for someone wants
to write assembly/machine code
Assembly • “Contract” between assembly/
Program machine code and processor
Instruction Set
Architecture (ISA)
Machine
Code
Microarchitecture Processor
Circuit Transistor
56
So far in 252…
High-Level
• ISA: Software programmers’
C Program view of a computer
Language
• Provide all info for someone wants
to write assembly/machine code
Assembly • “Contract” between assembly/
Program machine code and processor
Instruction Set
Architecture (ISA) • Processors execute machine
Machine code (binary). Assembly
Code program is merely a text
representation of machine
code
Microarchitecture Processor
Circuit Transistor
56
So far in 252…
High-Level
• ISA: Software programmers’
C Program view of a computer
Language
• Provide all info for someone wants
to write assembly/machine code
Assembly • “Contract” between assembly/
Program machine code and processor
Instruction Set
Architecture (ISA) • Processors execute machine
Machine code (binary). Assembly
Code program is merely a text
representation of machine
code
Microarchitecture Processor
• Microarchitecture: Hardware
implementation of the ISA (with
Circuit Transistor the help of circuit
technologies) 56
This Module (4-5 Lectures)
High-Level
• Assembly Programming
C Program
Language • Explain how various C constructs
are implemented in assembly code
• Effectively translating from C to
Assembly
assembly program manually
Program
Instruction Set • Helps us understand how
Architecture (ISA) compilers work
Machine • Helps us understand how
Code assemblers work
Microarchitecture Processor
Circuit Transistor
57
This Module (4-5 Lectures)
High-Level
• Assembly Programming
C Program
Language • Explain how various C constructs
are implemented in assembly code
• Effectively translating from C to
Assembly
assembly program manually
Program
Instruction Set • Helps us understand how
Architecture (ISA) compilers work
Machine • Helps us understand how
Code assemblers work
• Microarchitecture is the
Microarchitecture Processor topic of the next module
Circuit Transistor
57