Topic #3 - CPU - With Notations
Topic #3 - CPU - With Notations
Topic #3 - CPU - With Notations
COEN 311
Computer Organization & Software
Topic #3 - continued
Principle Components of a Computer (CPU)
Dr. Fadi Alzhouri
2
Performance: Execution Time = CPU Time
• Computers operations are synchronized with a clock signal.
• Clock will determine when the events must happen.
• Clock period, or clock cycle is the amount of time in which a period is completed.
• Clock rate (or frequency) is the reverse of the clock period.
• Example: if clock period is 250 ps, the clock rate will be 4 GHz.
• CPU Clocking
3
CPU Time
CPU Time CPU Clock Cycles Clock Cycle Time
CPU Clock Cycles
Clock Rate
Performance improved by
Reducing number of clock cycles
Increasing clock rate (reducing length of clock cycles)
4
Example: CPU Time
5
Example: CPU Time (cont.)
6
Components of a Computer System
7
Central Processing Unit (CPU)
• CPU is the heart and brain
• It interprets and executes machine level instructions
• Controls data transfer from/to Main Memory (MM) and CPU
• Detects any errors
8
Instruction Representation
• CPU operation is determined by the instruction it executes
• Collection of these instructions that a CPU can execute forms its Instruction Set
Architecture.
• An instruction is represented as sequence of bits, for example:
1001 0010 0000 0011 1011 1011 1000 0001
• Instruction is divided into fields 9 2 0 3 B B 8 1
Opcode Operand1 Operand2
• 1-address instructions
e.g. Inc A ; A = A+1
10
Simple Instruction Set
Assume we have a processor whose Instruction Set consists of four machine
language instructions
• Move from a memory location to a data register in CPU
• Move from a data register in CPU to a memory location
move $0000 0000
• Add the contents of a memory location to a data register
add
• Stop move
Suppose our program for Z = X + Y looks like:
Move D0, X
Add D0, Y
Move Z, D0
Directive
Stop
This program is coded into machine instruction and suppose is loaded into memory
starting at location $0000 0000 11
• How does the CPU know which instruction to execute?
• There is a dedicated register in CPU called Program Counter (PC)
that points to the memory location where next instruction is stored
Therefore, at start PC = $0000 0000
• Instruction is in Main Memory – it is to be transferred
(fetched) to CPU to be executed
• CPU has an Instruction Register (IR) that holds the instruction
• What kind of instruction is to be executed?
• CPU has its own Instruction Interpreter (Decoder)
• Followed by Instruction execution
• Next instruction follows. PC is incremented by length of
instruction just completed
12
Mechanism of Transferring Data from MM to CPU
CPU has an external bus that connects it to the Memory and I/O devices.
The data lines are connected to the processor via the Memory Data Register
(MDR)
The address lines are connected to the processor via the Memory Address
Register (MAR)
• Memory address from where the instruction/data is to be accessed is copied into
MAR register
• Contents of MAR are loaded onto address bus
• Corresponding memory location accessed MAR
Address bus
Control bus
CPU MM
R/W 13
General Purpose Register (GPR)Architecture
Its functional units are:
- Data Registers: Register File (consists of number of data register, for example D0, D1,
D2,..., D7) for arithmetic operations – holds any kind of data
- Address Registers: A0, A1, A2,..., A7 serve as pointers to memory addresses
- Working Registers: several such registers – serve as scratch pads for CPU
- Program Counter (PC) holds the address in memory of the next instruction to be
executed. After an instruction is fetched from memory, the PC is automatically
incremented to hold the address of, or point to, the next instruction to be executed.
- Instruction Register (IR) holds the most recently read instruction from memory while it
is being decoded by the Instruction Interpreter.
- Memory Address Register (MAR) holds the address of the next location to be accessed
in memory.
- Memory Buffer Register (MBR or MDR) holds the data just read from memory, or the
data which is about to be written to memory. Buffer is referring to temporarily holding
data.
- Status Register (SR) to record status information 14
GPR CPU (16 bit)
0
1 Register Data bus
2 File MDR
3 IR
Address bus
MAR
Interpreter
ALU
PC
Memory
Control
16 bit Increment
CPU 8 bit Memory 15
Program Execution
Fetch Cycle:
• Processor fetches one instruction at a time from successive memory locations until
a branch/jump occurs.
• Instructions are located in the memory location pointed to by the PC
• Instruction is loaded into the IR
• Increment the contents of the PC by the size of an instruction
Decode Cycle:
• Instruction is decoded/interpreted, opcode will provide the type of operation to be
performed, the nature and mode of the operands
• Decoder and control logic unit are responsible for selecting the registers involved
and directing the data transfer.
Execute Cycle:
• Carry out the actions specified by the instruction in the IR
16
Execution for add R3, R1,R2 in a GPR processor
Memory location MAR PC R3 R1 + R2
MDR M[MAR]
16 bit instruction
Fetch
PC PC + 2
IR MDR
Decode
R3 R1 + R2 Execute
17
Instruction Execution in GPR Machine
ADD R3, R1, R2
R3 <- R1 + R2
$10 9103
$12 9202 1) Fetch PC = $14 & Inc PC
$14 A039
2) Decode
Memory
1010 xxxx xx11 10 01
ADD R3, R2, R1
CPU
18
GPR CPU
0
1 Register Data bus
2 File MDR
3 IR
Address bus
Type equation here. MAR
Interpreter
ALU
PC
Memory
Control
16 bit Increment
CPU 8 bit Memory 19
Timing Analysis of Instruction Execution ADD R3, R1, R2
0.3ns 1 MARPC
imm
IR MDR
Decode
0
1 Register Data bus
2 File MDR
3 IR
Address bus
Type equation here. MAR
Interpreter
ALU
PC
Memory
Control
16 bit Increment
CPU 8 bit Memory 23
Complex (multiple words) instruction
40 bits = 5 Bytes!!
48 bits = 6 Bytes 24
1010 0000 0100 0000 $2000 $2002
ADD R4, ($2000), ($2002) 16 bits 16 bits 16 bits
$1000 A040
Instruction $1002 2000
PC
$1004 2002 48
A040 IR
16 bits
$0710 $0311
$2000
16
+
MAR Temp 1
$2002
$2000 0710
Data MDR Temp 2
$2002 0311 R4
MARPC $1000
IRMDR $A040
other opcode
decode interpret
26
ADD R4, ($2000), ($2002)
PCPC+2 $1002
PCPC+2 $1004
MAR PC $1004
Fetch address of
memory operand 2
MDRM[MAR] $2002
Temp2MDR $2002
27
ADD R4, ($2000), ($2002)
Temp2 MDR
Data bus
Acc MDR
IR
Address bus
MAR
Interpreter
ALU
PC
Memory
Control
16 bit Increment
CPU 10 bit Memory 32
Execution for Add Y in an Acc Architecture
MAR PC ADD Y
ACC ACC + M[Y]
MDR M[MAR]
Fetch
PC PC + 2
IR MDR
Decode
We want to compute
a (x+y) * (x-y)
where x, y and a are memory references
34
Instruction Sets
1) Accumulator Machine Memory
ADD X ; ACC ACC + M[X]
SUB X ; ACC ACC – M[X] ..
MUL X ; ACC ACC * M[X] .
.
LD X ; ACC M[X] X x
ST X ; M[X] ACC
address data
X: address in memory
x: data in memory, i.e., M[X]=x
2) GPR Machine
ADD Rk, Ri, Rj ; Rk Ri + Rj
SUB Rk, Ri, Rj ; Rk Ri – Rj dest src1 src2
MUL Rk, Ri, Rj ; Rk Ri * Rj ADD Rk, Ri, Rj
MOV Rj, Ri ; Rj Ri
MOV X, Ri ; M[X] Ri
MOV Ri, X ; Ri M[X] 35
1) Accumulator Machine
LD X ; ACC M[X] = x
x X
y Y
ADD Y ; ACC M[Y] + x ..
..
ST T ; M[T] = temp x + y a A
temp T
LD X ; ACC M[X] = x
SUB Y ; ACC ACC - M[Y] = x-y data address
36
2) GPR
37
The Assembly Programs
1) Accumulator Machine
LD X ; ACC M[X] = x
ADD Y ; ACC ACC + M[Y] = x + y
ST T ; M[T] = temp ACC = x + y x X
y Y
LD X ; ACC M[X] = x ..
SUB Y ; ACC ACC – M[Y] = x-y .
.
MUL T ; ACC (x-y)*M[T] = (x-y)*temp a A
ST A ; M[A] = a (x-y)*(x+y) temp T
2) GPR
MOV X, R0 ; R0 M[X] = x data address
MOV Y, R1 ; R1 M[Y] = y
ADD R2, R0, R1 ; R2 R0+R1
SUB R3, R0, R1 ; R3 R0-R1
MUL R0, R2, R3 ; R0 R2*R3
MOV A, R0 ; M[A] R0 = R2*R3
; a (x+y)*(x-y)
38
Next …. Memory (Topic #3_2)
39