Transcript Lecture 2

Lecture 2
Processor Organization
Control needs to have the
 Ability to fetch instructions from memory
 Logic and means to control instruction sequencing
 Logic and means to issue signals that control the way information flows
between datapath components
 Logic and means to control what operations the datapath’s functional
units perform
Datapath needs to have the
 Components - functional units (e.g., adder) and storage locations (e.g.,
register file) - needed to execute instructions
 Components interconnected so that the instructions can be accomplished
 Ability to load data from and store data to memory
What Happens Next?
Memory
Processor
Control
Datapath
000000
000000
100011
100011
101011
101011
000000
00000
00100
00010
00010
00010
00010
11111
00101
00010
01111
10000
10000
01111
00000
0001000010000000
0001000000100000
0000000000000000
0000000000000100
0000000000000000
0000000000000100
0000000000001000
Fetch
Exec
Decode
Devices
Input
Output
Output Data Stored in Memory
At program completion the data to be output resides in memory
Processor
Memory
Control
Datapath
Devices
Input
00000100010100000000000000000000
00000000010011110000000000000100
00000011111000000000000000001000
Output
Output Device Outputs Data
Processor
Control
Datapath
Devices
Memory
Input
Output
00000100010100000000000000000000
00000000010011110000000000000100
00000011111000000000000000001000
The Instruction Set Architecture
software
instruction set architecture
hardware
The interface description separating the software and hardware.
MIPS R3000 Instruction Set Architecture ISA
Instruction Categories




Registers
Load/Store
Computational
Jump and Branch
Floating Point
R0 - R31
 coprocessor
PC
HI
 Memory Management
 Special

