Lecture 6 Instruction Set Architectures
Download
Report
Transcript Lecture 6 Instruction Set Architectures
Topic 3
Number Representations
and Computer Arithmetics
Introduction to Computer
Systems Engineering
(CPEG 323)
2015/7/18
cpeg323-08F\Topic3-05F
1
Outline
Introduction
Number representation and 2’s
complement
ALU design
Integer multiplication/division
Real Numbers
2015/7/18
cpeg323-08F\Topic3-05F
2
Recap
Review
Steps in executing an instruction?
Fields of an instruction?
Performance?
Base of the operands?
What's up ahead:
Number representation
Arithmetic algorithms
Logic implementation
Instructions
2015/7/18
cpeg323-08F\Topic3-05F
Decoded opcode
a
32
ALU
result
32
b
32
3
Reading
Up to now, you should have read
(or are reading)
Patterson and Hennessy, chapters 12 and appendix A
New material
2015/7/18
Patterson and Hennessy, chapter 3
cpeg323-08F\Topic3-05F
4
Numbers Representation
It may get complicated:
How to represent negative numbers?
What is the range of numbers?
What if a number is out of the range?
How about rational and irrational numbers?
2015/7/18
How does hardware add/sub/div/mul these
numbers?
cpeg323-08F\Topic3-05F
5
Bits and Numbers
Bits are just bits: NO inherent meaning
2015/7/18
conventions define relationship between
bits and numbers
How does the hardware know which
convention is to use?
Add $s1, $s2, $s3
Addu $s1, $s2, $s3
What is the sign of $s1, $s2, and $s3?
cpeg323-08F\Topic3-05F
6
Number Representations
Unsigned integers
Signed integers
BCD (Binary Coded Decimal)
Fixed point
Floating point
Other types of data:
2015/7/18
Characters (ASCII, Unicode)
Pixels (graphics)
Groups of bits
cpeg323-08F\Topic3-05F
7
Unsigned Integers
Why unsigned integers?
Memory access, PC, SP, RA
In C, unsigned int
How to represent?
Number your fingers!
Radix number system
Decimal: 10 different symbols: 0 1 2 3 4 5 6 7 8 9
number=
n 1
i
(
d
*
1
0
)
i
i 0
2015/7/18
cpeg323-08F\Topic3-05F
8
Unsigned Integers(Radix number
system)
In general, k-radix number system
number=
n1
(d
i 0
i
* ki )
How many different di?
What is the biggest number?
What is the smallest one?
Special cases:
2-radix (binary)
8 (octal)
16 (hexademical)
How many different symbols do thy have?
2015/7/18
cpeg323-08F\Topic3-05F
9
Unsigned Integers(Radix number
system, Cont.)
How to convert binary to octal and
hexadecimal?
Example:
010100=(0 *22+1 *21+0*20)*23+(1*22+0*21+0*20)
=2*81+ 4 *80= 248
9
4
8
B
6
Hexadecimal: 1
Binary: 000110010100100010110110
Octal: 0 6 2 4 4 2 6 6
2015/7/18
cpeg323-08F\Topic3-05F
10
Unsigned Integers(BCD: binary coded decimal)
Representation: 12710
How many bits necessary for
BCD? For binary?
Storage space used ?
Addition
How to determine a carry:
“If ai+ bi >10” vs. “If ai+ bi >2”
Which one is more efficient for
computer, decimal or binary?
2015/7/18
cpeg323-08F\Topic3-05F
BCD
0000
0001
0010
0011
0100
0101
0110
0111
1000
1001
1010 1111
Number
0
1
2
3
4
5
6
7
8
9
No use
11
Signed Integers
How to distinguish a negative number
from a positive number ?
How to do so efficiently ?
2015/7/18
cpeg323-08F\Topic3-05F
12
Signed Integers (Sign and magnitude)
-12: -(sign) 12(absolute value)
A separate sign bit
A magnitude
For hardware:
2015/7/18
Where to put the sign bit? Right or Left?
How to know the sign of addition? (e.g.
one extra step ?)
What is the sign of 0? (positive and
negative 0 ?)
cpeg323-08F\Topic3-05F
13