Documente Academic
Documente Profesional
Documente Cultură
CPS104 Lec-8.1
GK Spring 2004
Circuit Design
Hardware
CPS104 Lec-8.2
GK Spring 2004
Levels of Representation
temp = v[k]; High Level Language Program Compiler Assembly Language Program Assembler Machine Language Program
0000 1010 1100 0101 1001 1111 0110 1000
RegDst
Rw Ra Rb 32 32-bit Registers
ALU
Mux
busB 32
32
Mux
Extender
imm16
32 ALUSrc
16
Data In 32 Clk
Data Memory
ExtOp
GK Spring 2004
Computer Architecture?
. . . the attributes of a [computing] system as seen by the programmer, i.e. the conceptual structure and functional behavior, as distinct from the organization of the data flows and controls the logic design, and the physical implementation. Amdahl, Blaaw, and Brooks, 1964
SOFTWARE
CPS104 Lec-8.4
GK Spring 2004
CPS104 Lec-8.5
GK Spring 2004
Other Aspects
Successor instruction Conditions Encoding Parallelism
CPS104 Lec-8.6
GK Spring 2004
Stack:
0 address add tos tos + next (JAVA VM)
Load/Store:
3 address add Ra Rb Rc load Ra Rb store Ra Rb Ra Rb + Rc Ra mem[Rb] mem[Rb] Ra
GK Spring 2004
CPS104 Lec-8.7
Accumulator
Instruction set: Accumulator is implicit operand one explicit operand add, sub, mult, div, . . . clear Example: a*b - (a+c*b) clear 0 add c 2 mult b 6 a 4 add a 10 b 3 time st tmp 10 c 2 tmp clear 0 add a 4 mult b 12 sub tmp 2 9 instructions
CPS104 Lec-8.8
GK Spring 2004
Stack Machines
Instruction set: add, sub, mult, div . . . Top of stack (TOS) and TOS+1 are implicit push A, pop A TOS is implicit operand, one explicit operand Example: a*b - (a+c*b) push a time push b mult C -+* C*B B A B +* A A*B push a A A*B A*B A C A A*B A A*B push c A*B push b mult add + * sub * a b a 9 instructions
CPS104 Lec-8.9
GK Spring 2004
2-address ISA
Instruction set: Two explicit operands, one implicit add, sub, mult, div, one source operand is also destination add a,b a <- a + b Example: a*b - (a+c*b)
add tmp1, b mult tmp1, c add tmp1, a add tmp2, b mult tmp2, a sub tmp2, tmp1 6 instructions
a b c tmp1 tmp2
4 3 2
CPS104 Lec-8.10
GK Spring 2004
3-address ISA
Instruction set: Three explicit operands, ZERO implicit add, sub, mult, div, add a,b,c a <- b + c
a b c tmp1 tmp2
4 3 2
CPS104 Lec-8.11
GK Spring 2004
A place to hold values that can be named within the instruction Like memory, but much smaller Byte Address Data u 32-128 locations 0 00110110 1 00001100 How many bits to specify a register?
2 3 4
r0
2n-1-4 2n-1
r31
CPS104 Lec-8.12
GK Spring 2004
Instruction set: Three explicit operands, ZERO implicit add, sub, mult, div, add a,b,c a <- b + c
a b c
4 3 2
CPS104 Lec-8.13
GK Spring 2004
Instruction set: add, sub, mult, div, only on operands in registers ld, st, to move data from and to memory, only
a b c
4 3 2
GK Spring 2004
Given int x; int *p; p = &x; *p = *p + 8; Instructions ld r1, p ld r2, r1 add r2, r2, 0x8 st r1, r2
x 0x26cf0
...
p 0x26d00 0x26cbf0
Many different ways to address operands u not all Instruction sets include all modes
CPS104 Lec-8.15
GK Spring 2004
So far, still too abstract u add r1, r2, r3 Need to specify instructions in machine readable form Bunch of Bits Instructions are bits with well defined fields u Like a floating point number has different fields Instruction Format u Establishes a mapping from instruction to binary values u Which bit positions correspond to which parts of the instruction (operation, operands, etc.)
CPS104 Lec-8.16
GK Spring 2004
A "Typical" RISC
32-bit fixed format instruction (3 formats) 32 64-bit GPR (R0 contains zero) 3-address, reg-reg arithmetic instruction Single address mode for load/store: base + displacement u no indirection
see: SPARC, MIPS, MC88100, AMD2900, i960, i860 PARISC, PowerPC, DEC Alpha, Clipper, CDC 6600, CDC 7600, Cray-1, Cray-2, Cray-3
CPS104 Lec-8.17
GK Spring 2004
Example: MIPS
Register-Register
31 26 25 21 20 16 15 11 10 6 5 0
Op
Rs1
Rs2
Rd
Opx
Register-Immediate
31 26 25 21 20 16 15 0
Op Branch
31
Rs1
26 25 21 20
Rd
16 15
immediate
Op Jump / Call
31
Rs1
Rs2/Opx
immediate
26 25
Op
CPS104 Lec-8.18
target
GK Spring 2004
A Program
#include <iostream.h> main() { int *a = new int[100]; int *p = a; int k; for (k = 0; k < 100; k++) { *p = k; p++; }
2n-1
Stack
.cc file
bits
Data
Text
cout << "entry 3 = " << a[3] << endl; }
add r,s1,s2
0
CPS104 Lec-8.19
Reserved
GK Spring 2004
Instructions: a fixed set of built-in operations Instructions and data are stored in the (same) computer memory Fetch Execute Cycle
while (true){ fetch instruction execute instruction }
CPS104 Lec-8.20
GK Spring 2004
Next Instruction
CPS104 Lec-8.21
Instruction Format u how do we tell what operation to perform? Location of operands and result u where other than memory? u how many explicit operands? u how are memory operands located? u which can or cannot be in memory? Data type and Size Operations u what are supported Successor instruction u jumps, conditions, branches fetch-decode-execute is implicit!
GK Spring 2004
Arithmetic u add, sub, mul, etc Logical u and, or, shift Data Transfer u load, store u MIPS is LOAD/STORE architecture Conditional Branch
u
implement if,
CPS104 Lec-8.22
GK Spring 2004
3-Address Load Store Architecture. Register and Immediate addressing modes for operations. Immediate and Displacement addressing for Loads and Stores. Examples: add $1, $2, $3 # $1 = $2 + $3 addi $1, $1, 4 # $1 = $1 + 4 lw sw lui addi $1, 100 ($2) $1, 100 ($2) $1, 100 $1, $3, 100 # # # # $1 = Memory[$2 + 100] Memory[$2 + 100] = $1 $1 = 100 << 16 $1 = $3 + 100
CPS104 Lec-8.23
GK Spring 2004
Registers: fast memory, Integral partr0 of the CPU. r1 Programmable storage 2 32 bytes 31 x 32-bit GPRs (R0 = 0) 32 x 32-bit FP regs (paired DP) 32-bit HI, LO, PC r31
PC lo hi
CPS104 Lec-8.24
GK Spring 2004
Op
Rs
Rt
Rd
shamt
func
I-type: Register-Immediate
31 26 25 21 20 16 15 0
Op
Rs
Rt
immediate
Op
target
R Type:
31 26 25 21 20
Op op rs rt rd shmt func
Rs
Rt
Rd
shmt
func
a 6-bit operation code. a 5-bit source register. a 5-bit target (source) register. a 5-bit destination register. a 5-bit shift amount. a 6-bit function field.
# $1 = $2 + $3
shmt func
000000
CPS104 Lec-8.26
00010
100000
GK Spring 2004
Op
Rs
Rt
Immediate
001000
00010
00001
GK Spring 2004
Op
Rs Register
Rt
Immediate Memory
+
Register
Base+index
Load Word Example lw $1, 100($2)
op rs
# $1 = Mem[$2+100]
rt immediate
010011
00010
00001
CPS104 Lec-8.28
GK Spring 2004
Successor Instruction
Instruction Fetch Instruction Decode Operand Fetch Execute Result Store Next Instruction
CPS104 Lec-8.29
GK Spring 2004
main() { int x,y,same; // $0 == 0 always x = 43; // addi $1, $0, y = 2; // addi $2, $0, same = 0; // addi $3, $0, if (x == y) same = 1; // execute only if x // addi $3, $0, 1 }
43 2 0 == y
Special register (pc) that points to instructions Contains memory address (like a pointer) Instruction fetch is
u
inst = mem[pc]
= pc + ?
Size of instruction?
CPS104 Lec-8.30
GK Spring 2004
43 2 0 1
Clearly, this is not correct We cannot always execute both 0x10008 and 0x1000c
CPS104 Lec-8.31
GK Spring 2004
Op
Rs PC
Rt
Immediate Memory
+
4
PC relative addressing Branch Not Equal Example bne $1, $2, 100 # If ($1!= $2) goto [PC+4+100] +4 because by default we increment for sequential u more detailed discussion later in semester
op
rs
rt
immediate
000101
00001
00010
CPS104 Lec-8.32
GK Spring 2004
addi $1, $0, 43 addi $2, $0, 2 addi $3, $0, 0 bne $1, $2, 4 addi $3, $0, 1
Understand branches
CPS104 Lec-8.33
GK Spring 2004
Successor Instruction
Instruction Fetch Instruction Decode Operand Fetch Execute Result Store Next Instruction
CPS104 Lec-8.34
GK Spring 2004
int equal(int a1, int a2) { int tsame; tsame = 0; if (a1 == a2) tsame = 1; // only if a1 == a2 return(tsame); } main() { int x,y,same; // r0 == 0 always x = 43; // addi $1, $0, 43 y = 2; // addi $2, $0, 2 same = equal(x,y); // need to call function // other computation }
0x10000 addi $1, $0, 43 0x10004 addi $2, $0, 2 0x10008 go execute equal
0x30408 addi $3, $0, 0 0x3040c beq $1, $2, 8 0x30410 addi $3, $0, 1
return $3
CPS104 Lec-8.35
GK Spring 2004