Lecture 3.1
Lecture 3.1
52
How Are These Instructions Executed?
By using instructions, we can speak the language of the
computer
FETCH
DECODE
EVALUATE ADDRESS
FETCH OPERANDS
EXECUTE
STORE RESULT
55
FETCH
The FETCH phase obtains the instruction from memory and
loads it into the Instruction Register (IR)
Complete description
Step 1: Load the MAR with the contents of the PC, and
simultaneously increment the PC
56
FETCH in LC-3
Step 1: Load
MAR and
increment PC
Step 2: Access
memory
Step 3: Load IR
with the content
of MDR
57
DECODE
The DECODE phase identifies the instruction
Also generates the set of control signals to process the
identified instruction in later phases of the instruction cycle
DECODE
identifies the
instruction to be
processed
Also generates
the set of
control signals
to process the
instruction
59
Recall: Decoder
“Input pattern detector”
n inputs and 2n outputs
Exactly one of the outputs is 1 and all the rest are 0s
The output that is logically 1 is the output corresponding to
the input pattern that the logic circuit is expected to detect
Example: 2-to-4 decoder
60
Recall: Decoder (II)
The decoder is useful in determining how to interpret a bit
pattern
It could be the A=1
address of a location 0
B=0
in memory, that the
processor intends to
read from 0
It could be an
instruction in the 1
program and the
processor needs to
decide what action to 0
take (based on
instruction opcode)
61
EVALUATE ADDRESS
The EVALUATE ADDRESS phase computes the address of
the memory location that is needed to process the
instruction
62
EVALUATE ADDRESS in LC-3
LDR calculates
the address by ADD
adding a
register and an
immediate
63
FETCH OPERANDS
The FETCH OPERANDS phase obtains the source operands
needed to process the instruction
In LDR
Step 1: Load MAR with the address calculated in EVALUATE
ADDRESS
In ADD
Obtain the source operands from the register file
64
FETCH OPERANDS in LC-3
65
EXECUTE
…
66
EXECUTE in LC-3
67
STORE RESULT
The STORE RESULT phase writes the result to the
designated destination
68
STORE RESULT in LC-3
69
STORE RESULT in LC-3
LDR loads
MDR into DR
70
The Instruction Cycle
FETCH
DECODE
EVALUATE ADDRESS
FETCH OPERANDS
EXECUTE
STORE RESULT
71
Changing the Sequence of Execution
A computer program executes in sequence (i.e., in program
order)
First instruction, second instruction, third instruction and so on
72
Jump in LC-3
Unconditional branch or jump
LC-3 JMP R2
Variations
RET: special case of JMP where BaseR = R7
JSR, JSRR: jump to subroutine
73
PC UPDATE in LC-3
JMP loads
SR1 into PC
74
Control of the Instruction Cycle
State 1
The FSM asserts GatePC and
LD.MAR
It selects input (+1) in PCMUX and
asserts LD.PC
State 2
MDR is loaded with the instruction
State 3
The FSM asserts GateMDR and
LD.IR
State 4
The FSM goes to next state
depending on opcode
State 63
JMP loads register into PC
FETCH
DECODE
EVALUATE ADDRESS
FETCH OPERANDS
EXECUTE
STORE RESULT
76
The Instruction Set
It defines opcodes, data types, and addressing modes
ADD and LDR have been our first examples
ADD
OP DR SR1 SR2
1 0 1 0 00 2
Register mode
LDR
OP DR BaseR offset6
6 3 0 4
Base+offset mode
77
The Instruction Set Architecture
The ISA is the interface between what the software commands
and what the hardware carries out
78
Many Different ISAs Over Decades
x86
PDP-x: Programmed Data Processor (PDP-11)
VAX
IBM 360
CDC 6600
SIMD ISAs: CRAY-1, Connection Machine
VLIW ISAs: Multiflow, Cydrome, IA-64 (EPIC)
PowerPC, POWER
RISC ISAs: Alpha, MIPS, SPARC, ARM, RISC-V, …
81
ISA-level Tradeoffs: Number of Registers
Affects:
Number of bits used for encoding register address
Number of values kept in fast storage (register file)
(uarch) Size, access time, power consumption of register file
82