Instruction Set Instruction Set Principles and Examples Principles and Examples Principles and Examples Principles and Examples
Instruction Set Instruction Set Principles and Examples Principles and Examples Principles and Examples Principles and Examples
Instruction Set Instruction Set Principles and Examples Principles and Examples Principles and Examples Principles and Examples
Source: Book
support materials
By: Alfonso Avila
Alfonso Avila, ITESM Campus Monterrey
RISC
(Mips,Sparc,HP-PA,IBM RS6000, . . .1987)
Alfonso Avila, ITESM Campus Monterrey
Classifying ISA’s
ISAs
ISA = Instruction Set Architecture
Classifying ISA’s
ISAs
Implement the following statement using an register-memory
architecture
C = A + B assuming: A in address 100
B in address 101
C in address 102
Classifying ISA’s
ISAs
Implement the following statement using an accumulator architecture
C = A + B assuming: A in address 100
B in address 101
C in address 102
Classifying ISA’s
ISAs
Implement the following statement using a
stack architecture
C = A + B assuming: A in address 100
B in address 101
C in address 102
SP = STACK POINTER
Alfonso Avila, ITESM Campus Monterrey
Classifying ISA’s
ISAs
Implement the following statement using an register-register or
load-store architecture
C = A + B assuming: A in address 100
B in address 101
C in address 102
Classifying ISA’s
ISAs
Implement the following statement using an memory-
memory architecture
C = A + B assuming: A in address 100
B in address 101
0
C in address 102
Classifying ISA’s
ISAs
Implicit operands vs explicit operands
# Operands
Architecture
A hit t I li it
Implicit E li it
Explicit
Stack
Accumulator
Register-memory
Register-register
eg s e eg s e
Alfonso Avila, ITESM Campus Monterrey
GPR vs SPR
General purpose registers (R0,R1,..RN) are used
instead of specific purpose registers
(Accumulator, B, etc.)
Di d t
Disadvantage
Source operand is destroyed in a binary operation
Clocks per instruction varies by operand type
Register number may be restricted due to encoding a register
and a memory address on each instruction
Alfonso Avila, ITESM Campus Monterrey
Disadvantage
Large variation on instruction size specially for
three operand instructions
Large variations in work per instruction
20%
in 8 bits 10%
5%
0%
75% to 80% fit
0
10
11
12
13
14
15
within 16 bits Number of bits needed for a displacement
Alfonso Avila, ITESM Campus Monterrey
Addressing summary
Important addressing modes are:
Displacement, immediate, register indirect
Displacement size:
12 bit displacement – 75%
16 bit and 32 bit - 99%
With displacement
The displacement
p is added to the PC
Useful for short jumps
Supports position independent coding
With register
It applies for indirect jumps and returns only known during program
execution
examples:
l switch,
wit h case, iin C
C; virtual
i t l ffunctions
ti en C++
Alfonso Avila, ITESM Campus Monterrey
Program Type
Instruction Tex Spice Gcc
Type
Call/Return 16% 13% 10%
Jump 18% 12% 12%
Conditional 66% 75% 78%
C diti l b
Conditional branches
h are more common
What is the condition most frequently tested?
Are the branches going forward or backward?
Alfonso Avila, ITESM Campus Monterrey
Program Type
Compare Tex Spice Gcc
Type
LT/GE 25% 0% 11%
GT/LE 3% 25% 0%
EQ/NE 72% 75% 89%
Immediate 83% 92% 84%
An average of 50% of the compares are simple
EQ or NE with the immediate value of 0 (zero)
Alfonso Avila, ITESM Campus Monterrey
dependent
Alfonso Avila, ITESM Campus Monterrey
Important branch
branch’ss property
Statistics obtained using benchmarks show:
Arithmetic subtract
sub ac sub $s1, $s2, $s3 $s1 = $s2 - $s3 Three
ee ope
operands;
a ds; da
data
a in registers
eg s e s
add immediate addi $s1, $s2, 100 $s1 = $s2 + 100 Used to add constants
load word lw $s1, 100($s2) $s1 = Memory[$s2 + 100] Word from memory to register
store word sw $s1, 100($s2) Memory[$s2 + 100] = $s1 Word from register to memory
Data transfer load byte lb $s1, 100($s2) $s1 = Memory[$s2 + 100] Byte from memory to register
store byte sb $s1,, 100($s2) Memory[$s2 + 100] = $s1 Byte from register to memory
load upper immediate lui $s1, 100 $s1 = 100 * 2
16 Loads constant in upper 16 bits
branch on equal beq $s1, $s2, 25 if ($s1 == $s2) go to Equal test; PC-relative branch
PC + 4 + 100
branch on not equal bne $s1, $s2, 25 if ($s1 != $s2) go to Not equal test; PC-relative
PC C + 4 + 100
00
Conditional
C diti l
branch set on less than slt $s1, $s2, $s3 if ($s2 < $s3) $s1 = 1; Compare less than; for beq, bne
else $s1 = 0
set less than slti $s1, $s2, 100 if ($s2 < 100) $s1 = 1; Compare less than constant
immediate else $s1 = 0
2. Register addressing
op rs rt rd ... funct Registers
R i t
Register
3. Base addressing
op rs rt Address Memory
4. PC-relative addressing
op rs rt Address Memory
PC + Word
5. Pseudodirect addressing
op Add
Address Memory
PC Word
Alfonso Avila, ITESM Campus Monterrey
Example:
C code: A=B+C
C code: A = B + C + D;
E = F - A;
.
Alfonso Avila, ITESM Campus Monterrey
.
Alfonso Avila, ITESM Campus Monterrey
1 8 bits of data
2 8 bits of data
3 8 bits of data
4 8 bits of data
5 8 bits of data
6 8 bits of data
...
Alfonso Avila, ITESM Campus Monterrey
0 32 bits of data
4 32 bits of data
8 32 bits of data
12 32 bits of data
...
C code: A[8]
[ ] = h + A[8];
[ ];
A[] start address in $s3; h value in $s2
MIPS code:
d lw $t0,
l $ 0 32($
32($s3)
3)
add $t0, $s2, $t0
sw $t0, 32($s3)
lui $1,
, 40 Load Upper
pp Immediate (
(16 bits
shifted left by 16)
Alfonso Avila, ITESM Campus Monterrey
Instruction Format:
op rs rt rd shamt funct
Wh do
What d the
h field
f ld names stand
d for?
f ?
Alfonso Avila, ITESM Campus Monterrey
35 18 9 32
op rs rt 16 bit number
Example: if (i = =j) h = i + j;
Example:
Formats:
op rs rt
t rd
d shamt
h t f
funct
t
R
op rs rt 16 bit address
I
op 26 bit address
J
Alfonso Avila, ITESM Campus Monterrey