LO
3 BASIC Instruction Formats: all 32 bits wide
OP
rs
rt
OP
rs
rt
OP
rd
sa
immediate
jump target
Q: How many already familiar with MIPS ISA?
funct
Refresh on Binary Numbers
Number Systems
9
Number Systems
• In grade school: decimal system
• To interpret a sequence of digits: assign each
digit to a column, multiply each digit by the
column, add them all together
Hundreds
Tens
Ones
2
3
7
2 x 100 + 3 x 10 +7 x 1’s = 237
10
Number Systems: Decimal System
• Decimal System = Base 10
Hundreds
102
Tens
101
Ones
100
0-9
0-9
0-9
• Base 10 uses digits 0 – 9
• Largest number represented with 3 columns?
• How do we represent a larger number?
11
Interpreting Number Systems
• For any Base B, use digits 0 – (B-1)
• Each column represents B raised to an
exponent, increasing to the left
Bn
B…
B2
B1
0 - (B-1) 0 - (B-1) 0 - (B-1) 0 - (B-1)
B0
0 - (B-1)
12
Other Number Systems
• Octal system (base 8) uses digits 0 – 7
82
81
80
2
3
7
2 x 82 + 3 x 81 + 7 x 80 = 159base10
The interpretation of any digit sequence
is dependent on the number system
13
Other Number Systems
• Hexadecimal system (base 16) uses digits 0 – 9, A-F
162
161
160
2
B
D
2 x 162 + 11 x 161 + 13 x 160 = 701base10
The interpretation of any symbolic sequence
is dependent on the number system
14
Binary Number System
• Binary system (base 2) uses digits 0 – 1
• Machine Language uses base 2
25
1
24
0
23
1
22
21
20
2
3
7
Invalid
1
0
0
Valid
15
Conversion from Binary to Decimal
Convert 100111base 2 to ???base 10
1. Assign each digit to a column (columns represent
base raised to exponents increasing to left)
25
24
23
22
21
20
1
0
0
1
1
1
16
Conversion from Binary to Decimal
2. Multiply each digit by the column and then add
them all together
25
24
23
22
21
20
1
0
0
1
1
1
1 x 25 + 0 x 24 + 0 x 23 + 1 x 22 + 1 x 21 + 1 x 20 =
32
+
0
+
0
+
4
39base10
+
2
+
1
=
17
Conversion from Decimal to Binary
Convert 237base10 to ??????base 2
1. Find the largest power of 2 in the decimal number
(trial and error)
2. Record this largest power in its column
28 27 26
256 128 64
1
25
32
24
16
23
8
22
4
21
2
3. Subtract this largest power: 237 – 128 = 109
20
1
18
Conversion from Decimal to Binary
4. REPEAT 1-3 with remainder, until 0
5. Record 0 for all powers not subtracted
109
- 64 = 26
45
45
- 32 = 25
13
13
- 8 = 23
5
5
- 4 = 22
1
1
- 1 = 20
0
28 27 26
256 128 64
25
32
24
16
23
8
22
4
21
2
20
1
1
1
0
1
1
0
1
1
237base10 = 11101101base 2
19
An algorithm for converting to decimal to other
bases
• Let N be the number (assume it is an integer now)
to be converted and b the base. Divide N by b and
record the remainder r0. Next divide the partial
quotient from the previous step by b and record
the remainder r1. Continue this process until the
partial quotient is 0 and record the final remainder
rn. The number N in base b is given by rn . . . r1 r0.
•
•
•
•
Example 315 decimal is converted to base 8 by
315/8 = 39 + 3
39/8 = 4 + 7
4/8 = 0 + 4
• So 31510 = 4738.
20
Suppose N is not an integer
•
•
•
Convert the integer part as on the previous slide. Now convert the
fractional part as follows. Multiply by the base and record the integer
part as r-1, then multiply the new fractional part by the base and record
the integer part as r-2. Continue this process until the result of
multiplying gives zero, or until a product is repeated, or until a certain
number of places is obtained.
If zero is reached, or the max number of digits is reached, then the
result is 0. r-1 r-2 . . . r-m.
On the other hand if a product is repeated then it is clear that the
pattern just seen will repeat so one gets an infinite repeating pattern in
the fractional representation.
•
•
•
•
•
•
•
•
•
Example: Represent .315 base 10 as a base 8 number with 8 digits.
.315 (8) = 2.52
.52 (8) = 4.16
.16 (8) = 1.28
.28 (8) = 2.24
.24 (8) = 1.92
.92 (8) = 7.36
.36 (8) = 2.88
.88 (8) = 7.04
•
Now .31510 is approximately .241217278.
21
Converting from one base to another
• The general problem of converting from base r to
base s can be done by converting the base r
number first to decimal, and then converting the
base 10 number to base s as shown previously.
• For example 3759 = 3×92 + 7×9 + 5 = 243 + 63 + 5 =
311. If we want to convert to base 3 we go through
the process below.
• 311/3 = 103 remainder 2
• 103/3 = 34 remainder 1
• 34/3 = 11 remainder 1
• 11/3 = 3 remainder 2
• 3/3 = 1 remainder 0
• 1/3 = 0 remainder 1. Therefore 3759 = 1021123
22
Class Example 1: Convert Binary to Decimal
Convert 1011base 2 to ??base 10
23
Class Example 2: Convert Decimal to Binary
Convert 22base10 to ?????base 2
24
Class Example: Convert Decimal to Binary
Convert 22base10 to ?????base 2
22
- 16 = 24
6
24
16
1
6
- 4 = 22
2
23
8
0
22
4
1
22base10 = 10110base 2
2
- 2 = 21
0
21
2
1
20
1
0
25
Example continued
• Now do it with the algorithm if you didn’t
previously
26
Counting in the Binary Number System
23
1
1
22
21
1
1
1
1
0
0
1
1
0
0
1
1
0
0
20
0
1
0
1
0
1
0
1
0
1
Base 10
0
1
2
3
4
5
6
7
8
9
27
Computer arithmetic
• When performing computations in a
computer precision is limited to a finite
number of bits. (In MIPS this is 32). We will
look at a couple of problems with limited
size words. In the first one below suppose
we have 8 bits and are looking at different
ways of doing the arithmetic.
• -71 – 109 = ? Change 71 and 109 to binary,
71 = 1000111, 109 = 1101101.
28
Sign and magnitude
•
-71 = 11000111 and -109 = 11101101. Since both
are negative we add the magnitudes 1000111 +
1101101 and append the 1 in the sign place.
• 1000111 + 1101101 = 10110100 which causes
overflow since the magnitude will not fit into 7
places allowed for the magnitude.
• -71 + 109 on the other hand is 1101101 – 1000111 =
100110 and the result is positive since the
magnitude of the positive number is larger.
Therefore the result in sign and magnitude is
00100110 where the first 0 is the sign designator.
29
1’s complement
• The 1’s complement of 71 = 01000111 is 10111000
and the 1’s complement of 109 = 01101101 is
10010010 (note we have to add the leading zero
since we are using 8 bits.). Now
• 10111000 + 10010010 = 1 01001010 = 01001010 + 1
(end around carry) = 01001011.
• But this is a positive number representation which
indicates overflow has occurred.
• Note: In 1’s complement any overflow out of the
allotted bits, in this case 8, is added back to the
sum and the overflow bit is deleted.
• On the other hand if we perform -71 + 109 we get
10111000 + 01101101 = 1 00100101
• = 00100101 + 1 = 00100110 = 38.
30
2’s complement
• The 2’s complement of 71 = 01000111 is 10111001
and the 2’s complement of 109 = 01101101 is
10010011 (note we have to add the leading zero
since we are using 8 bits.). Now
• 10111001 + 10010011 = 1 01001100 = 01001010.
• But this is a positive number representation which
indicates overflow has occurred.
• Note: In 2’s complement any overflow out of the
allotted bits, in this case 8, does not by itself
indicate overflow.
• On the other hand if we perform -71 + 109 we get
10111001 + 01101101 = 1 00100110
• = 00100110 = 38.
31
A hex example
• 3C5D28E2 – ED5E3026 (change to 16s complement
and add)
• = 3C5D28E2 + (12A1CFD9 + 1) = 4EFEF8BC
• Another example: 7F5D28E2 – ED5E3026 =
7F5D28E2 + 12A1CFDA = 91FEF8BC. However this
is an overflow since the sum of two positive
numbers gives a negative as indicated by the 9 in
the most significant place.
• The important point to note here is that these
addition or subtraction results have to fit in the 8
hex digits (32 bits). To form the 16’s complement
each hex digit x is replaced by hex digit y such that
x + y = F and then 1 is added to the result.
32