Professional Documents
Culture Documents
Notes
Not all phases are needed by every instruction But all instructions will go through F and D Phases may take more than one clock cycle
Phases: Fetch
Load next instruction (at address stored in PC) from memory into Instruction Register (IR). Copy contents of PC into MAR. Send read signal to memory. Copy contents of MDR into IR. Then increment PC, so that it points to the next instruction in sequence. PC becomes PC+1.
F D EA OP EX S
4
Phases: Decode
First identify the opcode In LC-3, this is always the first four bits of instruction. A 4-to-16 decoder asserts a control line corresponding to the desired opcode. Depending on opcode, identify other operands from the remaining bits Example:
F D EA OP EX S
5
for LDR, last six bits is offset for ADD, last three bits is second source operand
For instructions that require memory access, compute address used for access Examples: add offset to base register (as in LDR) add offset to PC add offset to zero
F D EA OP EX S
F D EA OP EX S
load data from memory (LDR) read data from register file (ADD)
Phases: Execute
Perform the operation, using the source operands Examples: send operands to ALU and assert ADD signal
F D EA OP EX S
Write results to destination (register or memory) Examples: result of ADD is placed in destination register result of memory load is placed in destination register for store instruction, data is stored to memory
F D EA OP EX S
10
What is a bus? Global bus: Special set of wires that carry a 16bit signal to many components Inputs to the bus are tri-state buffers that only place a signal on the bus when they are enabled Only one device speaks on the bus at any given time
Control unit decides which signal drives the bus Control unit write-enables the destination device
11
Tri-State Buffer
Tri-state buffer allows some outputs to be turned off Places them in high-impedance or high-Z state Outputs can have one of three values Zero (0) One (1) Z (no output)
12
Global Bus
What is a bus?
13
Control and data registers for memory and I/O devices MAR (Memory Address Register) Holds the last address accessed MDR (Memory Data Register) Holds the last data read Control signal for read/write
CMPE12 Summer 2008 Slides by ADB 15
ALU
Output goes to bus, and then used by Condition code logic Register file Memory
17
Register File
Two read addresses (SR1, SR2) One write address (DR) Inputs: one of the following Result of ALU operation Memory read Outputs: Two 16-bit outputs used by ALU
PC and PCMUX
PC and PCMUX Program Counter and the PC multiplexer Input to PC: one of the following (controlled by PCMUX) PC+1 from the fetch stage Output of address adder (for branches and jumps) Global bus for trap instructions
CMPE12 Summer 2008 Slides by ADB 21
Inputs to MAR: one of the following (controlled by MARMUX) Output of address adder (for loads and stores) Zero-extended IR[7:0] for trap instructions
23
Condition Codes
Input The global bus Output N, Z, P signals Registers set only when control unit enables them (LD.CC) Certain instructions set the codes
24
On each machine cycle, FSM changes control signals for next phase of instruction processing
GateALU,
LD.REG,
25
10
On each machine cycle, FSM changes control signals for next phase of instruction processing Who drives the bus?
GatePC, GateALU,
LD.IR, LD.REG,
ALUK
Example 1
Example 2
Example 3
27
11
System bus:
28
System bus:
29
12
System bus:
30
System bus:
31
13
System bus:
32
Example 1: 5. Execute
x30A2 add R2,R0,R1 R0 = R1 = R2 =
System bus:
33
14
System bus:
34
Example 2:
x3117 STR R3,R5,xB R3 = R5 =
15
Example 2:
x3117 STR R3,R5,xB R3 = R5 =
Example 2:
x3117 STR R3,R5,xB R3 = R5 =
2. Instruction decode
CMPE12 Summer 2008 Slides by ADB 37
16
Example 2:
x3117 STR R3,R5,xB R3 = R5 =
3. Evaluate address
CMPE12 Summer 2008 Slides by ADB 38
Example 2:
x3117 STR R3,R5,xB R3 = R5 =
4. Fetch operands
CMPE12 Summer 2008 Slides by ADB 39
17
Example 2:
x3117 STR R3,R5,xB R3 = R5 =
5. Execute
CMPE12 Summer 2008 Slides by ADB 40
Example 2:
x3117 STR R3,R5,xB R3 = R5 =
6. Store results
CMPE12 Summer 2008 Slides by ADB 41
18
Example 3:
x3040 BRZ EndLoop EndLoop =
Example 3:
x3040 BRZ EndLoop EndLoop =
19
Example 3:
x3040 BRZ EndLoop EndLoop =
2. Instruction decode
CMPE12 Summer 2008 Slides by ADB 44
Example 3:
x3040 BRZ EndLoop EndLoop =
3. Evaluate address
CMPE12 Summer 2008 Slides by ADB 45
20
Example 3:
x3040 BRZ EndLoop EndLoop =
4. Fetch operands
CMPE12 Summer 2008 Slides by ADB 46
Example 3:
x3040 BRZ EndLoop EndLoop =
5. Execute
CMPE12 Summer 2008 Slides by ADB 47
21
Example 3:
x3040 BRZ EndLoop EndLoop =
6. Store results
CMPE12 Summer 2008 Slides by ADB 48
Recommended exercises:
49
22
50
23