Chapter 02 The Processing Unit
Chapter 02 The Processing Unit
UNIT
11101001 0000...0000
• The processor keeps track of
the address of the memory 10101111 0000...0001
location containing the next 00001111 0000...0010
instruction by using a
dedicated register, referred to .
as the program counter (PC). .
.
• So if the PC is currently equal 01010101 1111...1110
to 0000. . . .0001, then the
next instruction to be fetched 10101010 1111...1111
and executed is found at that
memory address.
0000….0001
PC
11101001 0000...0000
• After fetching an
10101111 0000...0001
instruction, the contents
of the PC are updated 00001111 0000...0010
(incremented) to point to .
the next instruction in the .
sequence. .
01010101 1111...1110
next instruction to
10101010 1111...1111
be fetched and
executed
0000….0010
0000….0001
PC
• Example of a typical
assembly language
instruction:
R0
ADD R0, LOCA
LOCA
+
Add the operand at
memory location LOCA to
the operand in a register
in the processor, R0, and CPU Main Memory
place the result into
register R0.
Read signal
location to be written.
Main Memory
connections between
the processor and the
main memory
Main Memory
– The PC (Program
Counter) contains
the memory address
MAR MDR of the instruction to
Control
be executed.
PC
R0
IR R1
.
ALU During execution,
. the contents of the
CPU . PC are updated to
Rn-1 point to the next
n General Purpose instruction.
Registers
Main Memory
– The MAR (Memory
Address Register)
holds the address of
MAR MDR the location to or
Control
from which data are
PC
R0 to be transferred.
IR R1
ALU
.
. The MAR is used by
CPU . the CPU to send
Rn-1 addresses to the
n General Purpose MM.
Registers
Main Memory
– The MDR (Memory
Data Register)
contains the data to
MAR MDR
Control
be written or read
PC out of the addressed
R0 location.
IR R1
ALU
.
. The MDR is used by
CPU .
Rn-1
the CPU to send or
receive data to/from
n General Purpose
Registers
the MM.
Main Memory
– The IR (Instruction
Register) contains
MAR MDR the instruction that
Control
is being executed.
PC
R0
IR R1
.
ALU After an instruction
. is fetched from the
CPU . MM, it is sent to the
Rn-1 IR for decoding
n General Purpose
Registers
• Operating Steps:
Recall that whenever a user
wants to execute a particular
program, the operating
system will:
1 2
1. copy the program from
secondary to primary
memory
fetch
decode
2. and the CPU will then execute
fetch these instructions
(one by one) from main
memory for execution.
• Operating Steps:
Main Memory
1. The PC is set to point
to the first
instruction of the
MAR MDR
program Control
address of1st
PC
instruction R0
The operating IR R1
ALU
system is the one .
that loads the .
memory address of CPU .
Rn-1
the first instruction n General Purpose
of the program into Registers
the PC.
• Operating Steps:
Main Memory
2. The contents of the
Read signal
PC are transferred to
the MAR.
address of 1st MAR MDR
instruction Control
This address is then PC
R0
automatically IR R1
transmitted to the .
ALU
MM. .
CPU .
Rn-1
A Read signal is sent n General Purpose
to the MM (by the Registers
Control Unit).
The Processing Unit
INSIDE THE PROCESSOR
• Operating Steps:
Main Memory
3. The addressed word instruction
(which is the instruction to be executed
to be executed) is read
out of MM and loaded MAR MDR
into the MDR. Control
PC
R0
4. The contents of MDR IR R1
ALU
are transferred to the .
IR. .
CPU .
Rn-1
The instruction is ready
n General Purpose
to be decoded and then Registers
executed.
• Operating Steps:
Main Memory
• Operating Steps:
Main Memory
If operand or data needed by requested
the instruction resides in operand Read signal
MM:
MAR MDR
a. It will have to be fetched Control
by sending its address to PC
R0
the MAR and initiating a IR R1
read cycle. .
ALU
b. When the operand has .
been read from MM into
the MDR, it may be
CPU .
Rn-1
transferred from the address of n General Purpose
MDR to the ALU or to a operand Registers
internal register
• Operating Steps:
Main Memory
If result is to be stored result Write signal
in MM:
MAR MDR
Control
a. The address of the
PC
location where the R0
result is to be stored IR R1
ALU
is sent to the MAR. .
.
CPU .
b. The result is sent to address of
Rn-1
result
the MDR and a write location where
result will be
n General Purpose
cycle is initiated Registers
stored
• When a word of data is transferred between units, all its bits are
transferred in parallel.
Main or
Secondary I/O
CPU Primary
Memory Devices
Memory
Interconnecting Bus
2 1 3
1. Data Bus. This is for the
transmission of data.
MAR MDR
Control
2. Address Bus. This specifies PC
the location of data in MM. R0
IR R1
ALU
.
3. Control Bus. This indicates .
the direction of data CPU .
transfer and coordinates Rn-1
the timing of events during n General Purpose
the transfer. Registers
• Types of Instructions:
R1
LOC
R2
A
+
B
IR [ [PC] ]
PC [PC] + 1
IR [ [PC] ]
0 MOV R1, LOC1
PC 2
1 MOV R2, LOC2
4 SUB R2, R1
IR ADD R1, R2
IR [ [PC] ]
PC [PC] + 1
Instruction
Decoder Internal
Processor
Main Memory IR
Bus
PC
Address Lines
MAR
Memory
Bus Data Lines
MAR MDR MDR
Control
R0
PC
R0 R1
.
IR R1 .
ALU .
.
Rn-1
.
CPU .
Rn-1
1 Y
Select MUX
n General Purpose
Registers
Add A B
ALU Sub
Control : ALU
Lines XOR Carry-in
Instruction
Decoder Internal
Processor • This is the single-bus organization of the
IR
Bus
data paths inside the processing unit.
PC
Address Lines
MAR
• In this organization, the arithmetic and
Memory
Bus Data Lines
logic unit (ALU) and all the registers are
MDR
interconnected via a single common bus
R0 (internal processor bus).
R1
external
.
. • This bus is internal to the processor and
bus
.
should not be confused with the external
Rn-1
bus that connects the processor to the
1 Y memory and I/O devices.
Select MUX
• The data and address lines of the external
ALU
Add
Sub
A B memory bus are connected to the internal
Control
Lines XOR
: ALU
Carry-in
processor via the MDR and the MAR
Z
respectively
Instruction
Decoder Internal
Processor
Bus
• Two registers (Y and Z) have not
IR
been mentioned before.
PC
Address Lines
MAR
Memory
Bus Data Lines
MDR
These registers are transparent to
R0
the programmer; that is, the
programmer need not be
R1
.
concerned with them, because
.
. they are never referenced directly
Rn-1
by any instruction.
1 Y
Instruction
Decoder Internal
Processor
•
Bus
IR
The ALU performs all
Address Lines
PC
arithmetic (ADD, SUB, MULT,
Memory
Bus Data Lines
MAR
DIV, etc.) and logic (AND, OR,
MDR
NOT, XOR, etc.) operations.
R0
R1
.
ALU control .
.
lines Rn-1
• The ALU control lines
1 Y determine the exact
Select MUX operation the ALU will
Add
perform.
ALU A B
Sub ALU
Control :
Lines XOR Carry-in
Yin
result is stored at
register Z. Zout
Instruction
Decoder Internal
Processor
Bus
IR
PC
• The Instruction Decoder unit is
Address Lines
MAR
responsible for implementing
Memory
Bus Data Lines
MDR
the actions specified by the
R0 instruction loaded in the IR
R1
register.
.
.
.
Rn-1
• The decoder generates the
1 Y
control signals needed to
Select MUX select the registers involved
ALU
Add
Sub
A B
and direct the transfer of data.
Control : ALU
Lines XOR Carry-in
Instruction
Decoder Internal
Processor
Bus
IR
PC
Address Lines
MAR
Memory
Bus Data Lines
R0
R1
.
the interconnecting bus
.
. are collectively referred to
Rn-1
as the data path.
1 Y
Select MUX
Add A B
ALU Sub
Control : ALU
Lines XOR Carry-in
Instruction
Decoder Internal
Input
Processor Gate of Ri
Bus
IR
PC
Address Lines
MAR
Memory
Bus Data Lines Riin
MDR
R0
Internal
R1 Ri Processor
.
.
Bus
.
Rn-1
Riout
1 Y
Select MUX
Add A B
ALU
Control
Sub
: ALU Output
Lines XOR Carry-in Gate of Ri
Z
Internal
• The input and output gates Ri Processor
Bus
for register Ri are controlled
by the signals Riin and Riout, Riout
respectively.
R1
Enable the output gate of
register R1 by setting R1out to
1. This places the contents R1out 1
of R1 on the processor bus. Internal
Processor
R4 in Bus
1
Enable the input gate of
register R4 by setting R4in to R4
1. This loads data from the
processor bus into register
R4. R4 out
Yin
• The ALU is a
combinational circuit 1
Y
A B
ALU
It performs arithmetic
and logic operations Zin
on the two operands
applied to its A and B Z
inputs.
Zout
Yin
If Select = 0, then 1
Y
the signal 0
Select MUX
representing the A B
constant 1 passes ALU
Zout
Yin
If Select = 1, then 1
1
register Y pass A
ALU
B
Zout
(input B) is obtained
Zin
directly from the bus.
Z
R2
Select MUX
Zout
R2
bus to Y. Z
Zout
R2
1. R1 out =
R1out = 1,
1, Yin = 1 R3
Yin
or simply write: Y
1
Select MUX
1. R1out, Yin
Add A B
Sub .
.
ALU
.
step. Z
Zout
R2
Before proceeding to the next
step in the sequence (step 2), all R3
Add A B
Sub .
ALU
Take note that Y does not have
.
.
XOR
Zout
R2
In step 2, the contents of register R2
are gated onto the bus and, hence to R3
Add A B
Sub
At this point, both operands are in the .
.
.
ALU
ALU. XOR
Zin
2. R2out, SelectY Z
Zout
R2
1 Add A B
This sum is loaded into register Z by Sub .
ALU
activating Zin.
.
.
XOR
Zin
Zout
R2
1. R1out, Yin Y
1
Select MUX
2. R2out, SelectY, Add, Zin
Add A B
Sub .
.
ALU
Zout
.
XOR
R2
1. R1out, Yin 1
3. Zout, R3
R3inin Add
Sub
A B
.
.
ALU
.
XOR
Zout
• The time for one cycle (which is called the period) is just the
reciprocal of the frequency.
period = == 1/f
1/f = 1/2,000,000,000 = 0.5 ns/cycle
Instruction
Decoder
MDRoutE MDRin
Internal
Processor
Bus
IR
PC Memory-bus Internal
MDR Processor
Address Lines Data Lines
Memory
MAR Bus
Bus Data Lines
MDR
R0 MDRinE MDRout
R1
.
.
.
Rn-1 • Register MDR has four control signals:
1 Y
Select MUX
‒ MDRin and MDRout control the
connection to the internal bus, and
Add A B
ALU Sub
Control : ALU
Lines XOR Carry-in
‒ MDRinE and MDRoutE control the
Z
connection to the external bus.
R4out, R1in
1. R1out, Yin
2. R2out, SelectY, Add, Zin
3. Zout, R3in
Assume that the address of the memory location to be accessed is in R1 and the
memory data in that location is to be loaded into R2.
11 87 1. MAR [R1]
12 15
2. Start a Read operation on the memory bus
13 30
14 46 3. Wait for the MFC response from the
memory
15 92
number to be
loaded to R2 4. Load MDR from the memory bus
5. R2 [MDR]
1. MAR [R1]
• The actions may be carried
out as separate steps, but
2. Start a Read operation on some can be combined into
the memory bus
a single step.
3. Wait for the MFC
response from the • Each action can be
memory completed in one clock cycle,
except action 3 which
4. Load MDR from the requires one or more clock
memory bus cycles, depending on the
speed of the addressed
5. R2 [MDR] device.
3. MDRout
out, R2in MDRoutE MDRin
• In order to store/write
data into main memory: • So to store a word into
main memory:
1. The CPU first sends the
address of the memory 1. Load the address
location to be written. into the MAR.
• Example:
R1
Assume that the data word to
be stored in memory is in R2 R2
1. R1
R1out
out,, MAR
MARinin, MARoutE
outE Data Bus MDR
MARoutE MARin
However, for future
discussions, assume all external Address Bus MAR
[ [R2] ]
• Assume the following
instruction:
R2 12
R1 [R1] + [[R2]]
[R2] ==1212 11 87
The contents of register
R1 are added to the 12 15
contents of a memory [[R2]] = [12] = 12
location (the address of 13 30
which is in register R2) 14 46
and store the results in number to be
15 92
register R1. added to the
contents of R1
1. PC
PCout
out,, MAR
MARinin,, Read
Read Rn-1
1 Y
Select MUX
Since the Read operation will
take several clock cycles, the ALU
Control
Add
Sub
:
A
ALU
B
step. Z
R0
R1
1
Add A B
ALU Sub
1. PCout, MARin, Read,, Select1, Add, Zin Control
Lines XOR
: ALU
Carry-in
Z
PC + 1
R0
Add A B
ALU Sub
Control : ALU
2. ZZout
out, ,PC
PCinin, ,WMFC
WMFC Lines XOR Carry-in
Z
updated PC
R1
MDR now contains the
.
instruction that was
.
The instruction decoding circuit fetched .
Select MUX
sequence.
3. MDRout, IRin R0
R1
.
.
.
Steps 1 through 3 constitute the Rn-1
Add A B
ALU Sub
Control : ALU
memory. R1
R2
Rn-1
The contents of register R2 are
transferred to the MAR and a 1 Y
Add A B
ALU Sub
Control : ALU
Lines XOR Carry-in
4. R2out
out, MARin
in,, Read
Read Z
R0
can do. R1
R2
operation. Add
ALU A B
Sub ALU
Control :
Lines XOR Carry-in
5. R1out, Yin, WMFC Z
MDR
R0
The contents of the MDR are gated
to the bus, and thus also to the B MDR now contains the
R1
Select MUX
Z
6. MDRout, SelectY,
SelectY, Add, Zinin
PC
R0
R1
The End signal causes a new R2
instruction fetch cycle to begin Rn-1
by returning to step 1.
1 Y
Select MUX
R1inin,, End
7. Zout, R1 ALU
Control
Add
Sub
A
ALU
B
:
Lines XOR Carry-in
MDR
R0
1. PCout, MARin, Read, Select1,
Add, Zin R1
R2
2. Zout, PCin, WMFC Rn-1
3. MDRout, IRin
1 Y
4. R2out, MARin, Read
Select MUX
5. R1out, Yin, WMFC
6. MDRout, SelectY, Add, Zin ALU
Control
Add
Sub
:
A
ALU
B
LOC
op-code address field
field
MDR
3. MDRout, IRin R1
.
.
.
Rn-1
As discussed earlier, steps 1
through 3 constitute the 1 Y
PC
LOC is the address of the Address Lines
MAR
memory. .
.
.
Rn-1
R0
R1
.
4. Address-Field-of-IRout
out,
.
.
Add, Zin R1
4. Address-Field-of-IRout, MARin, 1 Y
R0
3. MDRout, IRin R1
R2
6. R3out
out, MARin
Select MUX
Lines XOR
8. WMFC, End Z
Carry-in
Unconditional Branching IR
Internal
Processor
Bus
PC
Address Lines
1. PCout, MARin, Read, Select1, Memory
Bus Data Lines
MAR
R0
3. MDRout, IRin .
.
.
Rn-1
4. PCout,, YYinin 1 Y
Z
Carry-in
2. Assume that each instruction consists of two words and that each
word occupies one address location.
Write the sequence of control signals that will add the contents of
LOC to register R1 and store the results in register R1.
• To execute instructions, the CPU must be able to generate the right control
signals at the right time.
. . .
• Each state or count
of this counter indicates what the
Control Signals
corresponds to one current instruction is
step in the
execution of an • The contents of the IR
instruction. represent the current
instruction being executed
The Processing Unit
HARDWIRED CONTROL UNIT
. . .
R1 [R1] + [[R2]
Control Signals
indicates what the
• If control step counter current instruction is
CLK
Clock Control Step Reset
CLK Control Step Counter
Clock
Counter . . .
. . .
Step Decoder
Status Flags T1 T2 . . . Tn
. INS1
Decoder/
IR . INS2
Encoder Status Flags
.
. .
Condition Codes Instruction
IR . . Encoder
Decoder
. .
. . .
INSm Condition Codes
CLK
Clock Control Step Reset
Counter
. . .
Step Decoder
T1 T2 . . . Tn
INS1
INS2 Status Flags
. .
Instruction
IR . . Encoder
Decoder
. .
INSm Condition Codes
PCout . . . END
• The step decoder provides a separate signal line for each step, or
time slot, in the control sequence.
T2 = 1 while the 000000000001
rest will be 0 CLK (step 2)
Clock Control Step Reset
Counter
. . .
Step Decoder
T1 T2 . . . Tn
INS1
INS2 Status Flags
. .
Instruction
IR . . Encoder
Decoder
. .
INSm Condition Codes
PCout . . . END
T1 T2 . . . Tn
INS1
INS2 Status Flags
. .
Instruction
IR . . Encoder
Decoder
. .
INSm Condition Codes
PCout . . . END
Step Decoder
T1 T2 . . . Tn
INS1
INS2 Status Flags
. .
Instruction
IR . . Encoder
Decoder
. .
INSm Condition Codes
PCout . . . END
Zin = (T1 and INS1) or (T6 and INS1) or (T1 and INS2) or (T6 and INS2) or (T1 and INS3) or
(T4 and INS3)
T1
INS1
T6
INS1
T1
INS2
Zin
T6
INS2
T1
INS3
T4
INS3
• Simplification:
Therefore, the circuit can be
Since Zin is active at simplified as:
T1 for all
T1
instructions, it can
be concluded that
Zin is active at T1 no T6
matter what INS1
instruction is being Zin
executed. T6
INS2
In other words, if T1 T4
= 1, then Zin = 1. INS3
1. PCout
2. WMFC
• Advantages:
‒ Speed.
• Disadvantages: