Lecture 8 - Instruction Processing and lidar EECS 388
Lecture 8 - Instruction Processing and lidar EECS 388
Jacob Schoonover
Lecture notes based in part on slides created by Alex Fosdick,
Heechul Yun, Mohammad Alian, and Tamzidul Hoque
1
Agenda & Announcements
• Instruction Pipeline
• 5 minute break
• Review Lab 4
2
Homework 1 Correction
3
Context
Application Program
Operating
Compiler System Ch 5. Computer Organization and
Design
Machine Language (ISA)
Digital Logic
Electronic Circuits
Transistors
4
Control Unit
• Control unit orchestrates the execution of
each instruction
5
Function of Control Unit
• Read an instruction from
memory into Instruction
Register (IR)
• By loading the memory
address pointed by PC
6
Instruction Processing
7
Instruction
Smallest unit of execution in a processor
• Carries two pieces of information
• Opcode: operation to be performed
• Operands: data to be used for operation
• Registers, immediate values, memory addresses
• Instructions are sequences of bits
• Instruction Set Architecture (ISA) is the
collection of all instructions that a
processor supports
8
Instruction Example
Assembly Machine code
addi $sp, $sp, -32 0x23bdffe0
9
Instruction in memory
Machine code in Main
PC addi $sp, $sp, -32 0x23bdffe0 Memory
Address Data /
sw $s0, 24($sp) 0xafb0001 Instructions
8
0x00 0x23
• Q1: What is the value of PC 0x01 0xbd
before any instruction is fetched? 0x02 0xff
0x03 0xe0
0x04 0xaf
• Q2: What is the endianness of the
0x05 0xb0
processor?
0x06 0x00
0x07 0x18
0x08 ….
10
#include <stdio.h>
int main ()
{
unsigned int x = 0x76543210;
char *c = (char*) &x;
11
Instruction Processing: Fetch
F
• Read next instruction (pointed by PC) from
memory into IR
D
12
Updating PC for Jump Instruction
But we do not always fetch from the next address!
• Semantics
• target_addr = PC + imm
• GPR[rd] PC + 4
• PC target_addr
13
Instruction Processing: Decode
1. Identify the opcode and operands F
2. Generate control signal to perform
the tasks
D
Mem
WB
14
Instruction Processing: Execute
F
ADD
Mem
$sp- 32
WB
15
Instruction Processing: Memory
Operations
F
• If the instruction is a load or
store, then perform loading D
from or storing to memory
sw $s0, 24($sp) EXE
Mem
• Load/store also involves ALU
operation in EXE stage. What WB
ALU operation is that?
16
Instruction Processing: Write Back
• Update the register file with newly calculated
results F
• E.g.,
• Here, $sp register needs update after the D
addi is performed
EXE
addi $sp, $sp, -32
Mem
17
Illustration of CPU Datapath for
MIPS
Figure from Chapter 5 of Textbook: Computer Organization and Design, Revised Printing, Third Edition
Case Study: Atmel ATmega168
8 bit data bus
19
Case Study: Atmel ATmega168
8 bit data bus
Instruction PC
Memory
Register
IR
File
Control
Unit
ALU
Data
IO
Memory
20
???
21
22
23
Register Value
$zero 0x00000000
$v0 0x0000000A
$v1
…
$sp 0xFFFFFF02
$fp 0xFFFFFFA5
$ra 0x00008008
24
Initial State
$t0 0
$t1 40
Register
$t2 60
$s0 200
$s1
$s2
Address Data
Inst. Memory
0 add $t0, $t1, $t2
4 sw $s0, 4($t1)
8 beq $s1, $s2, 24
Address Data
Data Memory
40 0
44 0
48 0
25
Fetch
Mem
EXE
WB
D
F
$t0 0
$t1 40
Register
$t2 60
$s0 200
$s1
$s2
Address Data
Inst. Memory
0 add $t0, $t1, $t2
4 sw $s0, 4($t1)
0
8 beq $s1, $s2, 24
Address Data
Data Memory
40 0
44 0
48 0
26
Fetch
Mem
EXE
WB
D
F
$t0 0
$t1 40
Register
$t2 60
$s0 200
$s1
$s2
Address Data
Inst. Memory
0 0 add $t0, $t1, $t2
4 sw $s0, 4($t1)
8 beq $s1, $s2, 24
Address Data
Data Memory
40 0
44 0
48 0
Program counter starts from 0
27
Fetch
Mem
EXE
WB
D
F
$t0 0
$t1 40
Register
$t2 60
$s0 200
$s1
$s2
Address Data
Inst. Memory
add $t0,
0 $t1, $t2 0 add $t0, $t1, $t2
4 sw $s0, 4($t1)
8 beq $s1, $s2, 24
Address Data
Data Memory
40 0
44 0
48 0
Inst mem gets 0 as input, outputs the content at address 0
28
Fetch
Mem
EXE
WB
D
F
$t0 0
$t1 40
Register
$t2 60
$s0 200
$s1
$s2
add $t0, $t1, $t2
Address Data
Inst. Memory
add $t0,
0 $t1, $t2 0 add $t0, $t1, $t2
4 sw $s0, 4($t1)
8 beq $s1, $s2, 24
Address Data
Data Memory
40 0
44 0
48 0
Content at address 0 is the first instruction
29
Decode for Add
Inst 25-21,
rs
Inst 20-16, rt
Inst 15-11,
rd
Inst 15-0, imm
30
30
Decode
Mem
EXE
WB
D
F
$t0 0
$t1 40
Register
$t2 60
$s0 200
$s1
$s2
Address Data
Inst. Memory
add $t0,
0 $t1, $t2 0 add $t0, $t1, $t2
$t1
$t2 4 sw $s0, 4($t1)
$t0 8 beq $s1, $s2, 24
Address Data
Data Memory
40 0
add 44 0
48 0
Instruction gets broken down into segments and goes to
register and control units
31
Decode
Mem
EXE
WB
D
F
$t0 0
$t1 40
Register
$t2 60
$s0 200
$s1
$s2
Address Data
Inst. Memory
add $t0,
0 $t1, $t2 0 add $t0, $t1, $t2
$t1
$t2 4 sw $s0, 4($t1)
$t0 8 beq $s1, $s2, 24
Address Data
Data Memory
Select Rt 40 0
add 44 0
48 0
Control signals are asserted
32
Decode
Mem
EXE
WB
D
F
$t0 0
$t1 40
Register
$t2 60
$s0 200
$s1
$s2
Address Data
Inst. Memory
add $t0, 40
0 $t1, $t2 0 add $t0, $t1, $t2
$t1
$t2 60 4 sw $s0, 4($t1)
$t0 8 beq $s1, $s2, 24
Address Data
Data Memory
40 0
add 44 0
48 0
Register data Rs and Rt comes out
33
Execute
Mem
EXE
WB
D
F
$t0 0
$t1 40
Register
$t2 60
$s0 200
$s1
$s2
Address Data
Inst. Memory
add $t0, 40
0 $t1, $t2 0 add $t0, $t1, $t2
$t1 100
Address Data
Data Memory
40 0
add Do Add 44 0
48 0
ALU Performs Add
34
Mem
Mem
EXE
WB
D
F
$t0 0
$t1 40
Register
$t2 60
$s0 200
$s1
$s2
Address Data
Inst. Memory
add $t0, 40
0 $t1, $t2 0 add $t0, $t1, $t2
$t1 100
Address Data
Data Memory
40 0
add No read/Write
44 0
48 0
Mem stage only needed for Load Store
35
Write Back
Mem
EXE
WB
D
F
$t0 100
$t1 40
Register
$t2 60
Select ALU out
$s0 200
$s1
10 10
0 0 $s2
Address Data
Inst. Memory
add $t0,
0 $t1, $t2 0 add $t0, $t1, $t2
4 sw $s0, 4($t1)
$t0 8 beq $s1, $s2, 24
Address Data
Data Memory
add
36
Anytime
Mem
EXE
WB
D
F
Not a branch
$t0 100
PC+ $t1 40
Register
4
$t2 60
PC+4 $s0 200
$s1
$s2
Address Data
Inst. Memory
4 0 add $t0, $t1, $t2
4 sw $s0, 4($t1)
8 beq $s1, $s2, 24
Address Data
Data Memory
add
37
5 minute break
38
Lab 4: Lidar
39
Lab 4: Lidar
40
How the TFmini sends data
1 0 0 0 1 1 1 0 0 1 0 1 1 1 0 1
0 1 0 1 1 1 0 1 1 0 0 0 1 1 1 0
43