Basic Processing Unit
Basic Processing Unit
Lecture 09:
Basic Processing Unit
Ming-Chang YANG
mcyang@[Link]
Registers
Input
Arithmetic and
Memory
Logic Unit
Output
Control
Processor–Memory Interface
Allow communication between processor and memory through two special registers:
memory address register (MAR) and memory data register (MDR)
CSCI2510 Lec09: Basic Processing Unit 2024-25 T1 5
Register File
• General-purpose registers are usually implemented
as a register file, a small and fast memory block.
• It allows data to be read from written into any register
with two data outputs (A & B) and one data input (C).
C C C
A B A B
– It supports arithmetic
Register
operations (e.g., ADD and File
SUB) and logic operations
(e.g., AND, OR, and XOR). A B
Register
B SUM
Combinational 0 0 0 0 0
…
…
Logic 0 0 1 1 0
Cin
Circuit Cout ...
1 1 1 1 1
Clock
CSCI2510 Lec09: Basic Processing Unit 2024-25 T1 8
Structure for Data Processing (2/2)
• Alternatively, data processing can be broken down
into simpler steps:
– Each step is performed by a subcircuit (that can be
completed in less time;
– These subcircuits are cascaded into a multistage structure.
• If 𝑛 stages are used, the operation will be completed in 𝑛 cycles.
– It is particularly suitable for pipelined operation (see Lec10).
Register
Register
Register
Register
Sub- Sub- Sub-
…
…
…
circuit circuit circuit
Mem
• This multi-stage structure MuxY MDR MAR
#immediate
1) IR [[PC]] A
(R0~Rn-1)
B
addr.
Control
• Load the memory contents Circuitry
...
pointed to by PC into IR. RA RB
control signals
Mem
R/W
Adder RY MDR MAR
Address MFC
Generator
CSCI2510 Lec09: Basic Processing Unit 2024-25 T1 15
Execution Phase: Stage
• The execution phase is
RY MDR
Addr.
C IR PC
Gen.
generally of four stages: Register
File reg. IR
#immediate
Decode the instruction & A
(R0~Rn-1)
B
addr.
Control
read source registers. Circuitry
...
control signals
• [IR] must be firstly decoded RA RB
by Control Circuity. RB
Mem
into RA and RB (no matter RY MDR MAR
whether
CSCI2510 Lec09: Basic theyUnit
Processing are2024-25
needed).
T1 16
Instruction Encoding
• Consider a RISC-style processor that
– Has 32 general-purpose registers;
– Represents every instruction by a 32-bit word.
Address-operand Format 31 6 5 0
• E.g., Branch instruction OP
Address
• E.g., Call instruction code
The instruction
CSCI2510 encoding
Lec09: Basic Processing varies
Unit 2024-25 T1 (a lot) from machine to machine!
17
Class Exercise 9.1
• Consider the register-operand format for the
instruction encoding.
#immediate
Perform ALU operation. A
(R0~Rn-1)
B
addr.
Control
• The input InA of ALU is Circuitry
...
supplied by RA. RA RB
control signals
Mem
forwarded to RM (though it’s RY MDR MAR
only
CSCI2510 Lec09: needed
Basic Processing Store).
byUnit 2024-25 T1 20
Execution Phase: Stage
• The execution phase is
RY MDR
Addr.
C IR PC
Gen.
generally of four stages: Register
File reg. IR
#immediate
Read/write memory data. A
(R0~Rn-1)
B
addr.
Control
• The memory read/write takes Circuitry
...
place via Processor-Mem RA RB
control signals
Interface. RB
– The effective address is MuxB
derived by ALU and kept in
RA
RZ in Stage .
InA InB
– The “loaded” data are put ALU
into RY (with the multiplexer RB
MuxY properly set). RZ RM
– The “to-be-stored” data are
available in RM. RZ MDR RZ PC
• Note: For non-Load and non- Y_sel MuxY MA_sel MuxMA
Store instructions, the data
Mem
R/W
in RZ are forwarded to RY. RY MFC
MDR MAR
CSCI2510 Lec09: Basic Processing Unit 2024-25 T1 21
Execution Phase: Stage
• The execution phase is
RY MDR
Addr.
RF_write C IR PC
Gen.
generally of four stages: Register
File reg. IR
#immediate
Write the result into the A
(R0~Rn-1)
B
addr.
Control
destination register. Circuitry
...
control signals
• The data kept in RY, which RA RB
can be: RB
Mem
RY MDR MAR
– RF_write must be set.
CSCI2510 Lec09: Basic Processing Unit 2024-25 T1 22
Observations
• The datapath is designed
RY MDR
Addr.
C IR PC
Gen.
to be independent, multi- Register
File reg. IR
#immediate
function, and general. A
(R0~Rn-1)
B
addr.
Control
Circuitry
• But not all actions/stages ...
control signals
RA RB
have to be carried out by RB
every instructions. MuxB
Mem
RY MDR MAR
CSCI2510 Lec09: Basic Processing Unit 2024-25 T1 23
Recall: Register Transfer Notation
• Register Transfer Notation (RTN) describes the data
transfer from one location in computer to another.
– Possible locations: memory locations, processor registers.
• Locations can be identified symbolically with names (e.g., LOC).
Ex.
R2 ← [LOC]
– Transferring the contents of memory LOC into register R2.
#immediate
(R0~Rn-1) addr.
Decode instruction, A B Control
Circuitry
RA [R4], RB [R5] ...
control signals
• The source register addresses are RA RB
available in IR31-27 and IR26-22. RB
• As a result, [R4] and [R5] can be B_sel MuxB
read into RA and RB in Stage . RA
Mem
• The dest. reg. address is in IR21-17. RY MDR MAR
• RF_write
CSCI2510 Lec09: BasicisProcessing
set to allow R3.
writingT1
Unit 2024-25 25
Class Exercise 9.2
• Assume R3, R4, and R5 originally hold the values 0,
40, and 60, respectively.
• Considering Add R3, R4, R5, show the registers’
contents “after” the completion of Stages to :
– Note: Fill in “?” for those blanks that cannot be determined.
RA RB RZ RY R3
#immediate
(R0~Rn-1) addr.
Decode instruction, A B Control
Circuitry
RA [R7] ...
control signals
• The src. reg. address is in IR31-27. RA RB
RB
RZ [RA] + X B_sel MuxB
• The immediate value X is from IR. RA
• MuxB is set to select input from IR. InA InB
• ALU is set to perform an Add. ALU
Wait_MFC, RY [MDR] RZ RM
Mem
R
• The dest. reg. address is in IR26-22. RY MFC
MDR MAR
• RF_write
CSCI2510 Lec09: BasicisProcessing
set to allow R5.
writingT1
Unit 2024-25 28
Class Exercise 9.3
• Assume R5 and R7 originally hold the values 0 and 4,
respectively, and the contents of main memory are
shown as follows:
0x0 0x1 0x2 0x3 0x4 0x5 0x6 0x7 0x8 0x9 …
9 8 7 6 5 4 3 2 1 0 …
• Considering Load R5, 4(R7), show the registers’
contents “after” the completion of Stages to :
– Note: Fill in “?” for those blanks that cannot be determined.
RA RB RZ RY MAR MDR R5 R7
CSCI2510 Lec09: Basic Processing Unit 2024-25 T1 29
Ex 3: Store R6, X(R8)
MAR [PC], Read memory, RY MDR
Addr.
C IR PC
Wait_MFC, IR [MDR], Register
Gen.
PC [PC] + 4 (shown here) File reg. IR
#immediate
(R0~Rn-1) addr.
Decode instruction, A B Control
Circuitry
RA [R8], RB [R6] ...
control signals
• The src. reg. address is in IR31-27. RA RB
• The dest. reg. address is in IR26-22. RB
B_sel MuxB
RZ [RA] + X, RM [RB]
RA
• The immediate value X is from IR.
InA InB
• [R6] is forwarded to via RM. ALU
No action
Mem
W
RY MFC
MDR MAR
CSCI2510 Lec09: Basic Processing Unit 2024-25 T1 31
Ex 4: Branch
PC_enable
MAR [PC], Read memory, RY MDR
Addr.
C IR PC
Wait_MFC, IR [MDR], Register
Gen.
PC [PC] + 4 (shown here) File reg. IR
#immediate
(R0~Rn-1) addr.
Decode instruction A B Control
Circuitry
PC [PC] + branch offset ...
control signals
RA RB
• The branch offset is from IR.
• MuxINC (in Instruction Address RB
No action RA
InA InB
No action ALU
RB
Branch offset RZ RM
PC_enable
4 from IR
INC_sel
RZ MDR RZ PC
PC MuxINC
MuxY MuxMA
Instruction
Mem
Adder RY MDR MAR
Address
Generator
CSCI2510 Lec09: Basic Processing Unit 2024-25 T1 32
Class Exercise 9.4
• Branch instructions typically use the address field to
specify an offset from the current instruction to the
branch target. LABEL ADDR. OPCODE OPERAND
• Inter-stage registers
RY MDR
Addr.
RF_write C IR PC
Gen.
(i.e., RA, RB, RZ, RM, & Register
File reg. IR
#immediate
RY) are always enabled. A
(R0~Rn-1)
B
addr.
Control
Circuitry
– The results from one stage ...
control signals
are always transferred to RA RB
the next for simplicity. RB
MuxB
• Other registers (e.g., PC, RA
every stage. RZ RM
Mem
RY MDR MAR
IR_enable and RF_write.
CSCI2510 Lec09: Basic Processing Unit 2024-25 T1 35
Remark 2: Memory Function Completed
• For stages involving Mem,
RY MDR
Addr.
C IR PC
Gen.
– If data are in cache, the Register
File reg. IR
#immediate
stage can be completed in (R0~Rn-1) addr.
Control
A B
one clock cycle. Circuitry
...
– If data are not in cache, the RA RB
control signals
Mem
R/W
RY MFC
MDR MAR
subsequent stage(s).
CSCI2510 Lec09: Basic Processing Unit 2024-25 T1 36
Outline
• Processor Basics
• RISC-Style Processor Design
– Five-Stage Organization
– Instruction Execution
Register Control
File Circuitry
Temporary
Registers IR
Interconnect
CPU-Mem PC
Interface
Instruction
ALU
Address
To cache and main memory Generator
CSCI2510 Lec09: Basic Processing Unit 2024-25 T1 38
Buses: Key to Transferring Data
• It is typical to use buses to implement Interconnect.
– A bus consists of a set of lines that enable data transferring
from any one device to any other (connected to the bus).
A B C D
A-in A-out B-in B-out C-in C-out D-in D-out
#immediate
signals that determine: A
(R0~Rn-1)
B
addr.
Control
– What is the input data appearing Circuitry
...
at a Multiplexer’s output? RA RB
control signals
Mem
R/W
Adder RY MDR MAR
Address MFC
Generator
CSCI2510 Lec09: Basic Processing Unit 2024-25 T1 49
Control Signal Generation
• There’re two typical ways to generate control signals:
1) Hardwired Control: 2) Microprogrammed Control:
• The combinational circuit is used • Control signals are specified by
to “hard code” the generation of “micro-programs” in Control Store.
control signals with logic gates. – The micro-Program Counter (μPC)
points to the next control word.
• It is a “hardware approach” and can
operate at high speed. • It is a “software approach” and can
support a complex instruction set.
001...
T4 μProgram μProgram
(Add) (Sub)
T5
MAR [PC], Read memory, Wait_MFC, MAR [PC], Read memory, Wait_MFC,
IR [MDR], PC [PC] + 4 IR [MDR], PC [PC] + 4
Control Circuitry
T1 Control Word
T2 Control Word
Control
Memory I0 I1 I2 … …
Store
E.g.,
Add
Assembly μProgram
Program (Add)
CSCI2510 Lec09: Basic Processing Unit 2024-25 T1 53
Summary
• Processor Basics
• RISC-Style Processor Design
– Five-Stage Organization
– Instruction Execution