Computer Architecture
Topics:
l
Processor Design
C-Programming
l
Data Representation
l
Digital Logic
l
l
Processor Design
Figure out how a small subset of the
instruction set works in hardware
l Use Hardware blocks to describe data path
l Use control logic to ensure steps of the
instruction flows smoothly
l
Add instruction
l
Instruction Example
l
Generic Form!
Addition Instruction
Encoded Representation!
addl %edx, %eax!
0 3 rA! rB!
Two-byte encoding
l
l
Generic Form!
Addition Instruction
Encoded Representation!
addl %edx, %eax!
l
l
l
l
l
0 3 C! 2!
8(%ebp),
%eax!
So, 03 C2 means add addl
%edx,
%eax
03 45
means add 8(%ebp), %eax
addl $4, %eax!
05
add $cons, %eax
0 3 4 5
0 5 000
Instruction Code!
Subtract (rA from rB)!
subl rA, rB!
2 B rA! rB!
And!
andl rA, rB!
2 3 rA! rB!
Exclusive-Or!
xorl rA, rB!
3 3 rA! rB!
Building Blocks
l
fun"
A"
Combinational Logic
l
Compute Boolean
functions of inputs
Continuously respond to
input changes
Operate on data and
implement control
A"
L"
U"
B"
A"
MUX"
B"
="
S
B
valA"
srcA"
Storage Elements
l
l
valW"
Register"
file"
valB"
srcB"
A"
Store bits
Addressable memories
Non-addressable registers
B"
W"
dstW"
Clock"
Clock!
Fetch Instruction
+"
+4"
PC
IR
A"
L"
U"
IR
%edx
Register file
%eax
l
l
l
l
A"
L"
U"
03 C2
IR
%eax
Register file
l
l
l
l
l
l
A"
L"
U"
+"
IR
%ebp
Register file
A"
L"
U"
address
%eax
data
l
l
l
l
R/W
+"
IR
%ebp
Register file
A"
L"
U"
address
%eax
data
l
l
l
l
R/W
SEQ Hardware
Structure
l
State
l
l
l
l
Instruction Flow
l
l
l
newPC
PC!
!! !
valE , valM
Write back!
valM
!
!
Data
Data
memory
memory
Memory!
! !
Addr, Data
valE
CC!
! CC
aluA!, a!luB!
Execute!
ALU
ALU
Bch
!! !
valA , valB
!! !
!! !
! ! !!
! !
srcA , srcB
dstA , dstB
Decode!
Register
RegisterM
file
file
E
, !! !!
icode! ifun
rA! , rB
valC
Fetch!
valP
!
!
!
Instruction
Instruction
memory
memory
PC
!
!
PC
PC
increment
increment
newPC
SEQ Stages
l
Fetch
l
valM
!
!
Data
Data
memory
memory
Memory!
! !
Addr, Data
valE
CC!
! CC
aluA!, a!luB!
Execute!
!! !
valA , valB
! ! !!
! !
Register
RegisterM
file
file
E
!! !
!! !
srcA , srcB
dstA , dstB
Decode!
, !! !!
icode!ifun
rA! , rB
valC
PC
l
ALU
ALU
Bch
Write Back
l
Write back!
Memory
l
Execute
l
!! !
valE , valM
Decode
l
PC!
Fetch!
valP
!
!
!
Instruction
Instruction
memory
memory
PC
!
!
PC
PC
increment
increment
Instruction Decoding
Optional!
5
0 rA" rB"
Optional!
D"
icode!
ifun!
rA!
rB!
valC!
Instruction Format
l Instruction
byte
icode:ifun
l Optional register byte
rA:rB
l Optional constant word
valC
Executing Arith./Logical
OperationOPl rA, rB! 6 rA! rB!
fn"
Fetch
l
Read 2 bytes
Decode
l
Perform operation
Set condition codes
Memory
l
Execute
l
Write back
l
Do nothing
Update register
PC Update
l
Increment PC by 2
Fetch!
Decode!
Execute!
Memory!
Write!
icode:ifun M1[PC]!
rA:rB M1[PC+1]!
valP PC+2!
valA R[rA]!
Read operand A!
valB R[rB]!
Read operand B!
Set CC!
R[rB] valE!
!
back!
PC update! PC valP!
!
Write back result!
!
Update PC!
Executing popl
l
Fetch
l
8 F rA! 8
l
Read 2 bytes
Decode
l
popl rA!
Write back
l
Execute
l
Memory
PC Update
l
Increment PC by 2
POP Instruction
Fetch!
Decode!
Execute!
Memory!
icode:ifun M1[PC]!
rA:rB M1[PC+1]!
valP PC+2!
valA %esp!
valB %esp!
valE valB + 4!
valM M4[valA]!
Write!
R[%esp] valE!
R[rA] valM!
back!
PC update! PC valP!
l
l
Popped value
New stack pointer
Executing Jumps
fall thru:!
XX XX
Not taken!
target:!
XX XX
Taken!
Read 5 bytes
Increment PC by 5
Decode
l
7 fn"
Fetch
l
jXX Dest!
Do nothing
Execute
l
Dest"
Memory
l
Write back
l
Do nothing
Do nothing
PC Update
l
Fetch!
icode:ifun M1[PC]!
valC M4[PC+1]!
valP PC+5!
Bch Cond(CC,ifun)!
Take branch?!
Decode!
Execute!
Memory!
Write!
!
back!
PC update! PC Bch ? valC : valP!
l
l
!
!
Update PC!
Executing call
call Dest!
XX XX
target:!
XX XX
Dest"
Memory
l
Execute
l
Read 5 bytes
Increment PC by 5
Decode
l
return:!
Fetch
l
E 8
Write back
l
PC Update
l
Set PC to Dest
Fetch!
Decode!
Execute!
Memory!
Write!
icode:ifun M1[PC]!
valC M4[PC+1]!
valP PC+5!
valB R[%esp]!
valE valB + 4!
M4[valE] valP !
R[%esp] valE!
!
back!
PC update! PC valC!
l
l
Executing ret
C 3
ret!
return:!
l
Fetch
l
Read 1 byte
Read stack pointer
Execute
l
Memory
l
Decode
l
XX XX
Write back
l
PC Update
l
Fetch!
Decode!
Execute!
Memory!
Write!
icode:ifun M1[PC]!
valA R[%esp]!
valB R[%esp]!
valE valB + 4!
valM M4[valA] !
R[%esp] valE!
!
back!
PC update! PC valM!
l
l