lecture 2 processor organization control needs to have the ability to fetch instructions from...
TRANSCRIPT
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?
Processor
Control
Datapath
MemoryDevices
Input
Output
000000 00000 00101 0001000010000000000000 00100 00010 0001000000100000100011 00010 01111 0000000000000000100011 00010 10000 0000000000000100101011 00010 10000 0000000000000000101011 00010 01111 0000000000000100000000 11111 00000 0000000000001000
Fetch
DecodeExec
Output Data Stored in Memory
Processor
Control
Datapath
MemoryDevices
Input
Output000001000101000000000000000000000000000001001111000000000000010000000011111000000000000000001000
At program completion the data to be output resides in memory
Output Device Outputs Data
Processor
Control
Datapath
Memory
Devices
Input
Output
000001000101000000000000000000000000000001001111000000000000010000000011111000000000000000001000
The Instruction Set Architecture
instruction set architecture
software
hardware
The interface description separating the software and hardware.
MIPS R3000 Instruction Set Architecture ISA
Instruction Categories Load/Store Computational Jump and Branch Floating Point
coprocessor
Memory Management Special
R0 - R31
PCHI
LO
OP
OP
OP
rs rt rd sa funct
rs rt immediate
jump target
3 BASIC Instruction Formats: all 32 bits wide
Registers
Q: How many already familiar with MIPS ISA?
9
Number Systems
Refresh on Binary Numbers
10
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
11
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?
12
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 B0
0 - (B-1) 0 - (B-1) 0 - (B-1) 0 - (B-1) 0 - (B-1)
13
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
14
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
15
Binary Number System
• Binary system (base 2) uses digits 0 – 1
• Machine Language uses base 2
25 24 23 22 21 20
2 3 7
1 0 1 1 0 0
Invalid
Valid
16
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
17
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 + 2 + 1 =
39base10
18
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
3. Subtract this largest power: 237 – 128 = 109
28
256
27 128
26
64
25
32
24
16
23
8
22
4
21
2
20
1
1
19
Conversion from Decimal to Binary
4. REPEAT 1-3 with remainder, until 05. Record 0 for all powers not subtracted
109 45 13 5 1- 64 = 26 - 32 = 25 - 8 = 23 - 4 = 22 - 1 = 20
45 13 5 1 0
28
256
27
128
26
64
25
32
24
16
23
8
22
4
21
2
20
1
1 1 1 0 1 1 0 1
237base10 = 11101101base 2
20
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.
21
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.
22
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
23
Class Example 1: Convert Binary to Decimal
Convert 1011base 2 to ??base 10
24
Class Example 2: Convert Decimal to Binary
Convert 22base10 to ?????base 2
25
Class Example: Convert Decimal to Binary
Convert 22base10 to ?????base 2
22 6 2 - 16 = 24 - 4 = 22 - 2 = 21
6 2 0
24
16
23
8
22
4
21
2
20
1
1 0 1 1 0
22base10 = 10110base 2
26
Example continued
• Now do it with the algorithm if you didn’t previously
27
Counting in the Binary Number System
23 22 21 20 Base 10
0 0
1 1
1 0 2
1 1 3
1 0 0 4
1 0 1 5
1 1 0 6
1 1 1 7
1 0 0 0 8
1 0 0 1 9
1 0 1 0 10
28
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.
29
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.
30
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.
31
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.
32
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.