Lecture 05 - CPU Architecture
Lecture 05 - CPU Architecture
CPU Architecture
Arithmetic Logic Unit (ALU)
2
Arithmetic Logic Unit (ALU) (contd..)
3
Arithmetic Logic Unit (ALU) (contd..)
Output F
4
Arithmetic and Logic Unit (ALU) (contd..)
ALU connections to the bus
Carry-in
Processor bus
5
Arithmetic and Logic Unit (ALU) (contd..)
ALU connections to the bus
Control ALU
lines
Carry-in
Processor bus
6
Performing an arithmetic operation
Add the contents of registers R1 and R2 and place the result in R3.
That is: R3 = R1 + R2
1. Place the contents of register R1 into the Y register in the first clock cycle.
2. Place the contents of register R2 onto the bus in the second clock cycle. Both
inputs to the ALU are now valid. Select register Y, and assert the ALU command
F=A+B.
3. In the third clock cycle, Z register has latched the output of the ALU. Thus the
contents of the Z register can be copied into register R3.
7
Performing an arithmetic operation (contd..)
Instruction
PC Control
decoder and
Signals
control logic
Address
lines
MAR
Memory
bus
Clock cycle 1:
Data
MDR IR R1out, Yin
lines
Y
Constant 4 R1
R
Select MUX
R
Add
A B
ALU Sub R( n - 1 )
control ALU
lines
Carry-in
XOR TEMP
8
Performing an arithmetic operation (contd..)
Instruction
PC Control
decoder and
Signals
control logic
Address
lines
MAR
Memory
bus
Clock cycle 2:
Data
MDR IR R2out, SelectY,
lines Add, Zin
Y
Constant 4 R1
R
SelectY MUX
R
Add=1
A B
ALU Sub R( n - 1 )
control ALU
lines
Carry-in
XOR TEMP
9
Performing an arithmetic operation (contd..)
Instruction
PC Control
decoder and
Signals
control logic
Address
lines
MAR
Memory
bus
Clock cycle 3:
Data
MDR IR Zout, R3in
lines
Y
Clock cycle 4:
Constant 4 R1
R3 has the sum.
R
SelectY MUX
R
Add
A B
ALU Sub R( n - 1 )
control ALU
lines
Carry-in
XOR TEMP
10
Performing an arithmetic operation (contd..)
Clock Cycle 1:
R1out, Yin (Y=R1)
Clock Cycle 2:
Clock Cycle 3:
11
Performing an arithmetic operation (contd..)
12
Performing an arithmetic operation (contd..)
Events as seen by the system registers, bus, ALU over time.
cycle: controls active what the bus sees what Y has output of ALU
start of
1 R1out , Yin contents of R1 --unknown --unknown
end of
1 R1out , Yin contents of R1 R1 --unknown
=
start of
2 R2out , F=A+B contents of R2 R1 F=A+B=R1+R2
but this is not
valid yet
end of
2 R2out , F=A+B,Zin contents of R2 R1 F=A+B=R1+R2
(now valid)
=
start of
3 Zout ,R3in contents of Z R1 --unknown
end of
3 Zout , R3in contents of Z R1 --unknown (but R3
latches bus
contents)
13
ALU operations
❑ RC = RA op RB
❑ Clock cycle 1:
◆ Move RA to Y register.
◆ RAout, Yin
❑ Clock cycle 2:
◆ Put RB on the bus, perform F = RA op RB, and transfer the
result to Z.
◆ RBout, (RA op RB)=1, SelectY, Zin
❑ Clock cycle 3:
◆ Put Z on the bus, and load Z into RC.
◆ Zout, RCin
14
Fetching a word from memory
15
Fetching a word from memory (contd..)
16
Fetching a word from memory (contd..)
Step 1:
- Place R1 onto the internal processor bus.
- Load the contents of the bus into MAR.
- Activate the Read control signal.
- R1out, MARin, Read.
Step 2:
- Wait for MFC from the memory.
- Activate the control signal to load data from external bus to MDR.
- MDRinE, WMFC
Step 3:
- Place the contents of MDR onto the internal processor bus.
- Load the contents of the bus into Register R2.
- MDRoutI, R2in
17
Storing a word into memory
Step 1:
- Place R1 onto the internal processor bus.
- Load the contents of the bus into MAR.
- R1out, MARin, Write.
Step 2:
- Place R2 onto the internal processor bus.
- Load the contents of the internal processor bus into MDR.
- Activate Write operation.
. - R2out, MDRin, Write
Step 3:
- Place the contents of MDR into the external memory bus.
- Wait for the memory write operation to be complete.
- MDRoutE, WMFC
18
Execution of a complete instruction
Add the contents of a memory location pointed to by Register R3
to register R1.
ADD (R3) R1
19
Execution of a complete instruction
Task 1: Fetch the instruction
Recall that:
- PC holds the address of the memory location which has the next
instruction to be executed.
- IR holds the instruction currently being executed.
Step 1
- Load the contents of PC to MAR.
- Activate the Read control signal.
- Increment the contents of the PC by 4.
- PCout, MARin, Read, Select4, Add, Z in.
Step 2
- Update the contents of the PC.
- Copy the updated PC to Register Y (useful for Branch instructions).
- Wait for MFC from memory.
- Zout, PCin, Yin, WMFC
Step 3
- Place the contents of MDR onto the bus.
- Load the IR with the contents of the bus.
- MDRout, IRin
20
Execution of a complete instruction (contd..)
Task 2. Fetch the operand (contents of memory pointed to by R3.)
Task 3. Perform the addition.
Task 4. Load the result into R1.
21
Execution of a complete instruction (contd..)
Step Action
22
Branch instructions
23
Thank You for Listening !
24