SlideShare a Scribd company logo
Instruction Set Architecture
Instruction Set Architecture COE 308 – Computer Architecture – KFUPM
© Muhamed Mudawar – slide 2
Presentation Outline
 Instruction Set Architecture
 Overview of the MIPS Processor
 R-Type Arithmetic, Logical, and Shift Instructions
 I-Type Format and Immediate Constants
 Jump and Branch Instructions
 Translating If Statements and Boolean Expressions
 Load and Store Instructions
 Translating Loops and Traversing Arrays
 Alternative Architecture
Instruction Set Architecture COE 308 – Computer Architecture – KFUPM
© Muhamed Mudawar – slide 3
 Critical Interface between hardware and software
 An ISA includes the following …
 Instructions and Instruction Formats
 Data Types, Encodings, and Representations
 Programmable Storage: Registers and Memory
 Addressing Modes: to address Instructions and Data
 Handling Exceptional Conditions (like division by zero)
 Examples (Versions) First Introduced in
 Intel (8086, 80386, Pentium, ...) 1978
 MIPS (MIPS I, II, III, IV, V) 1986
 PowerPC (601, 604, …) 1993
Instruction Set Architecture (ISA)
Instruction Set Architecture COE 308 – Computer Architecture – KFUPM
© Muhamed Mudawar – slide 4
Instructions
 Instructions are the language of the machine
 We will study the MIPS instruction set architecture
 Known as Reduced Instruction Set Computer (RISC)
 Elegant and relatively simple design
 Similar to RISC architectures developed in mid-1980’s and 90’s
 Very popular, used in many products
 Silicon Graphics, ATI, Cisco, Sony, etc.
 Comes next in sales after Intel IA-32 processors
 Almost 100 million MIPS processors sold in 2002 (and increasing)
 Alternative design: Intel IA-32
 Known as Complex Instruction Set Computer (CISC)
Instruction Set Architecture COE 308 – Computer Architecture – KFUPM
© Muhamed Mudawar – slide 5
Basics of RISC Design
 All instructions are typically of one size
 Few instruction formats
 Arithmetic instructions are register to register
 Operands are read from registers
 Result is stored in a register
 General purpose integer and floating point registers
 Typically, 32 integer and 32 floating-point registers
 Memory access only via load and store instructions
 Load and store: bytes, half words, words, and double words
 Few simple addressing modes
Instruction Set Architecture COE 308 – Computer Architecture – KFUPM
© Muhamed Mudawar – slide 6
Next . . .
 Instruction Set Architecture
 Overview of the MIPS Processor
 R-Type Arithmetic, Logical, and Shift Instructions
 I-Type Format and Immediate Constants
 Jump and Branch Instructions
 Translating If Statements and Boolean Expressions
 Load and Store Instructions
 Translating Loops and Traversing Arrays
 Alternative Architecture
Instruction Set Architecture COE 308 – Computer Architecture – KFUPM
© Muhamed Mudawar – slide 7
Logical View of the MIPS Processor
Memory
Up to 232
bytes = 230
words
4 bytes per word
$0
$1
$2
$31
Hi Lo
ALU
$F0
$F1
$F2
$F31
FP
Arith
EPC
Cause
BadVaddr
Status
EIU FPU
TMU
Execution
&
Integer Unit
(Main proc)
Floating
Point Unit
(Coproc 1)
Trap &
Memory Unit
(Coproc 0)
. . .
. . .
Integer
mul/div
Arithmetic &
Logic Unit
32 General
Purpose
Registers
Integer
Multiplier/Divider
32 Floating-Point
Registers
Floating-Point
Arithmetic Unit
Instruction Set Architecture COE 308 – Computer Architecture – KFUPM
© Muhamed Mudawar – slide 8
 32 General Purpose Registers (GPRs)
 32-bit registers are used in MIPS32
 Register 0 is always zero
 Any value written to R0 is discarded
 Special-purpose registers LO and HI
 Hold results of integer multiply and divide
 Special-purpose program counter PC
 32 Floating Point Registers (FPRs)
 Floating Point registers can be either 32-bit or 64-bit
 A pair of registers is used for double-precision floating-point
Overview of the MIPS Registers
GPRs
$0 – $31
LO
HI
PC
FPRs
$F0 – $F31
Instruction Set Architecture COE 308 – Computer Architecture – KFUPM
© Muhamed Mudawar – slide 9
MIPS General-Purpose Registers
 32 General Purpose Registers (GPRs)
 Assembler uses the dollar notation to name registers
 $0 is register 0, $1 is register 1, …, and $31 is register 31
 All registers are 32-bit wide in MIPS32
 Register $0 is always zero
 Any value written to $0 is discarded
 Software conventions
 Software defines names to all registers
 To standardize their use in programs
 $8 - $15 are called $t0 - $t7
 Used for temporary values
 $16 - $23 are called $s0 - $s7
$0 = $zero
$1 = $at
$2 = $v0
$3 = $v1
$4 = $a0
$5 = $a1
$6 = $a2
$7 = $a3
$8 = $t0
$9 = $t1
$10 = $t2
$11 = $t3
$12 = $t4
$13 = $t5
$14 = $t6
$15 = $t7
$16 = $s0
$17 = $s1
$18 = $s2
$19 = $s3
$20 = $s4
$21 = $s5
$22 = $s6
$23 = $s7
$24 = $t8
$25 = $t9
$26 = $k0
$27 = $k1
$28 = $gp
$29 = $sp
$30 = $fp
$31 = $ra
Instruction Set Architecture COE 308 – Computer Architecture – KFUPM
© Muhamed Mudawar – slide 10
MIPS Register Conventions
Name Register Usage
$zero $0 Always 0 (forced by hardware)
$at $1 Reserved for assembler use
$v0 – $v1 $2 – $3 Result values of a function
$a0 – $a3 $4 – $7 Arguments of a function
$t0 – $t7 $8 – $15 Temporary Values
$s0 – $s7 $16 – $23 Saved registers (preserved across call)
$t8 – $t9 $24 – $25 More temporaries
$k0 – $k1 $26 – $27 Reserved for OS kernel
$gp $28 Global pointer (points to global data)
$sp $29 Stack pointer (points to top of stack)
$fp $30 Frame pointer (points to stack frame)
$ra $31 Return address (used by jal for function call)
 Assembler can refer to registers by name or by number
 It is easier for you to remember registers by name
 Assembler converts register name to its corresponding number
Instruction Set Architecture COE 308 – Computer Architecture – KFUPM
© Muhamed Mudawar – slide 11
Instruction Formats
 All instructions are 32-bit wide, Three instruction formats:
 Register (R-Type)
 Register-to-register instructions
 Op: operation code specifies the format of the instruction
 Immediate (I-Type)
 16-bit immediate constant is part in the instruction
 Jump (J-Type)
 Used by jump instructions
Op6
Rs5
Rt5
Rd5
funct6
sa5
Op6
Rs5
Rt5
immediate16
Op6
immediate26
Instruction Set Architecture COE 308 – Computer Architecture – KFUPM
© Muhamed Mudawar – slide 12
Instruction Categories
 Integer Arithmetic
 Arithmetic, logical, and shift instructions
 Data Transfer
 Load and store instructions that access memory
 Data movement and conversions
 Jump and Branch
 Flow-control instructions that alter the sequential sequence
 Floating Point Arithmetic
 Instructions that operate on floating-point registers
 Miscellaneous
 Instructions that transfer control to/from exception handlers
 Memory management instructions
Instruction Set Architecture COE 308 – Computer Architecture – KFUPM
© Muhamed Mudawar – slide 13
Next . . .
 Instruction Set Architecture
 Overview of the MIPS Processor
 R-Type Arithmetic, Logical, and Shift Instructions
 I-Type Format and Immediate Constants
 Jump and Branch Instructions
 Translating If Statements and Boolean Expressions
 Load and Store Instructions
 Translating Loops and Traversing Arrays
 Alternative Architecture
Instruction Set Architecture COE 308 – Computer Architecture – KFUPM
© Muhamed Mudawar – slide 14
R-Type Format
 Op: operation code (opcode)
 Specifies the operation of the instruction
 Also specifies the format of the instruction
 funct: function code – extends the opcode
 Up to 26
= 64 functions can be defined for the same opcode
 MIPS uses opcode 0 to define R-type instructions
 Three Register Operands (common to many instructions)
 Rs, Rt: first and second source operands
 Rd: destination operand
 sa: the shift amount used by shift instructions
Op6
Rs5
Rt5
Rd5
funct6
sa5
Instruction Set Architecture COE 308 – Computer Architecture – KFUPM
© Muhamed Mudawar – slide 15
Integer Add /Subtract Instructions
Instruction Meaning R-Type Format
add $s1, $s2, $s3 $s1 = $s2 + $s3 op = 0 rs = $s2 rt = $s3 rd = $s1 sa = 0 f = 0x20
addu $s1, $s2, $s3 $s1 = $s2 + $s3 op = 0 rs = $s2 rt = $s3 rd = $s1 sa = 0 f = 0x21
sub $s1, $s2, $s3 $s1 = $s2 – $s3 op = 0 rs = $s2 rt = $s3 rd = $s1 sa = 0 f = 0x22
subu $s1, $s2, $s3 $s1 = $s2 – $s3 op = 0 rs = $s2 rt = $s3 rd = $s1 sa = 0 f = 0x23
 add & sub: overflow causes an arithmetic exception
 In case of overflow, result is not written to destination register
 addu & subu: same operation as add & sub
 However, no arithmetic exception can occur
 Overflow is ignored
 Many programming languages ignore overflow
 The + operator is translated into addu
 The – operator is translated into subu
Instruction Set Architecture COE 308 – Computer Architecture – KFUPM
© Muhamed Mudawar – slide 16
Addition/Subtraction Example
 Consider the translation of: f = (g+h) – (i+j)
 Compiler allocates registers to variables
 Assume that f, g, h, i, and j are allocated registers $s0 thru $s4
 Called the saved registers: $s0 = $16, $s1 = $17, …, $s7 = $23
 Translation of: f = (g+h) – (i+j)
addu $t0, $s1, $s2 # $t0 = g + h
addu $t1, $s3, $s4 # $t1 = i + j
subu $s0, $t0, $t1 # f = (g+h)–(i+j)
 Temporary results are stored in $t0 = $8 and $t1 = $9
 Translate: addu $t0,$s1,$s2 to binary code
 Solution: 000000
op
10001
rs = $s1
10010
rt = $s2
01000
rd = $t0
00000
sa
100001
func
Instruction Set Architecture COE 308 – Computer Architecture – KFUPM
© Muhamed Mudawar – slide 17
Logical Bitwise Operations
 Logical bitwise operations: and, or, xor, nor
 AND instruction is used to clear bits: x and 0 = 0
 OR instruction is used to set bits: x or 1 = 1
 XOR instruction is used to toggle bits: x xor 1 = not x
 NOR instruction can be used as a NOT, how?
 nor $s1,$s2,$s2 is equivalent to not $s1,$s2
x
0
0
1
1
y
0
1
0
1
x and y
0
0
0
1
x
0
0
1
1
y
0
1
0
1
x or y
0
1
1
1
x
0
0
1
1
y
0
1
0
1
x xor y
0
1
1
0
x
0
0
1
1
y
0
1
0
1
x nor y
1
0
0
0
Instruction Set Architecture COE 308 – Computer Architecture – KFUPM
© Muhamed Mudawar – slide 18
Logical Bitwise Instructions
Instruction Meaning R-Type Format
and $s1, $s2, $s3 $s1 = $s2 & $s3 op = 0 rs = $s2 rt = $s3 rd = $s1 sa = 0 f = 0x24
or $s1, $s2, $s3 $s1 = $s2 | $s3 op = 0 rs = $s2 rt = $s3 rd = $s1 sa = 0 f = 0x25
xor $s1, $s2, $s3 $s1 = $s2 ^ $s3 op = 0 rs = $s2 rt = $s3 rd = $s1 sa = 0 f = 0x26
nor $s1, $s2, $s3 $s1 = ~($s2|$s3) op = 0 rs = $s2 rt = $s3 rd = $s1 sa = 0 f = 0x27
 Examples:
Assume $s1 = 0xabcd1234 and $s2 = 0xffff0000
and $s0,$s1,$s2 # $s0 = 0xabcd0000
or $s0,$s1,$s2 # $s0 = 0xffff1234
xor $s0,$s1,$s2 # $s0 = 0x54321234
nor $s0,$s1,$s2 # $s0 = 0x0000edcb
Instruction Set Architecture COE 308 – Computer Architecture – KFUPM
© Muhamed Mudawar – slide 19
Shift Operations
 Shifting is to move all the bits in a register left or right
 Shifts by a constant amount: sll, srl, sra
 sll/srl mean shift left/right logical by a constant amount
 The 5-bit shift amount field is used by these instructions
 sra means shift right arithmetic by a constant amount
 The sign-bit (rather than 0) is shifted from the left
shift-in 0
. . .
shift-out MSB
sll 32-bit register
. . .
shift-in 0 shift-out LSB
srl
. . .
shift-in sign-bit shift-out LSB
sra
Instruction Set Architecture COE 308 – Computer Architecture – KFUPM
© Muhamed Mudawar – slide 20
$s1 = 0x0000abcd
$s1 = 0xcd123400
Shift Instructions
Instruction Meaning R-Type Format
sll $s1,$s2,10 $s1 = $s2 << 10 op = 0 rs = 0 rt = $s2 rd = $s1 sa = 10 f = 0
srl $s1,$s2,10 $s1 = $s2>>>10 op = 0 rs = 0 rt = $s2 rd = $s1 sa = 10 f = 2
sra $s1, $s2, 10 $s1 = $s2 >> 10 op = 0 rs = 0 rt = $s2 rd = $s1 sa = 10 f = 3
sllv $s1,$s2,$s3 $s1 = $s2 << $s3 op = 0 rs = $s3 rt = $s2 rd = $s1 sa = 0 f = 4
srlv $s1,$s2,$s3 $s1 = $s2>>>$s3 op = 0 rs = $s3 rt = $s2 rd = $s1 sa = 0 f = 6
srav $s1,$s2,$s3 $s1 = $s2 >> $s3 op = 0 rs = $s3 rt = $s2 rd = $s1 sa = 0 f = 7
 Shifts by a variable amount: sllv, srlv, srav
 Same as sll, srl, sra, but a register is used for shift amount
 Examples: assume that $s2 = 0xabcd1234, $s3 = 16
sll $s1,$s2,8
sra $s1,$s2,4 $s1 = 0xfabcd123
srlv $s1,$s2,$s3
rt=$s2=10010
op=000000 rs=$s3=10011 rd=$s1=10001 sa=00000 f=000110
$s1 = $s2<<8
$s1 = $s2>>4
$s1 = $s2>>>$s3
Instruction Set Architecture COE 308 – Computer Architecture – KFUPM
© Muhamed Mudawar – slide 21
Binary Multiplication
 Shift-left (sll) instruction can perform multiplication
 When the multiplier is a power of 2
 You can factor any binary number into powers of 2
 Example: multiply $s1 by 36
 Factor 36 into (4 + 32) and use distributive property of multiplication
 $s2 = $s1*36 = $s1*(4 + 32) = $s1*4 + $s1*32
sll $t0, $s1, 2 ; $t0 = $s1 * 4
sll $t1, $s1, 5 ; $t1 = $s1 * 32
addu $s2, $t0, $t1 ; $s2 = $s1 * 36
Instruction Set Architecture COE 308 – Computer Architecture – KFUPM
© Muhamed Mudawar – slide 22
Your Turn . . .
sll $t0, $s1, 1 ; $t0 = $s1 * 2
sll $t1, $s1, 3 ; $t1 = $s1 * 8
addu $s2, $t0, $t1 ; $s2 = $s1 * 10
sll $t0, $s1, 4 ; $t0 = $s1 * 16
addu $s2, $s2, $t0 ; $s2 = $s1 * 26
Multiply $s1 by 26, using shift and add instructions
Hint: 26 = 2 + 8 + 16
Multiply $s1 by 31, Hint: 31 = 32 – 1
sll $s2, $s1, 5 ; $s2 = $s1 * 32
subu $s2, $s2, $s1 ; $s2 = $s1 * 31
Instruction Set Architecture COE 308 – Computer Architecture – KFUPM
© Muhamed Mudawar – slide 23
Integer Multiplication & Division
 Consider a×b and a/b where a and b are in $s1 and $s2
 Signed multiplication: mult $s1,$s2
 Unsigned multiplication: multu $s1,$s2
 Signed division: div $s1,$s2
 Unsigned division: divu $s1,$s2
 For multiplication, result is 64 bits
 LO = low-order 32-bit and HI = high-order 32-bit
 For division
 LO = 32-bit quotient and HI = 32-bit remainder
 If divisor is 0 then result is unpredictable
 Moving data
 mflo rd (move from LO to rd), mfhi rd (move from HI to rd)
 mtlo rs (move to LO from rs), mthi rs (move to HI from rs)
Multiply
Divide
$0
HI LO
$1
.
.
$31
Instruction Set Architecture COE 308 – Computer Architecture – KFUPM
© Muhamed Mudawar – slide 24
Integer Multiply/Divide Instructions
Instruction Meaning Format
mult rs, rt hi, lo = rs × rt op6
= 0 rs5
rt5
0 0 0x18
multu rs, rt hi, lo = rs × rt op6
= 0 rs5
rt5
0 0 0x19
div rs, rt hi, lo = rs / rt op6
= 0 rs5
rt5
0 0 0x1a
divu rs, rt hi, lo = rs / rt op6
= 0 rs5
rt5
0 0 0x1b
mfhi rd rd = hi op6
= 0 0 0 rd5
0 0x10
mflo rd rd = lo op6
= 0 0 0 rd5
0 0x12
mthi rs hi = rs op6
= 0 rs5
0 0 0 0x11
mtlo rs lo = rs op6
= 0 rs5
0 0 0 0x13
 Signed arithmetic: mult, div (rs and rt are signed)
 LO = 32-bit low-order and HI = 32-bit high-order of multiplication
 LO = 32-bit quotient and HI = 32-bit remainder of division
 Unsigned arithmetic: multu, divu (rs and rt are unsigned)
 NO arithmetic exception can occur
Instruction Set Architecture COE 308 – Computer Architecture – KFUPM
© Muhamed Mudawar – slide 25
Next . . .
 Instruction Set Architecture
 Overview of the MIPS Processor
 R-Type Arithmetic, Logical, and Shift Instructions
 I-Type Format and Immediate Constants
 Jump and Branch Instructions
 Translating If Statements and Boolean Expressions
 Load and Store Instructions
 Translating Loops and Traversing Arrays
 Alternative Architecture
Instruction Set Architecture COE 308 – Computer Architecture – KFUPM
© Muhamed Mudawar – slide 26
I-Type Format
 Constants are used quite frequently in programs
 The R-type shift instructions have a 5-bit shift amount constant
 What about other instructions that need a constant?
 I-Type: Instructions with Immediate Operands
 16-bit immediate constant is stored inside the instruction
 Rs is the source register number
 Rt is now the destination register number (for R-type it was Rd)
 Examples of I-Type ALU Instructions:
 Add immediate: addi $s1, $s2, 5 # $s1 = $s2 + 5
 OR immediate: ori $s1, $s2, 5 # $s1 = $s2 | 5
Op6
Rs5
Rt5
immediate16
Instruction Set Architecture COE 308 – Computer Architecture – KFUPM
© Muhamed Mudawar – slide 27
I-Type ALU Instructions
Instruction Meaning I-Type Format
addi $s1, $s2, 10 $s1 = $s2 + 10 op = 0x8 rs = $s2 rt = $s1 imm16
= 10
addiu $s1, $s2, 10 $s1 = $s2 + 10 op = 0x9 rs = $s2 rt = $s1 imm16
= 10
andi $s1, $s2, 10 $s1 = $s2 & 10 op = 0xc rs = $s2 rt = $s1 imm16
= 10
ori $s1, $s2, 10 $s1 = $s2 | 10 op = 0xd rs = $s2 rt = $s1 imm16
= 10
xori $s1, $s2, 10 $s1 = $s2 ^ 10 op = 0xe rs = $s2 rt = $s1 imm16
= 10
lui $s1, 10 $s1 = 10 << 16 op = 0xf 0 rt = $s1 imm16
= 10
 addi: overflow causes an arithmetic exception
 In case of overflow, result is not written to destination register
 addiu: same operation as addi but overflow is ignored
 Immediate constant for addi and addiu is signed
 No need for subi or subiu instructions
 Immediate constant for andi, ori, xori is unsigned
Instruction Set Architecture COE 308 – Computer Architecture – KFUPM
© Muhamed Mudawar – slide 28
 Examples: assume A, B, C are allocated $s0, $s1, $s2
 No need for subi, because addi has signed immediate
 Register 0 ($zero) has always the value 0
Examples: I-Type ALU Instructions
A = B+5; translated as
C = B–1; translated as
addiu $s0,$s1,5
addiu $s2,$s1,-1
A = B&0xf; translated as
C = B|0xf; translated as
andi $s0,$s1,0xf
ori $s2,$s1,0xf
C = 5; translated as
A = B; translated as
ori $s2,$zero,5
ori $s0,$s1,0
rt=$s2=10010
op=001001 rs=$s1=10001 imm = -1 = 1111111111111111
Instruction Set Architecture COE 308 – Computer Architecture – KFUPM
© Muhamed Mudawar – slide 29
 I-Type instructions can have only 16-bit constants
 What if we want to load a 32-bit constant into a register?
 Can’t have a 32-bit constant in I-Type instructions 
 We have already fixed the sizes of all instructions to 32 bits
 Solution: use two instructions instead of one 
 Suppose we want: $s1=0xAC5165D9 (32-bit constant)
 lui: load upper immediate
32-bit Constants
Op6
Rs5
Rt5
immediate16
lui $s1,0xAC51
ori $s1,$s1,0x65D9 0xAC51 0x65D9
$s1=$17
0xAC51 0x0000
$s1=$17
clear lower
16 bits
load upper
16 bits
Instruction Set Architecture COE 308 – Computer Architecture – KFUPM
© Muhamed Mudawar – slide 30
Next . . .
 Instruction Set Architecture
 Overview of the MIPS Processor
 R-Type Arithmetic, Logical, and Shift Instructions
 I-Type Format and Immediate Constants
 Jump and Branch Instructions
 Translating If Statements and Boolean Expressions
 Load and Store Instructions
 Translating Loops and Traversing Arrays
 Alternative Architecture
Instruction Set Architecture COE 308 – Computer Architecture – KFUPM
© Muhamed Mudawar – slide 31
J-Type Format
 J-type format is used for unconditional jump instruction:
j label # jump to label
. . .
label:
 26-bit immediate value is stored in the instruction
 Immediate constant specifies address of target instruction
 Program Counter (PC) is modified as follows:
 Next PC =
 Upper 4 most significant bits of PC are unchanged
Op6
immediate26
immediate26
PC4
00
least-significant
2 bits are 00
Instruction Set Architecture COE 308 – Computer Architecture – KFUPM
© Muhamed Mudawar – slide 32
 MIPS compare and branch instructions:
beq Rs,Rt,label branch to label if (Rs == Rt)
bne Rs,Rt,label branch to label if (Rs != Rt)
 MIPS compare to zero & branch instructions
Compare to zero is used frequently and implemented efficiently
bltz Rs,label branch to label if (Rs < 0)
bgtz Rs,label branch to label if (Rs > 0)
blez Rs,label branch to label if (Rs <= 0)
bgez Rs,label branch to label if (Rs >= 0)
 No need for beqz and bnez instructions. Why?
Conditional Branch Instructions
Instruction Set Architecture COE 308 – Computer Architecture – KFUPM
© Muhamed Mudawar – slide 33
Set on Less Than Instructions
 MIPS also provides set on less than instructions
slt rd,rs,rt if (rs < rt) rd = 1 else rd = 0
sltu rd,rs,rt unsigned <
slti rt,rs,im16
if (rs < im16
) rt = 1 else rt = 0
sltiu rt,rs,im16
unsigned <
 Signed / Unsigned Comparisons
Can produce different results
Assume $s0 = 1 and $s1 = -1 = 0xffffffff
slt $t0,$s0,$s1 results in $t0 = 0
stlu $t0,$s0,$s1 results in $t0 = 1
Instruction Set Architecture COE 308 – Computer Architecture – KFUPM
© Muhamed Mudawar – slide 34
More on Branch Instructions
 MIPS hardware does NOT provide instructions for …
blt, bltu branch if less than (signed/unsigned)
ble, bleu branch if less or equal (signed/unsigned)
bgt, bgtu branch if greater than (signed/unsigned)
bge, bgeu branch if greater or equal (signed/unsigned)
Can be achieved with a sequence of 2 instructions
 How to implement: blt $s0,$s1,label
 Solution: slt $at,$s0,$s1
bne $at,$zero,label
 How to implement: ble $s2,$s3,label
 Solution: slt $at,$s3,$s2
beq $at,$zero,label
Instruction Set Architecture COE 308 – Computer Architecture – KFUPM
© Muhamed Mudawar – slide 35
Pseudo-Instructions
 Introduced by assembler as if they were real instructions
 To facilitate assembly language programming
 Assembler reserves $at = $1 for its own use
 $at is called the assembler temporary register
ori $s1, $zero, 0xabcd
li $s1, 0xabcd
slt $s1, $s3, $s2
sgt $s1, $s2, $s3
nor $s1, $s2, $s2
not $s1, $s2
slt $at, $s1, $s2
bne $at, $zero, label
blt $s1, $s2, label
lui $s1, 0xabcd
ori $s1, $s1, 0x1234
li $s1, 0xabcd1234
addu Ss1, $s2, $zero
move $s1, $s2
Conversion to Real Instructions
Pseudo-Instructions
Instruction Set Architecture COE 308 – Computer Architecture – KFUPM
© Muhamed Mudawar – slide 36
Jump, Branch, and SLT Instructions
Instruction Meaning Format
j label jump to label op6
= 2 imm26
beq rs, rt, label branch if (rs == rt) op6
= 4 rs5
rt5
imm16
bne rs, rt, label branch if (rs != rt) op6
= 5 rs5
rt5
imm16
blez rs, label branch if (rs<=0) op6
= 6 rs5
0 imm16
bgtz rs, label branch if (rs > 0) op6
= 7 rs5
0 imm16
bltz rs, label branch if (rs < 0) op6
= 1 rs5
0 imm16
bgez rs, label branch if (rs>=0) op6
= 1 rs5
1 imm16
Instruction Meaning Format
slt rd, rs, rt rd=(rs<rt?1:0) op6
= 0 rs5
rt5
rd5
0 0x2a
sltu rd, rs, rt rd=(rs<rt?1:0) op6
= 0 rs5
rt5
rd5
0 0x2b
slti rt, rs, imm16
rt=(rs<imm?1:0) 0xa rs5
rt5
imm16
sltiu rt, rs, imm16 rt=(rs<imm?1:0) 0xb rs5
rt5
imm16
Instruction Set Architecture COE 308 – Computer Architecture – KFUPM
© Muhamed Mudawar – slide 37
Next . . .
 Instruction Set Architecture
 Overview of the MIPS Processor
 R-Type Arithmetic, Logical, and Shift Instructions
 I-Type Format and Immediate Constants
 Jump and Branch Instructions
 Translating If Statements and Boolean Expressions
 Load and Store Instructions
 Translating Loops and Traversing Arrays
 Alternative Architecture
Instruction Set Architecture COE 308 – Computer Architecture – KFUPM
© Muhamed Mudawar – slide 38
Translating an IF Statement
 Consider the following IF statement:
if (a == b) c = d + e; else c = d – e;
Assume that a, b, c, d, e are in $s0, …, $s4 respectively
 How to translate the above IF statement?
bne $s0, $s1, else
addu $s2, $s3, $s4
j exit
else: subu $s2, $s3, $s4
exit: . . .
Instruction Set Architecture COE 308 – Computer Architecture – KFUPM
© Muhamed Mudawar – slide 39
Compound Expression with AND
 Programming languages use short-circuit evaluation
 If first expression is false, second expression is skipped
if (($s1 > 0) && ($s2 < 0)) {$s3++;}
# One Possible Implementation ...
bgtz $s1, L1 # first expression
j next # skip if false
L1: bltz $s2, L2 # second expression
j next # skip if false
L2: addiu $s3,$s3,1 # both are true
next:
Instruction Set Architecture COE 308 – Computer Architecture – KFUPM
© Muhamed Mudawar – slide 40
Better Implementation for AND
The following implementation uses less code
Reverse the relational operator
Allow the program to fall through to the second expression
Number of instructions is reduced from 5 to 3
if (($s1 > 0) && ($s2 < 0)) {$s3++;}
# Better Implementation ...
blez $s1, next # skip if false
bgez $s2, next # skip if false
addiu $s3,$s3,1 # both are true
next:
Instruction Set Architecture COE 308 – Computer Architecture – KFUPM
© Muhamed Mudawar – slide 41
Compound Expression with OR
 Short-circuit evaluation for logical OR
 If first expression is true, second expression is skipped
 Use fall-through to keep the code as short as possible
 bgt, ble, and li are pseudo-instructions
 Translated by the assembler to real instructions
if (($sl > $s2) || ($s2 > $s3)) {$s4 = 1;}
bgt $s1, $s2, L1 # yes, execute if part
ble $s2, $s3, next # no: skip if part
L1: li $s4, 1 # set $s4 to 1
next:
Instruction Set Architecture COE 308 – Computer Architecture – KFUPM
© Muhamed Mudawar – slide 42
Your Turn . . .
 Translate the IF statement to assembly language
 $s1 and $s2 values are unsigned
 $s3, $s4, and $s5 values are signed
bgtu $s1, $s2, next
move $s3, $s4
next:
if( $s1 <= $s2 ) {
$s3 = $s4
}
if (($s3 <= $s4) &&
($s4 > $s5)) {
$s3 = $s4 + $s5
}
bgt $s3, $s4, next
ble $s4, $s5, next
addu $s3, $s4, $s5
next:
Instruction Set Architecture COE 308 – Computer Architecture – KFUPM
© Muhamed Mudawar – slide 43
Next . . .
 Instruction Set Architecture
 Overview of the MIPS Processor
 R-Type Arithmetic, Logical, and Shift Instructions
 I-Type Format and Immediate Constants
 Jump and Branch Instructions
 Translating If Statements and Boolean Expressions
 Load and Store Instructions
 Translating Loops and Traversing Arrays
 Alternative Architecture
Instruction Set Architecture COE 308 – Computer Architecture – KFUPM
© Muhamed Mudawar – slide 44
Load and Store Instructions
 Instructions that transfer data between memory & registers
 Programs include variables such as arrays and objects
 Such variables are stored in memory
 Load Instruction:
 Transfers data from memory to a register
 Store Instruction:
 Transfers data from a register to memory
 Memory address must be specified by load and store
Memory
Registers
load
store
Instruction Set Architecture COE 308 – Computer Architecture – KFUPM
© Muhamed Mudawar – slide 45
 Load Word Instruction (Word = 4 bytes in MIPS)
lw Rt, imm16
(Rs) # Rt = MEMORY[Rs+imm16
]
 Store Word Instruction
sw Rt, imm16
(Rs) # MEMORY[Rs+imm16
] = Rt
 Base or Displacement addressing is used
 Memory Address = Rs (base) + Immediate16
(displacement)
 Immediate16
is sign-extended to have a signed displacement
Load and Store Word
Op6
Rs5
Rt5
immediate16
Base or Displacement Addressing
Memory Word
Base address
+
Instruction Set Architecture COE 308 – Computer Architecture – KFUPM
© Muhamed Mudawar – slide 46
Example on Load & Store
 Translate A[1] = A[2] + 5 (A is an array of words)
 Assume that address of array A is stored in register $s0
lw $s1, 8($s0) # $s1 = A[2]
addiu $s2, $s1, 5 # $s2 = A[2] + 5
sw $s2, 4($s0) # A[1] = $s2
 Index of a[2] and a[1] should be multiplied by 4. Why?
sw
Memory
A[1]
A[0]
A[2]
A[3]
. . .
. . .
A+12
A+8
A+4
A
Registers
address of A
$s0 = $16
value of A[2]
$s1 = $17
A[2] + 5
$s2 = $18
. . .
. . .
lw
Instruction Set Architecture COE 308 – Computer Architecture – KFUPM
© Muhamed Mudawar – slide 47
0 0
s s s
s s
0 0
s
bu
b
h
hu
sign – extend
zero – extend
sign – extend
zero – extend
32-bit Register
 The MIPS processor supports the following data formats:
 Byte = 8 bits, Halfword = 16 bits, Word = 32 bits
 Load & store instructions for bytes and halfwords
 lb = load byte, lbu = load byte unsigned, sb = store byte
 lh = load half, lhu = load half unsigned, sh = store halfword
 Load expands a memory data to fit into a 32-bit register
 Store reduces a 32-bit register to fit in memory
Load and Store Byte and Halfword
Instruction Set Architecture COE 308 – Computer Architecture – KFUPM
© Muhamed Mudawar – slide 48
Load and Store Instructions
Instruction Meaning I-Type Format
lb rt, imm16
(rs) rt = MEM[rs+imm16
] 0x20 rs5
rt5
imm16
lh rt, imm16
(rs) rt = MEM[rs+imm16
] 0x21 rs5
rt5
imm16
lw rt, imm16
(rs) rt = MEM[rs+imm16
] 0x23 rs5
rt5
imm16
lbu rt, imm16
(rs) rt = MEM[rs+imm16
] 0x24 rs5
rt5
imm16
lhu rt, imm16
(rs) rt = MEM[rs+imm16
] 0x25 rs5
rt5
imm16
sb rt, imm16
(rs) MEM[rs+imm16
] = rt 0x28 rs5
rt5
imm16
sh rt, imm16
(rs) MEM[rs+imm16
] = rt 0x29 rs5
rt5
imm16
sw rt, imm16
(rs) MEM[rs+imm16
] = rt 0x2b rs5
rt5
imm16
 Base or Displacement Addressing is used
 Memory Address = Rs (base) + Immediate16
(displacement)
 Two variations on base addressing
 If Rs = $zero = 0 then Address = Immediate16
(absolute)
 If Immediate16
= 0 then Address = Rs (register indirect)
Instruction Set Architecture COE 308 – Computer Architecture – KFUPM
© Muhamed Mudawar – slide 49
Next . . .
 Instruction Set Architecture
 Overview of the MIPS Processor
 R-Type Arithmetic, Logical, and Shift Instructions
 I-Type Format and Immediate Constants
 Jump and Branch Instructions
 Translating If Statements and Boolean Expressions
 Load and Store Instructions
 Translating Loops and Traversing Arrays
 Alternative Architecture
Instruction Set Architecture COE 308 – Computer Architecture – KFUPM
© Muhamed Mudawar – slide 50
Translating a WHILE Loop
 Consider the following WHILE statement:
i = 0; while (A[i] != k) i = i+1;
Where A is an array of integers (4 bytes per element)
Assume address A, i, k in $s0, $s1, $s2, respectively
 How to translate above WHILE statement?
xor $s1, $s1, $s1 # i = 0
move $t0, $s0 # $t0 = address A
loop: lw $t1, 0($t0) # $t1 = A[i]
beq $t1, $s2, next # exit if (A[i]== k)
addiu $s1, $s1, 1 # i = i+1
sll $t0, $s1, 2 # $t0 = 4*i
addu $t0, $s0, $t0 # $t0 = address A[i]
j loop
next: . . .
Memory
A[2]
A[i]
A[1]
A[0]
. . .
. . .
A
A+4
A+8
A+4×i
. . .
Instruction Set Architecture COE 308 – Computer Architecture – KFUPM
© Muhamed Mudawar – slide 51
Using Pointers to Traverse Arrays
 Consider the same WHILE loop:
i = 0; while (A[i] != k) i = i+1;
Where address of A, i, k are in $s0, $s1, $s2, respectively
 We can use a pointer to traverse array A
Pointer is incremented by 4 (faster than indexing)
move $t0, $s0 # $t0 = $s0 = addr A
j cond # test condition
loop: addiu $s1, $s1, 1 # i = i+1
addiu $t0, $t0, 4 # point to next
cond: lw $t1, 0($t0) # $t1 = A[i]
bne $t1, $s2, loop # loop if A[i]!= k
 Only 4 instructions (rather than 6) in loop body
Instruction Set Architecture COE 308 – Computer Architecture – KFUPM
© Muhamed Mudawar – slide 52
Arrays vs. Pointers
 Array indexing involves
 Multiplying index by element size
 Using shift instruction when element size is a power of 2
 Adding to array base address
 Array version requires shift to be inside loop
 Part of index calculation for incremented i
 Pointers correspond directly to memory addresses
 Can avoid indexing complexity
 Induction variable elimination
 Less instructions and faster code
Instruction Set Architecture COE 308 – Computer Architecture – KFUPM
© Muhamed Mudawar – slide 53
Copying a String
move $t0, $s0 # $t0 = pointer to source
move $t1, $s1 # $t1 = pointer to target
L1: lb $t2, 0($t0) # load byte into $t2
sb $t2, 0($t1) # store byte into target
addiu $t0, $t0, 1 # increment source pointer
addiu $t1, $t1, 1 # increment target pointer
bne $t2, $zero, L1 # loop until NULL char
The following code copies source string to target string
Address of source in $s0 and address of target in $s1
Strings are terminated with a null character (C strings)
i = 0;
do {target[i]=source[i]; i++;} while (source[i]!=0);
Instruction Set Architecture COE 308 – Computer Architecture – KFUPM
© Muhamed Mudawar – slide 54
Summing an Integer Array
move $t0, $s0 # $t0 = address A[i]
xor $t1, $t1, $t1 # $t1 = i = 0
xor $s2, $s2, $s2 # $s2 = sum = 0
L1: lw $t2, 0($t0) # $t2 = A[i]
addu $s2, $s2, $t2 # sum = sum + A[i]
addiu $t0, $t0, 4 # point to next A[i]
addiu $t1, $t1, 1 # i++
bne $t1, $s1, L1 # loop if (i != n)
Assume $s0 = array address, $s1 = array length = n
sum = 0;
for (i=0; i<n; i++) sum = sum + A[i];
Instruction Set Architecture COE 308 – Computer Architecture – KFUPM
© Muhamed Mudawar – slide 55
Addressing Modes
Op6
Rs5
Rt5
immediate16
Base or Displacement Addressing
Word
Operand is in memory (load/store)
Register = Base address
+ Halfword
Op6
Rs5
Rt5
immediate16
Immediate Addressing
Operand is a constant
Op6
Rs5
Rt5
Rd5
funct6
sa5
Register Addressing
Register
Operand is in a register
 Where are the operands?
 How memory addresses are computed?
Instruction Set Architecture COE 308 – Computer Architecture – KFUPM
© Muhamed Mudawar – slide 56
Branch / Jump Addressing Modes
Used for branching (beq, bne, …)
Word = Target Instruction
Op6
Rs5
Rt5
immediate16
PC-Relative Addressing
PC30
00
+1
Target Instruction Address
PC = PC + 4 × (1 + immediate16
)
PC30
+ immediate16
+ 1 00
immediate26
PC4 00
Target Instruction Address
Word = Target Instruction
immediate26
Op6
Pseudo-direct Addressing
PC26
:
00
Used by jump instruction
PC4
Instruction Set Architecture COE 308 – Computer Architecture – KFUPM
© Muhamed Mudawar – slide 57
Jump and Branch Limits
 Jump Address Boundary = 226
instructions = 256 MB
 Text segment cannot exceed 226
instructions or 256 MB
 Upper 4 bits of PC are unchanged
 Branch Address Boundary
 Branch instructions use I-Type format (16-bit immediate constant)
 PC-relative addressing:
 Target instruction address = PC + 4×(1 + immediate16
)
 Count number of instructions to branch from next instruction
 Positive constant => Forward Branch, Negative => Backward branch
 At most ±215
instructions to branch (most branches are near)
immediate26
PC4 00
Target Instruction Address
PC30
+ immediate16
+ 1 00
Instruction Set Architecture COE 308 – Computer Architecture – KFUPM
© Muhamed Mudawar – slide 58
Next . . .
 Instruction Set Architecture
 Overview of the MIPS Processor
 R-Type Arithmetic, Logical, and Shift Instructions
 I-Type Format and Immediate Constants
 Jump and Branch Instructions
 Translating If Statements and Boolean Expressions
 Load and Store Instructions
 Translating Loops and Traversing Arrays
 Alternative Architecture
Instruction Set Architecture COE 308 – Computer Architecture – KFUPM
© Muhamed Mudawar – slide 59
Design alternative:
 Provide more complex instructions
 Goal is to reduce number of instructions executed
 Danger is a slower cycle time and/or a higher CPI
 Let’s look briefly at IA-32 (Intel Architecture - 32 bits)
 An architecture that is “difficult to explain and impossible to love”
 Developed by several independent groups
 Evolved over more than 20 years
 History illustrates impact of compatibility on the ISA
Alternative Architecture
Instruction Set Architecture COE 308 – Computer Architecture – KFUPM
© Muhamed Mudawar – slide 60
The Intel x86 ISA
Evolution with backward compatibility
 8080 (1974): 8-bit microprocessor
 Accumulator, plus 3 index-register pairs
 8086 (1978): 16-bit extension to 8080
 Complex instruction set (CISC)
 8087 (1980): floating-point coprocessor
 Adds FP instructions and register stack
 80286 (1982): 24-bit addresses, MMU
 Segmented memory mapping and protection
 80386 (1985): 32-bit extension (now IA-32)
 Additional addressing modes and operations
 Paged memory mapping as well as segments
Instruction Set Architecture COE 308 – Computer Architecture – KFUPM
© Muhamed Mudawar – slide 61
The Intel x86 ISA
Further evolution…
 i486 (1989): pipelined, on-chip caches and FPU
 Compatible competitors: AMD, Cyrix, …
 Pentium (1993): superscalar, 64-bit datapath
 Added MMX (Multi-Media eXtension) instructions
 The infamous FDIV bug
 Pentium Pro (1995), Pentium II (1997)
 New microarchitecture (see Colwell, The Pentium Chronicles)
 Pentium III (1999)
 Added SSE (Streaming SIMD Extensions) and registers
 Pentium 4 (2001)
 New microarchitecture
 Added SSE2 instructions
Instruction Set Architecture COE 308 – Computer Architecture – KFUPM
© Muhamed Mudawar – slide 62
The Intel x86 ISA
And further…
 AMD64 (2003): extended architecture to 64 bits
 EM64T – Extended Memory 64 Technology (2004)
 AMD64 adopted by Intel (with refinements)
 Added SSE3 instructions
 Intel Core (2006)
 Added SSE4 instructions, virtual machine support
 AMD64 (announced 2007): SSE5 instructions
 Intel declined to follow, instead…
 Advanced Vector Extension (announced 2008)
 Longer SSE registers, more instructions
Technical elegance ≠ market success
Instruction Set Architecture COE 308 – Computer Architecture – KFUPM
© Muhamed Mudawar – slide 63
Basic x86 Registers (IA-32)
Instruction Set Architecture COE 308 – Computer Architecture – KFUPM
© Muhamed Mudawar – slide 64
Typical IA-32 Instructions
 Data movement instructions
 MOV, PUSH, POP, LEA, …
 Arithmetic and logical instructions
 ADD, SUB, SHL, SHR, ROL, OR, XOR, INC, DEC, CMP, …
 Control flow instructions
 JMP, JZ, JNZ, CALL, RET, LOOP, …
 String instructions
 MOVS, LODS, …
 First operand is a source and destination
 Can be register or memory operand
 Second operand is a source
 Can be register, memory, or an immediate constant
Instruction Set Architecture COE 308 – Computer Architecture – KFUPM
© Muhamed Mudawar – slide 65
IA-32 Instruction Formats
 Complexity:
 Instruction formats from 1 to 17 bytes long
 One operand must act as both a source and destination
 One operand can come from memory
 Complex addressing modes
 Base or scaled index with 8 or 32 bit displacement
 Typical IA-32 Instruction Formats:
JE EIP + displacement
JE Displacement
Condi-
tion
4 4 8
CALL
CALL Offset
8 32
MOV EBX, [EDI + 45]
MOV w
d Displacement
r/m
Postbyte
6 8
1 1 8
PUSH ESI
PUSH Reg
5 3
ADD EAX, #6765
ADD w Immediate
Reg
4 32
3 1
TEST EDX, #42
Immediate
Postbyte
TEST w
7 32
1 8
Instruction Set Architecture COE 308 – Computer Architecture – KFUPM
© Muhamed Mudawar – slide 66
ARM & MIPS Similarities
ARM: the most popular embedded core
Similar basic set of instructions to MIPS
ARM MIPS
Date announced 1985 1985
Instruction size 32 bits 32 bits
Address space 32-bit flat 32-bit flat
Data alignment Aligned Aligned
Data addressing modes 9 3
Registers 15 × 32-bit 31 × 32-bit
Input/output Memory
mapped
Memory
mapped
Instruction Set Architecture COE 308 – Computer Architecture – KFUPM
© Muhamed Mudawar – slide 67
Compare and Branch in ARM
 Uses condition codes for the result of an arithmetic/logic
instruction
 Negative, zero, carry, overflow
 Compare instructions to set condition codes without keeping the
result
 Each instruction can be conditional
 Top 4 bits of instruction word: condition value
 Can avoid branches over single instructions
Instruction Set Architecture COE 308 – Computer Architecture – KFUPM
© Muhamed Mudawar – slide 68
Instruction Encoding
Instruction Set Architecture COE 308 – Computer Architecture – KFUPM
© Muhamed Mudawar – slide 69
Fallacies
Powerful instruction  higher performance
 Fewer instructions required
 But complex instructions are hard to implement
 May slow down all instructions, including simple ones
 Compilers are good at making fast code from simple
instructions
Use assembly code for high performance
 But modern compilers are better at dealing with
modern processors
 More lines of code  more errors and less productivity
Instruction Set Architecture COE 308 – Computer Architecture – KFUPM
© Muhamed Mudawar – slide 70
Fallacies
 Backward compatibility  instruction set doesn’t change
 But they do introduce more instructions
x86 instruction set
Instruction Set Architecture COE 308 – Computer Architecture – KFUPM
© Muhamed Mudawar – slide 71
Summary of Design Principles
1. Simplicity favors regularity
 Simple instructions dominate the instruction frequency
 So design them to be simple and regular, and make them fast
 Use general-purpose registers uniformly across instructions
 Fix the size of instructions (simplifies fetching & decoding)
 Fix the number of operands per instruction
 Three operands is the natural number for a typical instruction
2. Smaller is faster
 Limit the number of registers for faster access (typically 32)
3. Make the common case fast
 Include constants inside instructions (faster than loading them)
 Design most instructions to be register-to-register
4. Good design demands good compromises
 Smaller immediate constants in I-type instructions

More Related Content

PPT
insyruction set architecture-digital principles and computer organization
PPTX
06 mips-isa
PPT
f37-book-intarch-pres-pt2.ppt
PPT
f37-book-intarch-pres-pt2.ppt
PPTX
CSe_Cumilla Bangladesh_Country CSE CSE213_5.ppt
PPT
Lec18 Intro to Computer Engineering by Hsien-Hsin Sean Lee Georgia Tech -- In...
PPT
COMPUTER ARCHITECTURE MIPS INTRODUCTION ISA
PPTX
Instruction Set Architecture: MIPS
insyruction set architecture-digital principles and computer organization
06 mips-isa
f37-book-intarch-pres-pt2.ppt
f37-book-intarch-pres-pt2.ppt
CSe_Cumilla Bangladesh_Country CSE CSE213_5.ppt
Lec18 Intro to Computer Engineering by Hsien-Hsin Sean Lee Georgia Tech -- In...
COMPUTER ARCHITECTURE MIPS INTRODUCTION ISA
Instruction Set Architecture: MIPS

Similar to Digital principles and computer organisation -Instruction set architecture.ppt (20)

PPT
Assembly.ppt
PPTX
Unit 1 computer architecture_gghhhjjhbh.pptx
PPTX
11-risc-cisc-and-isa-w.pptx
PPT
MIPS instruction set microprocessor lecture notes
PPTX
Introduction to Computer Architecture: unit 1
PDF
ARM_InstructionSet.pdf; For VTU 22 regulation course code BCS402
PPTX
Introduction to Processor Design and ARM Processor
PPTX
Introduction to Computer Architecture
PDF
2. ALU and MIPS Arcitecture introduction.pdf
PPTX
Instruction Set Architecture
PPT
LECTURE2 td 2 sue les theories de graphes
PDF
CE412 -advanced computer Architecture lecture 1.pdf
PPTX
Basic Structure of a Computer System
PDF
Cmps290 classnoteschap02
PPTX
HDL17_MIPS CPU Design using Verilog.pptx
PPTX
mips processor with vlsi 32 bit architecture
PDF
digitaldesign-2020-lecture10a-lc3andmips-beforelecture.pdf
PDF
Architecture of 8085
PPTX
Computer Architecturebhhgggfggtggeerr.pptx
PDF
嵌入式系統 課程講義
Assembly.ppt
Unit 1 computer architecture_gghhhjjhbh.pptx
11-risc-cisc-and-isa-w.pptx
MIPS instruction set microprocessor lecture notes
Introduction to Computer Architecture: unit 1
ARM_InstructionSet.pdf; For VTU 22 regulation course code BCS402
Introduction to Processor Design and ARM Processor
Introduction to Computer Architecture
2. ALU and MIPS Arcitecture introduction.pdf
Instruction Set Architecture
LECTURE2 td 2 sue les theories de graphes
CE412 -advanced computer Architecture lecture 1.pdf
Basic Structure of a Computer System
Cmps290 classnoteschap02
HDL17_MIPS CPU Design using Verilog.pptx
mips processor with vlsi 32 bit architecture
digitaldesign-2020-lecture10a-lc3andmips-beforelecture.pdf
Architecture of 8085
Computer Architecturebhhgggfggtggeerr.pptx
嵌入式系統 課程講義
Ad

More from JemimaA1 (9)

PPTX
digitial crime studies in digital and mobile forensic subject.pptx
PPTX
5_Introduction_to_digital_forensics.pptx
PPTX
767659167-digital and mobile forensic laboratory THE-SLEUTH-KIT.pptx
PPT
Industrial Automation SEQUENTIAL FLOW CHARTSDL.ppt
PPTX
INTRODUCTION TO INDUSTRIAL AUTOMATION FULL SRM.pptx
PPT
Digital principles and computer organisation -Addressing modes.ppt
PPTX
UNIT-5 computer architecture and instruction set .pptx
PPT
Digital principles and computer organisation -dataHazard.ppt
PDF
23634082-INDUSTRIAL-AUTOMATION-CLASS-Notes.pdf
digitial crime studies in digital and mobile forensic subject.pptx
5_Introduction_to_digital_forensics.pptx
767659167-digital and mobile forensic laboratory THE-SLEUTH-KIT.pptx
Industrial Automation SEQUENTIAL FLOW CHARTSDL.ppt
INTRODUCTION TO INDUSTRIAL AUTOMATION FULL SRM.pptx
Digital principles and computer organisation -Addressing modes.ppt
UNIT-5 computer architecture and instruction set .pptx
Digital principles and computer organisation -dataHazard.ppt
23634082-INDUSTRIAL-AUTOMATION-CLASS-Notes.pdf
Ad

Recently uploaded (20)

PPTX
ANATOMY OF ANTERIOR CHAMBER ANGLE AND GONIOSCOPY.pptx
PDF
UNIT 1 Introduction fnfbbfhfhfbdhdbdto Java.pptx.pdf
PPTX
YV PROFILE PROJECTS PROFILE PRES. DESIGN
PDF
Wio LTE JP Version v1.3b- 4G, Cat.1, Espruino Compatible\202001935, PCBA;Wio ...
DOCX
The story of the first moon landing.docx
PPTX
areprosthodontics and orthodonticsa text.pptx
PPTX
DOC-20250430-WA0014._20250714_235747_0000.pptx
PDF
BRANDBOOK-Presidential Award Scheme-Kenya-2023
PDF
Facade & Landscape Lighting Techniques and Trends.pptx.pdf
PDF
GREEN BUILDING MATERIALS FOR SUISTAINABLE ARCHITECTURE AND BUILDING STUDY
PPTX
Implications Existing phase plan and its feasibility.pptx
PPT
unit 1 ppt.ppthhhhhhhhhhhhhhhhhhhhhhhhhh
PPT
pump pump is a mechanism that is used to transfer a liquid from one place to ...
PPTX
AC-Unit1.pptx CRYPTOGRAPHIC NNNNFOR ALL
PDF
Key Trends in Website Development 2025 | B3AITS - Bow & 3 Arrows IT Solutions
PPTX
Causes of Flooding by Slidesgo sdnl;asnjdl;asj.pptx
PDF
High-frequency high-voltage transformer outline drawing
PPTX
12. Community Pharmacy and How to organize it
PDF
Integrated-2D-and-3D-Animation-Bridging-Dimensions-for-Impactful-Storytelling...
PDF
Benefits_of_Cast_Aluminium_Doors_Presentation.pdf
ANATOMY OF ANTERIOR CHAMBER ANGLE AND GONIOSCOPY.pptx
UNIT 1 Introduction fnfbbfhfhfbdhdbdto Java.pptx.pdf
YV PROFILE PROJECTS PROFILE PRES. DESIGN
Wio LTE JP Version v1.3b- 4G, Cat.1, Espruino Compatible\202001935, PCBA;Wio ...
The story of the first moon landing.docx
areprosthodontics and orthodonticsa text.pptx
DOC-20250430-WA0014._20250714_235747_0000.pptx
BRANDBOOK-Presidential Award Scheme-Kenya-2023
Facade & Landscape Lighting Techniques and Trends.pptx.pdf
GREEN BUILDING MATERIALS FOR SUISTAINABLE ARCHITECTURE AND BUILDING STUDY
Implications Existing phase plan and its feasibility.pptx
unit 1 ppt.ppthhhhhhhhhhhhhhhhhhhhhhhhhh
pump pump is a mechanism that is used to transfer a liquid from one place to ...
AC-Unit1.pptx CRYPTOGRAPHIC NNNNFOR ALL
Key Trends in Website Development 2025 | B3AITS - Bow & 3 Arrows IT Solutions
Causes of Flooding by Slidesgo sdnl;asnjdl;asj.pptx
High-frequency high-voltage transformer outline drawing
12. Community Pharmacy and How to organize it
Integrated-2D-and-3D-Animation-Bridging-Dimensions-for-Impactful-Storytelling...
Benefits_of_Cast_Aluminium_Doors_Presentation.pdf

Digital principles and computer organisation -Instruction set architecture.ppt

  • 2. Instruction Set Architecture COE 308 – Computer Architecture – KFUPM © Muhamed Mudawar – slide 2 Presentation Outline  Instruction Set Architecture  Overview of the MIPS Processor  R-Type Arithmetic, Logical, and Shift Instructions  I-Type Format and Immediate Constants  Jump and Branch Instructions  Translating If Statements and Boolean Expressions  Load and Store Instructions  Translating Loops and Traversing Arrays  Alternative Architecture
  • 3. Instruction Set Architecture COE 308 – Computer Architecture – KFUPM © Muhamed Mudawar – slide 3  Critical Interface between hardware and software  An ISA includes the following …  Instructions and Instruction Formats  Data Types, Encodings, and Representations  Programmable Storage: Registers and Memory  Addressing Modes: to address Instructions and Data  Handling Exceptional Conditions (like division by zero)  Examples (Versions) First Introduced in  Intel (8086, 80386, Pentium, ...) 1978  MIPS (MIPS I, II, III, IV, V) 1986  PowerPC (601, 604, …) 1993 Instruction Set Architecture (ISA)
  • 4. Instruction Set Architecture COE 308 – Computer Architecture – KFUPM © Muhamed Mudawar – slide 4 Instructions  Instructions are the language of the machine  We will study the MIPS instruction set architecture  Known as Reduced Instruction Set Computer (RISC)  Elegant and relatively simple design  Similar to RISC architectures developed in mid-1980’s and 90’s  Very popular, used in many products  Silicon Graphics, ATI, Cisco, Sony, etc.  Comes next in sales after Intel IA-32 processors  Almost 100 million MIPS processors sold in 2002 (and increasing)  Alternative design: Intel IA-32  Known as Complex Instruction Set Computer (CISC)
  • 5. Instruction Set Architecture COE 308 – Computer Architecture – KFUPM © Muhamed Mudawar – slide 5 Basics of RISC Design  All instructions are typically of one size  Few instruction formats  Arithmetic instructions are register to register  Operands are read from registers  Result is stored in a register  General purpose integer and floating point registers  Typically, 32 integer and 32 floating-point registers  Memory access only via load and store instructions  Load and store: bytes, half words, words, and double words  Few simple addressing modes
  • 6. Instruction Set Architecture COE 308 – Computer Architecture – KFUPM © Muhamed Mudawar – slide 6 Next . . .  Instruction Set Architecture  Overview of the MIPS Processor  R-Type Arithmetic, Logical, and Shift Instructions  I-Type Format and Immediate Constants  Jump and Branch Instructions  Translating If Statements and Boolean Expressions  Load and Store Instructions  Translating Loops and Traversing Arrays  Alternative Architecture
  • 7. Instruction Set Architecture COE 308 – Computer Architecture – KFUPM © Muhamed Mudawar – slide 7 Logical View of the MIPS Processor Memory Up to 232 bytes = 230 words 4 bytes per word $0 $1 $2 $31 Hi Lo ALU $F0 $F1 $F2 $F31 FP Arith EPC Cause BadVaddr Status EIU FPU TMU Execution & Integer Unit (Main proc) Floating Point Unit (Coproc 1) Trap & Memory Unit (Coproc 0) . . . . . . Integer mul/div Arithmetic & Logic Unit 32 General Purpose Registers Integer Multiplier/Divider 32 Floating-Point Registers Floating-Point Arithmetic Unit
  • 8. Instruction Set Architecture COE 308 – Computer Architecture – KFUPM © Muhamed Mudawar – slide 8  32 General Purpose Registers (GPRs)  32-bit registers are used in MIPS32  Register 0 is always zero  Any value written to R0 is discarded  Special-purpose registers LO and HI  Hold results of integer multiply and divide  Special-purpose program counter PC  32 Floating Point Registers (FPRs)  Floating Point registers can be either 32-bit or 64-bit  A pair of registers is used for double-precision floating-point Overview of the MIPS Registers GPRs $0 – $31 LO HI PC FPRs $F0 – $F31
  • 9. Instruction Set Architecture COE 308 – Computer Architecture – KFUPM © Muhamed Mudawar – slide 9 MIPS General-Purpose Registers  32 General Purpose Registers (GPRs)  Assembler uses the dollar notation to name registers  $0 is register 0, $1 is register 1, …, and $31 is register 31  All registers are 32-bit wide in MIPS32  Register $0 is always zero  Any value written to $0 is discarded  Software conventions  Software defines names to all registers  To standardize their use in programs  $8 - $15 are called $t0 - $t7  Used for temporary values  $16 - $23 are called $s0 - $s7 $0 = $zero $1 = $at $2 = $v0 $3 = $v1 $4 = $a0 $5 = $a1 $6 = $a2 $7 = $a3 $8 = $t0 $9 = $t1 $10 = $t2 $11 = $t3 $12 = $t4 $13 = $t5 $14 = $t6 $15 = $t7 $16 = $s0 $17 = $s1 $18 = $s2 $19 = $s3 $20 = $s4 $21 = $s5 $22 = $s6 $23 = $s7 $24 = $t8 $25 = $t9 $26 = $k0 $27 = $k1 $28 = $gp $29 = $sp $30 = $fp $31 = $ra
  • 10. Instruction Set Architecture COE 308 – Computer Architecture – KFUPM © Muhamed Mudawar – slide 10 MIPS Register Conventions Name Register Usage $zero $0 Always 0 (forced by hardware) $at $1 Reserved for assembler use $v0 – $v1 $2 – $3 Result values of a function $a0 – $a3 $4 – $7 Arguments of a function $t0 – $t7 $8 – $15 Temporary Values $s0 – $s7 $16 – $23 Saved registers (preserved across call) $t8 – $t9 $24 – $25 More temporaries $k0 – $k1 $26 – $27 Reserved for OS kernel $gp $28 Global pointer (points to global data) $sp $29 Stack pointer (points to top of stack) $fp $30 Frame pointer (points to stack frame) $ra $31 Return address (used by jal for function call)  Assembler can refer to registers by name or by number  It is easier for you to remember registers by name  Assembler converts register name to its corresponding number
  • 11. Instruction Set Architecture COE 308 – Computer Architecture – KFUPM © Muhamed Mudawar – slide 11 Instruction Formats  All instructions are 32-bit wide, Three instruction formats:  Register (R-Type)  Register-to-register instructions  Op: operation code specifies the format of the instruction  Immediate (I-Type)  16-bit immediate constant is part in the instruction  Jump (J-Type)  Used by jump instructions Op6 Rs5 Rt5 Rd5 funct6 sa5 Op6 Rs5 Rt5 immediate16 Op6 immediate26
  • 12. Instruction Set Architecture COE 308 – Computer Architecture – KFUPM © Muhamed Mudawar – slide 12 Instruction Categories  Integer Arithmetic  Arithmetic, logical, and shift instructions  Data Transfer  Load and store instructions that access memory  Data movement and conversions  Jump and Branch  Flow-control instructions that alter the sequential sequence  Floating Point Arithmetic  Instructions that operate on floating-point registers  Miscellaneous  Instructions that transfer control to/from exception handlers  Memory management instructions
  • 13. Instruction Set Architecture COE 308 – Computer Architecture – KFUPM © Muhamed Mudawar – slide 13 Next . . .  Instruction Set Architecture  Overview of the MIPS Processor  R-Type Arithmetic, Logical, and Shift Instructions  I-Type Format and Immediate Constants  Jump and Branch Instructions  Translating If Statements and Boolean Expressions  Load and Store Instructions  Translating Loops and Traversing Arrays  Alternative Architecture
  • 14. Instruction Set Architecture COE 308 – Computer Architecture – KFUPM © Muhamed Mudawar – slide 14 R-Type Format  Op: operation code (opcode)  Specifies the operation of the instruction  Also specifies the format of the instruction  funct: function code – extends the opcode  Up to 26 = 64 functions can be defined for the same opcode  MIPS uses opcode 0 to define R-type instructions  Three Register Operands (common to many instructions)  Rs, Rt: first and second source operands  Rd: destination operand  sa: the shift amount used by shift instructions Op6 Rs5 Rt5 Rd5 funct6 sa5
  • 15. Instruction Set Architecture COE 308 – Computer Architecture – KFUPM © Muhamed Mudawar – slide 15 Integer Add /Subtract Instructions Instruction Meaning R-Type Format add $s1, $s2, $s3 $s1 = $s2 + $s3 op = 0 rs = $s2 rt = $s3 rd = $s1 sa = 0 f = 0x20 addu $s1, $s2, $s3 $s1 = $s2 + $s3 op = 0 rs = $s2 rt = $s3 rd = $s1 sa = 0 f = 0x21 sub $s1, $s2, $s3 $s1 = $s2 – $s3 op = 0 rs = $s2 rt = $s3 rd = $s1 sa = 0 f = 0x22 subu $s1, $s2, $s3 $s1 = $s2 – $s3 op = 0 rs = $s2 rt = $s3 rd = $s1 sa = 0 f = 0x23  add & sub: overflow causes an arithmetic exception  In case of overflow, result is not written to destination register  addu & subu: same operation as add & sub  However, no arithmetic exception can occur  Overflow is ignored  Many programming languages ignore overflow  The + operator is translated into addu  The – operator is translated into subu
  • 16. Instruction Set Architecture COE 308 – Computer Architecture – KFUPM © Muhamed Mudawar – slide 16 Addition/Subtraction Example  Consider the translation of: f = (g+h) – (i+j)  Compiler allocates registers to variables  Assume that f, g, h, i, and j are allocated registers $s0 thru $s4  Called the saved registers: $s0 = $16, $s1 = $17, …, $s7 = $23  Translation of: f = (g+h) – (i+j) addu $t0, $s1, $s2 # $t0 = g + h addu $t1, $s3, $s4 # $t1 = i + j subu $s0, $t0, $t1 # f = (g+h)–(i+j)  Temporary results are stored in $t0 = $8 and $t1 = $9  Translate: addu $t0,$s1,$s2 to binary code  Solution: 000000 op 10001 rs = $s1 10010 rt = $s2 01000 rd = $t0 00000 sa 100001 func
  • 17. Instruction Set Architecture COE 308 – Computer Architecture – KFUPM © Muhamed Mudawar – slide 17 Logical Bitwise Operations  Logical bitwise operations: and, or, xor, nor  AND instruction is used to clear bits: x and 0 = 0  OR instruction is used to set bits: x or 1 = 1  XOR instruction is used to toggle bits: x xor 1 = not x  NOR instruction can be used as a NOT, how?  nor $s1,$s2,$s2 is equivalent to not $s1,$s2 x 0 0 1 1 y 0 1 0 1 x and y 0 0 0 1 x 0 0 1 1 y 0 1 0 1 x or y 0 1 1 1 x 0 0 1 1 y 0 1 0 1 x xor y 0 1 1 0 x 0 0 1 1 y 0 1 0 1 x nor y 1 0 0 0
  • 18. Instruction Set Architecture COE 308 – Computer Architecture – KFUPM © Muhamed Mudawar – slide 18 Logical Bitwise Instructions Instruction Meaning R-Type Format and $s1, $s2, $s3 $s1 = $s2 & $s3 op = 0 rs = $s2 rt = $s3 rd = $s1 sa = 0 f = 0x24 or $s1, $s2, $s3 $s1 = $s2 | $s3 op = 0 rs = $s2 rt = $s3 rd = $s1 sa = 0 f = 0x25 xor $s1, $s2, $s3 $s1 = $s2 ^ $s3 op = 0 rs = $s2 rt = $s3 rd = $s1 sa = 0 f = 0x26 nor $s1, $s2, $s3 $s1 = ~($s2|$s3) op = 0 rs = $s2 rt = $s3 rd = $s1 sa = 0 f = 0x27  Examples: Assume $s1 = 0xabcd1234 and $s2 = 0xffff0000 and $s0,$s1,$s2 # $s0 = 0xabcd0000 or $s0,$s1,$s2 # $s0 = 0xffff1234 xor $s0,$s1,$s2 # $s0 = 0x54321234 nor $s0,$s1,$s2 # $s0 = 0x0000edcb
  • 19. Instruction Set Architecture COE 308 – Computer Architecture – KFUPM © Muhamed Mudawar – slide 19 Shift Operations  Shifting is to move all the bits in a register left or right  Shifts by a constant amount: sll, srl, sra  sll/srl mean shift left/right logical by a constant amount  The 5-bit shift amount field is used by these instructions  sra means shift right arithmetic by a constant amount  The sign-bit (rather than 0) is shifted from the left shift-in 0 . . . shift-out MSB sll 32-bit register . . . shift-in 0 shift-out LSB srl . . . shift-in sign-bit shift-out LSB sra
  • 20. Instruction Set Architecture COE 308 – Computer Architecture – KFUPM © Muhamed Mudawar – slide 20 $s1 = 0x0000abcd $s1 = 0xcd123400 Shift Instructions Instruction Meaning R-Type Format sll $s1,$s2,10 $s1 = $s2 << 10 op = 0 rs = 0 rt = $s2 rd = $s1 sa = 10 f = 0 srl $s1,$s2,10 $s1 = $s2>>>10 op = 0 rs = 0 rt = $s2 rd = $s1 sa = 10 f = 2 sra $s1, $s2, 10 $s1 = $s2 >> 10 op = 0 rs = 0 rt = $s2 rd = $s1 sa = 10 f = 3 sllv $s1,$s2,$s3 $s1 = $s2 << $s3 op = 0 rs = $s3 rt = $s2 rd = $s1 sa = 0 f = 4 srlv $s1,$s2,$s3 $s1 = $s2>>>$s3 op = 0 rs = $s3 rt = $s2 rd = $s1 sa = 0 f = 6 srav $s1,$s2,$s3 $s1 = $s2 >> $s3 op = 0 rs = $s3 rt = $s2 rd = $s1 sa = 0 f = 7  Shifts by a variable amount: sllv, srlv, srav  Same as sll, srl, sra, but a register is used for shift amount  Examples: assume that $s2 = 0xabcd1234, $s3 = 16 sll $s1,$s2,8 sra $s1,$s2,4 $s1 = 0xfabcd123 srlv $s1,$s2,$s3 rt=$s2=10010 op=000000 rs=$s3=10011 rd=$s1=10001 sa=00000 f=000110 $s1 = $s2<<8 $s1 = $s2>>4 $s1 = $s2>>>$s3
  • 21. Instruction Set Architecture COE 308 – Computer Architecture – KFUPM © Muhamed Mudawar – slide 21 Binary Multiplication  Shift-left (sll) instruction can perform multiplication  When the multiplier is a power of 2  You can factor any binary number into powers of 2  Example: multiply $s1 by 36  Factor 36 into (4 + 32) and use distributive property of multiplication  $s2 = $s1*36 = $s1*(4 + 32) = $s1*4 + $s1*32 sll $t0, $s1, 2 ; $t0 = $s1 * 4 sll $t1, $s1, 5 ; $t1 = $s1 * 32 addu $s2, $t0, $t1 ; $s2 = $s1 * 36
  • 22. Instruction Set Architecture COE 308 – Computer Architecture – KFUPM © Muhamed Mudawar – slide 22 Your Turn . . . sll $t0, $s1, 1 ; $t0 = $s1 * 2 sll $t1, $s1, 3 ; $t1 = $s1 * 8 addu $s2, $t0, $t1 ; $s2 = $s1 * 10 sll $t0, $s1, 4 ; $t0 = $s1 * 16 addu $s2, $s2, $t0 ; $s2 = $s1 * 26 Multiply $s1 by 26, using shift and add instructions Hint: 26 = 2 + 8 + 16 Multiply $s1 by 31, Hint: 31 = 32 – 1 sll $s2, $s1, 5 ; $s2 = $s1 * 32 subu $s2, $s2, $s1 ; $s2 = $s1 * 31
  • 23. Instruction Set Architecture COE 308 – Computer Architecture – KFUPM © Muhamed Mudawar – slide 23 Integer Multiplication & Division  Consider a×b and a/b where a and b are in $s1 and $s2  Signed multiplication: mult $s1,$s2  Unsigned multiplication: multu $s1,$s2  Signed division: div $s1,$s2  Unsigned division: divu $s1,$s2  For multiplication, result is 64 bits  LO = low-order 32-bit and HI = high-order 32-bit  For division  LO = 32-bit quotient and HI = 32-bit remainder  If divisor is 0 then result is unpredictable  Moving data  mflo rd (move from LO to rd), mfhi rd (move from HI to rd)  mtlo rs (move to LO from rs), mthi rs (move to HI from rs) Multiply Divide $0 HI LO $1 . . $31
  • 24. Instruction Set Architecture COE 308 – Computer Architecture – KFUPM © Muhamed Mudawar – slide 24 Integer Multiply/Divide Instructions Instruction Meaning Format mult rs, rt hi, lo = rs × rt op6 = 0 rs5 rt5 0 0 0x18 multu rs, rt hi, lo = rs × rt op6 = 0 rs5 rt5 0 0 0x19 div rs, rt hi, lo = rs / rt op6 = 0 rs5 rt5 0 0 0x1a divu rs, rt hi, lo = rs / rt op6 = 0 rs5 rt5 0 0 0x1b mfhi rd rd = hi op6 = 0 0 0 rd5 0 0x10 mflo rd rd = lo op6 = 0 0 0 rd5 0 0x12 mthi rs hi = rs op6 = 0 rs5 0 0 0 0x11 mtlo rs lo = rs op6 = 0 rs5 0 0 0 0x13  Signed arithmetic: mult, div (rs and rt are signed)  LO = 32-bit low-order and HI = 32-bit high-order of multiplication  LO = 32-bit quotient and HI = 32-bit remainder of division  Unsigned arithmetic: multu, divu (rs and rt are unsigned)  NO arithmetic exception can occur
  • 25. Instruction Set Architecture COE 308 – Computer Architecture – KFUPM © Muhamed Mudawar – slide 25 Next . . .  Instruction Set Architecture  Overview of the MIPS Processor  R-Type Arithmetic, Logical, and Shift Instructions  I-Type Format and Immediate Constants  Jump and Branch Instructions  Translating If Statements and Boolean Expressions  Load and Store Instructions  Translating Loops and Traversing Arrays  Alternative Architecture
  • 26. Instruction Set Architecture COE 308 – Computer Architecture – KFUPM © Muhamed Mudawar – slide 26 I-Type Format  Constants are used quite frequently in programs  The R-type shift instructions have a 5-bit shift amount constant  What about other instructions that need a constant?  I-Type: Instructions with Immediate Operands  16-bit immediate constant is stored inside the instruction  Rs is the source register number  Rt is now the destination register number (for R-type it was Rd)  Examples of I-Type ALU Instructions:  Add immediate: addi $s1, $s2, 5 # $s1 = $s2 + 5  OR immediate: ori $s1, $s2, 5 # $s1 = $s2 | 5 Op6 Rs5 Rt5 immediate16
  • 27. Instruction Set Architecture COE 308 – Computer Architecture – KFUPM © Muhamed Mudawar – slide 27 I-Type ALU Instructions Instruction Meaning I-Type Format addi $s1, $s2, 10 $s1 = $s2 + 10 op = 0x8 rs = $s2 rt = $s1 imm16 = 10 addiu $s1, $s2, 10 $s1 = $s2 + 10 op = 0x9 rs = $s2 rt = $s1 imm16 = 10 andi $s1, $s2, 10 $s1 = $s2 & 10 op = 0xc rs = $s2 rt = $s1 imm16 = 10 ori $s1, $s2, 10 $s1 = $s2 | 10 op = 0xd rs = $s2 rt = $s1 imm16 = 10 xori $s1, $s2, 10 $s1 = $s2 ^ 10 op = 0xe rs = $s2 rt = $s1 imm16 = 10 lui $s1, 10 $s1 = 10 << 16 op = 0xf 0 rt = $s1 imm16 = 10  addi: overflow causes an arithmetic exception  In case of overflow, result is not written to destination register  addiu: same operation as addi but overflow is ignored  Immediate constant for addi and addiu is signed  No need for subi or subiu instructions  Immediate constant for andi, ori, xori is unsigned
  • 28. Instruction Set Architecture COE 308 – Computer Architecture – KFUPM © Muhamed Mudawar – slide 28  Examples: assume A, B, C are allocated $s0, $s1, $s2  No need for subi, because addi has signed immediate  Register 0 ($zero) has always the value 0 Examples: I-Type ALU Instructions A = B+5; translated as C = B–1; translated as addiu $s0,$s1,5 addiu $s2,$s1,-1 A = B&0xf; translated as C = B|0xf; translated as andi $s0,$s1,0xf ori $s2,$s1,0xf C = 5; translated as A = B; translated as ori $s2,$zero,5 ori $s0,$s1,0 rt=$s2=10010 op=001001 rs=$s1=10001 imm = -1 = 1111111111111111
  • 29. Instruction Set Architecture COE 308 – Computer Architecture – KFUPM © Muhamed Mudawar – slide 29  I-Type instructions can have only 16-bit constants  What if we want to load a 32-bit constant into a register?  Can’t have a 32-bit constant in I-Type instructions   We have already fixed the sizes of all instructions to 32 bits  Solution: use two instructions instead of one   Suppose we want: $s1=0xAC5165D9 (32-bit constant)  lui: load upper immediate 32-bit Constants Op6 Rs5 Rt5 immediate16 lui $s1,0xAC51 ori $s1,$s1,0x65D9 0xAC51 0x65D9 $s1=$17 0xAC51 0x0000 $s1=$17 clear lower 16 bits load upper 16 bits
  • 30. Instruction Set Architecture COE 308 – Computer Architecture – KFUPM © Muhamed Mudawar – slide 30 Next . . .  Instruction Set Architecture  Overview of the MIPS Processor  R-Type Arithmetic, Logical, and Shift Instructions  I-Type Format and Immediate Constants  Jump and Branch Instructions  Translating If Statements and Boolean Expressions  Load and Store Instructions  Translating Loops and Traversing Arrays  Alternative Architecture
  • 31. Instruction Set Architecture COE 308 – Computer Architecture – KFUPM © Muhamed Mudawar – slide 31 J-Type Format  J-type format is used for unconditional jump instruction: j label # jump to label . . . label:  26-bit immediate value is stored in the instruction  Immediate constant specifies address of target instruction  Program Counter (PC) is modified as follows:  Next PC =  Upper 4 most significant bits of PC are unchanged Op6 immediate26 immediate26 PC4 00 least-significant 2 bits are 00
  • 32. Instruction Set Architecture COE 308 – Computer Architecture – KFUPM © Muhamed Mudawar – slide 32  MIPS compare and branch instructions: beq Rs,Rt,label branch to label if (Rs == Rt) bne Rs,Rt,label branch to label if (Rs != Rt)  MIPS compare to zero & branch instructions Compare to zero is used frequently and implemented efficiently bltz Rs,label branch to label if (Rs < 0) bgtz Rs,label branch to label if (Rs > 0) blez Rs,label branch to label if (Rs <= 0) bgez Rs,label branch to label if (Rs >= 0)  No need for beqz and bnez instructions. Why? Conditional Branch Instructions
  • 33. Instruction Set Architecture COE 308 – Computer Architecture – KFUPM © Muhamed Mudawar – slide 33 Set on Less Than Instructions  MIPS also provides set on less than instructions slt rd,rs,rt if (rs < rt) rd = 1 else rd = 0 sltu rd,rs,rt unsigned < slti rt,rs,im16 if (rs < im16 ) rt = 1 else rt = 0 sltiu rt,rs,im16 unsigned <  Signed / Unsigned Comparisons Can produce different results Assume $s0 = 1 and $s1 = -1 = 0xffffffff slt $t0,$s0,$s1 results in $t0 = 0 stlu $t0,$s0,$s1 results in $t0 = 1
  • 34. Instruction Set Architecture COE 308 – Computer Architecture – KFUPM © Muhamed Mudawar – slide 34 More on Branch Instructions  MIPS hardware does NOT provide instructions for … blt, bltu branch if less than (signed/unsigned) ble, bleu branch if less or equal (signed/unsigned) bgt, bgtu branch if greater than (signed/unsigned) bge, bgeu branch if greater or equal (signed/unsigned) Can be achieved with a sequence of 2 instructions  How to implement: blt $s0,$s1,label  Solution: slt $at,$s0,$s1 bne $at,$zero,label  How to implement: ble $s2,$s3,label  Solution: slt $at,$s3,$s2 beq $at,$zero,label
  • 35. Instruction Set Architecture COE 308 – Computer Architecture – KFUPM © Muhamed Mudawar – slide 35 Pseudo-Instructions  Introduced by assembler as if they were real instructions  To facilitate assembly language programming  Assembler reserves $at = $1 for its own use  $at is called the assembler temporary register ori $s1, $zero, 0xabcd li $s1, 0xabcd slt $s1, $s3, $s2 sgt $s1, $s2, $s3 nor $s1, $s2, $s2 not $s1, $s2 slt $at, $s1, $s2 bne $at, $zero, label blt $s1, $s2, label lui $s1, 0xabcd ori $s1, $s1, 0x1234 li $s1, 0xabcd1234 addu Ss1, $s2, $zero move $s1, $s2 Conversion to Real Instructions Pseudo-Instructions
  • 36. Instruction Set Architecture COE 308 – Computer Architecture – KFUPM © Muhamed Mudawar – slide 36 Jump, Branch, and SLT Instructions Instruction Meaning Format j label jump to label op6 = 2 imm26 beq rs, rt, label branch if (rs == rt) op6 = 4 rs5 rt5 imm16 bne rs, rt, label branch if (rs != rt) op6 = 5 rs5 rt5 imm16 blez rs, label branch if (rs<=0) op6 = 6 rs5 0 imm16 bgtz rs, label branch if (rs > 0) op6 = 7 rs5 0 imm16 bltz rs, label branch if (rs < 0) op6 = 1 rs5 0 imm16 bgez rs, label branch if (rs>=0) op6 = 1 rs5 1 imm16 Instruction Meaning Format slt rd, rs, rt rd=(rs<rt?1:0) op6 = 0 rs5 rt5 rd5 0 0x2a sltu rd, rs, rt rd=(rs<rt?1:0) op6 = 0 rs5 rt5 rd5 0 0x2b slti rt, rs, imm16 rt=(rs<imm?1:0) 0xa rs5 rt5 imm16 sltiu rt, rs, imm16 rt=(rs<imm?1:0) 0xb rs5 rt5 imm16
  • 37. Instruction Set Architecture COE 308 – Computer Architecture – KFUPM © Muhamed Mudawar – slide 37 Next . . .  Instruction Set Architecture  Overview of the MIPS Processor  R-Type Arithmetic, Logical, and Shift Instructions  I-Type Format and Immediate Constants  Jump and Branch Instructions  Translating If Statements and Boolean Expressions  Load and Store Instructions  Translating Loops and Traversing Arrays  Alternative Architecture
  • 38. Instruction Set Architecture COE 308 – Computer Architecture – KFUPM © Muhamed Mudawar – slide 38 Translating an IF Statement  Consider the following IF statement: if (a == b) c = d + e; else c = d – e; Assume that a, b, c, d, e are in $s0, …, $s4 respectively  How to translate the above IF statement? bne $s0, $s1, else addu $s2, $s3, $s4 j exit else: subu $s2, $s3, $s4 exit: . . .
  • 39. Instruction Set Architecture COE 308 – Computer Architecture – KFUPM © Muhamed Mudawar – slide 39 Compound Expression with AND  Programming languages use short-circuit evaluation  If first expression is false, second expression is skipped if (($s1 > 0) && ($s2 < 0)) {$s3++;} # One Possible Implementation ... bgtz $s1, L1 # first expression j next # skip if false L1: bltz $s2, L2 # second expression j next # skip if false L2: addiu $s3,$s3,1 # both are true next:
  • 40. Instruction Set Architecture COE 308 – Computer Architecture – KFUPM © Muhamed Mudawar – slide 40 Better Implementation for AND The following implementation uses less code Reverse the relational operator Allow the program to fall through to the second expression Number of instructions is reduced from 5 to 3 if (($s1 > 0) && ($s2 < 0)) {$s3++;} # Better Implementation ... blez $s1, next # skip if false bgez $s2, next # skip if false addiu $s3,$s3,1 # both are true next:
  • 41. Instruction Set Architecture COE 308 – Computer Architecture – KFUPM © Muhamed Mudawar – slide 41 Compound Expression with OR  Short-circuit evaluation for logical OR  If first expression is true, second expression is skipped  Use fall-through to keep the code as short as possible  bgt, ble, and li are pseudo-instructions  Translated by the assembler to real instructions if (($sl > $s2) || ($s2 > $s3)) {$s4 = 1;} bgt $s1, $s2, L1 # yes, execute if part ble $s2, $s3, next # no: skip if part L1: li $s4, 1 # set $s4 to 1 next:
  • 42. Instruction Set Architecture COE 308 – Computer Architecture – KFUPM © Muhamed Mudawar – slide 42 Your Turn . . .  Translate the IF statement to assembly language  $s1 and $s2 values are unsigned  $s3, $s4, and $s5 values are signed bgtu $s1, $s2, next move $s3, $s4 next: if( $s1 <= $s2 ) { $s3 = $s4 } if (($s3 <= $s4) && ($s4 > $s5)) { $s3 = $s4 + $s5 } bgt $s3, $s4, next ble $s4, $s5, next addu $s3, $s4, $s5 next:
  • 43. Instruction Set Architecture COE 308 – Computer Architecture – KFUPM © Muhamed Mudawar – slide 43 Next . . .  Instruction Set Architecture  Overview of the MIPS Processor  R-Type Arithmetic, Logical, and Shift Instructions  I-Type Format and Immediate Constants  Jump and Branch Instructions  Translating If Statements and Boolean Expressions  Load and Store Instructions  Translating Loops and Traversing Arrays  Alternative Architecture
  • 44. Instruction Set Architecture COE 308 – Computer Architecture – KFUPM © Muhamed Mudawar – slide 44 Load and Store Instructions  Instructions that transfer data between memory & registers  Programs include variables such as arrays and objects  Such variables are stored in memory  Load Instruction:  Transfers data from memory to a register  Store Instruction:  Transfers data from a register to memory  Memory address must be specified by load and store Memory Registers load store
  • 45. Instruction Set Architecture COE 308 – Computer Architecture – KFUPM © Muhamed Mudawar – slide 45  Load Word Instruction (Word = 4 bytes in MIPS) lw Rt, imm16 (Rs) # Rt = MEMORY[Rs+imm16 ]  Store Word Instruction sw Rt, imm16 (Rs) # MEMORY[Rs+imm16 ] = Rt  Base or Displacement addressing is used  Memory Address = Rs (base) + Immediate16 (displacement)  Immediate16 is sign-extended to have a signed displacement Load and Store Word Op6 Rs5 Rt5 immediate16 Base or Displacement Addressing Memory Word Base address +
  • 46. Instruction Set Architecture COE 308 – Computer Architecture – KFUPM © Muhamed Mudawar – slide 46 Example on Load & Store  Translate A[1] = A[2] + 5 (A is an array of words)  Assume that address of array A is stored in register $s0 lw $s1, 8($s0) # $s1 = A[2] addiu $s2, $s1, 5 # $s2 = A[2] + 5 sw $s2, 4($s0) # A[1] = $s2  Index of a[2] and a[1] should be multiplied by 4. Why? sw Memory A[1] A[0] A[2] A[3] . . . . . . A+12 A+8 A+4 A Registers address of A $s0 = $16 value of A[2] $s1 = $17 A[2] + 5 $s2 = $18 . . . . . . lw
  • 47. Instruction Set Architecture COE 308 – Computer Architecture – KFUPM © Muhamed Mudawar – slide 47 0 0 s s s s s 0 0 s bu b h hu sign – extend zero – extend sign – extend zero – extend 32-bit Register  The MIPS processor supports the following data formats:  Byte = 8 bits, Halfword = 16 bits, Word = 32 bits  Load & store instructions for bytes and halfwords  lb = load byte, lbu = load byte unsigned, sb = store byte  lh = load half, lhu = load half unsigned, sh = store halfword  Load expands a memory data to fit into a 32-bit register  Store reduces a 32-bit register to fit in memory Load and Store Byte and Halfword
  • 48. Instruction Set Architecture COE 308 – Computer Architecture – KFUPM © Muhamed Mudawar – slide 48 Load and Store Instructions Instruction Meaning I-Type Format lb rt, imm16 (rs) rt = MEM[rs+imm16 ] 0x20 rs5 rt5 imm16 lh rt, imm16 (rs) rt = MEM[rs+imm16 ] 0x21 rs5 rt5 imm16 lw rt, imm16 (rs) rt = MEM[rs+imm16 ] 0x23 rs5 rt5 imm16 lbu rt, imm16 (rs) rt = MEM[rs+imm16 ] 0x24 rs5 rt5 imm16 lhu rt, imm16 (rs) rt = MEM[rs+imm16 ] 0x25 rs5 rt5 imm16 sb rt, imm16 (rs) MEM[rs+imm16 ] = rt 0x28 rs5 rt5 imm16 sh rt, imm16 (rs) MEM[rs+imm16 ] = rt 0x29 rs5 rt5 imm16 sw rt, imm16 (rs) MEM[rs+imm16 ] = rt 0x2b rs5 rt5 imm16  Base or Displacement Addressing is used  Memory Address = Rs (base) + Immediate16 (displacement)  Two variations on base addressing  If Rs = $zero = 0 then Address = Immediate16 (absolute)  If Immediate16 = 0 then Address = Rs (register indirect)
  • 49. Instruction Set Architecture COE 308 – Computer Architecture – KFUPM © Muhamed Mudawar – slide 49 Next . . .  Instruction Set Architecture  Overview of the MIPS Processor  R-Type Arithmetic, Logical, and Shift Instructions  I-Type Format and Immediate Constants  Jump and Branch Instructions  Translating If Statements and Boolean Expressions  Load and Store Instructions  Translating Loops and Traversing Arrays  Alternative Architecture
  • 50. Instruction Set Architecture COE 308 – Computer Architecture – KFUPM © Muhamed Mudawar – slide 50 Translating a WHILE Loop  Consider the following WHILE statement: i = 0; while (A[i] != k) i = i+1; Where A is an array of integers (4 bytes per element) Assume address A, i, k in $s0, $s1, $s2, respectively  How to translate above WHILE statement? xor $s1, $s1, $s1 # i = 0 move $t0, $s0 # $t0 = address A loop: lw $t1, 0($t0) # $t1 = A[i] beq $t1, $s2, next # exit if (A[i]== k) addiu $s1, $s1, 1 # i = i+1 sll $t0, $s1, 2 # $t0 = 4*i addu $t0, $s0, $t0 # $t0 = address A[i] j loop next: . . . Memory A[2] A[i] A[1] A[0] . . . . . . A A+4 A+8 A+4×i . . .
  • 51. Instruction Set Architecture COE 308 – Computer Architecture – KFUPM © Muhamed Mudawar – slide 51 Using Pointers to Traverse Arrays  Consider the same WHILE loop: i = 0; while (A[i] != k) i = i+1; Where address of A, i, k are in $s0, $s1, $s2, respectively  We can use a pointer to traverse array A Pointer is incremented by 4 (faster than indexing) move $t0, $s0 # $t0 = $s0 = addr A j cond # test condition loop: addiu $s1, $s1, 1 # i = i+1 addiu $t0, $t0, 4 # point to next cond: lw $t1, 0($t0) # $t1 = A[i] bne $t1, $s2, loop # loop if A[i]!= k  Only 4 instructions (rather than 6) in loop body
  • 52. Instruction Set Architecture COE 308 – Computer Architecture – KFUPM © Muhamed Mudawar – slide 52 Arrays vs. Pointers  Array indexing involves  Multiplying index by element size  Using shift instruction when element size is a power of 2  Adding to array base address  Array version requires shift to be inside loop  Part of index calculation for incremented i  Pointers correspond directly to memory addresses  Can avoid indexing complexity  Induction variable elimination  Less instructions and faster code
  • 53. Instruction Set Architecture COE 308 – Computer Architecture – KFUPM © Muhamed Mudawar – slide 53 Copying a String move $t0, $s0 # $t0 = pointer to source move $t1, $s1 # $t1 = pointer to target L1: lb $t2, 0($t0) # load byte into $t2 sb $t2, 0($t1) # store byte into target addiu $t0, $t0, 1 # increment source pointer addiu $t1, $t1, 1 # increment target pointer bne $t2, $zero, L1 # loop until NULL char The following code copies source string to target string Address of source in $s0 and address of target in $s1 Strings are terminated with a null character (C strings) i = 0; do {target[i]=source[i]; i++;} while (source[i]!=0);
  • 54. Instruction Set Architecture COE 308 – Computer Architecture – KFUPM © Muhamed Mudawar – slide 54 Summing an Integer Array move $t0, $s0 # $t0 = address A[i] xor $t1, $t1, $t1 # $t1 = i = 0 xor $s2, $s2, $s2 # $s2 = sum = 0 L1: lw $t2, 0($t0) # $t2 = A[i] addu $s2, $s2, $t2 # sum = sum + A[i] addiu $t0, $t0, 4 # point to next A[i] addiu $t1, $t1, 1 # i++ bne $t1, $s1, L1 # loop if (i != n) Assume $s0 = array address, $s1 = array length = n sum = 0; for (i=0; i<n; i++) sum = sum + A[i];
  • 55. Instruction Set Architecture COE 308 – Computer Architecture – KFUPM © Muhamed Mudawar – slide 55 Addressing Modes Op6 Rs5 Rt5 immediate16 Base or Displacement Addressing Word Operand is in memory (load/store) Register = Base address + Halfword Op6 Rs5 Rt5 immediate16 Immediate Addressing Operand is a constant Op6 Rs5 Rt5 Rd5 funct6 sa5 Register Addressing Register Operand is in a register  Where are the operands?  How memory addresses are computed?
  • 56. Instruction Set Architecture COE 308 – Computer Architecture – KFUPM © Muhamed Mudawar – slide 56 Branch / Jump Addressing Modes Used for branching (beq, bne, …) Word = Target Instruction Op6 Rs5 Rt5 immediate16 PC-Relative Addressing PC30 00 +1 Target Instruction Address PC = PC + 4 × (1 + immediate16 ) PC30 + immediate16 + 1 00 immediate26 PC4 00 Target Instruction Address Word = Target Instruction immediate26 Op6 Pseudo-direct Addressing PC26 : 00 Used by jump instruction PC4
  • 57. Instruction Set Architecture COE 308 – Computer Architecture – KFUPM © Muhamed Mudawar – slide 57 Jump and Branch Limits  Jump Address Boundary = 226 instructions = 256 MB  Text segment cannot exceed 226 instructions or 256 MB  Upper 4 bits of PC are unchanged  Branch Address Boundary  Branch instructions use I-Type format (16-bit immediate constant)  PC-relative addressing:  Target instruction address = PC + 4×(1 + immediate16 )  Count number of instructions to branch from next instruction  Positive constant => Forward Branch, Negative => Backward branch  At most ±215 instructions to branch (most branches are near) immediate26 PC4 00 Target Instruction Address PC30 + immediate16 + 1 00
  • 58. Instruction Set Architecture COE 308 – Computer Architecture – KFUPM © Muhamed Mudawar – slide 58 Next . . .  Instruction Set Architecture  Overview of the MIPS Processor  R-Type Arithmetic, Logical, and Shift Instructions  I-Type Format and Immediate Constants  Jump and Branch Instructions  Translating If Statements and Boolean Expressions  Load and Store Instructions  Translating Loops and Traversing Arrays  Alternative Architecture
  • 59. Instruction Set Architecture COE 308 – Computer Architecture – KFUPM © Muhamed Mudawar – slide 59 Design alternative:  Provide more complex instructions  Goal is to reduce number of instructions executed  Danger is a slower cycle time and/or a higher CPI  Let’s look briefly at IA-32 (Intel Architecture - 32 bits)  An architecture that is “difficult to explain and impossible to love”  Developed by several independent groups  Evolved over more than 20 years  History illustrates impact of compatibility on the ISA Alternative Architecture
  • 60. Instruction Set Architecture COE 308 – Computer Architecture – KFUPM © Muhamed Mudawar – slide 60 The Intel x86 ISA Evolution with backward compatibility  8080 (1974): 8-bit microprocessor  Accumulator, plus 3 index-register pairs  8086 (1978): 16-bit extension to 8080  Complex instruction set (CISC)  8087 (1980): floating-point coprocessor  Adds FP instructions and register stack  80286 (1982): 24-bit addresses, MMU  Segmented memory mapping and protection  80386 (1985): 32-bit extension (now IA-32)  Additional addressing modes and operations  Paged memory mapping as well as segments
  • 61. Instruction Set Architecture COE 308 – Computer Architecture – KFUPM © Muhamed Mudawar – slide 61 The Intel x86 ISA Further evolution…  i486 (1989): pipelined, on-chip caches and FPU  Compatible competitors: AMD, Cyrix, …  Pentium (1993): superscalar, 64-bit datapath  Added MMX (Multi-Media eXtension) instructions  The infamous FDIV bug  Pentium Pro (1995), Pentium II (1997)  New microarchitecture (see Colwell, The Pentium Chronicles)  Pentium III (1999)  Added SSE (Streaming SIMD Extensions) and registers  Pentium 4 (2001)  New microarchitecture  Added SSE2 instructions
  • 62. Instruction Set Architecture COE 308 – Computer Architecture – KFUPM © Muhamed Mudawar – slide 62 The Intel x86 ISA And further…  AMD64 (2003): extended architecture to 64 bits  EM64T – Extended Memory 64 Technology (2004)  AMD64 adopted by Intel (with refinements)  Added SSE3 instructions  Intel Core (2006)  Added SSE4 instructions, virtual machine support  AMD64 (announced 2007): SSE5 instructions  Intel declined to follow, instead…  Advanced Vector Extension (announced 2008)  Longer SSE registers, more instructions Technical elegance ≠ market success
  • 63. Instruction Set Architecture COE 308 – Computer Architecture – KFUPM © Muhamed Mudawar – slide 63 Basic x86 Registers (IA-32)
  • 64. Instruction Set Architecture COE 308 – Computer Architecture – KFUPM © Muhamed Mudawar – slide 64 Typical IA-32 Instructions  Data movement instructions  MOV, PUSH, POP, LEA, …  Arithmetic and logical instructions  ADD, SUB, SHL, SHR, ROL, OR, XOR, INC, DEC, CMP, …  Control flow instructions  JMP, JZ, JNZ, CALL, RET, LOOP, …  String instructions  MOVS, LODS, …  First operand is a source and destination  Can be register or memory operand  Second operand is a source  Can be register, memory, or an immediate constant
  • 65. Instruction Set Architecture COE 308 – Computer Architecture – KFUPM © Muhamed Mudawar – slide 65 IA-32 Instruction Formats  Complexity:  Instruction formats from 1 to 17 bytes long  One operand must act as both a source and destination  One operand can come from memory  Complex addressing modes  Base or scaled index with 8 or 32 bit displacement  Typical IA-32 Instruction Formats: JE EIP + displacement JE Displacement Condi- tion 4 4 8 CALL CALL Offset 8 32 MOV EBX, [EDI + 45] MOV w d Displacement r/m Postbyte 6 8 1 1 8 PUSH ESI PUSH Reg 5 3 ADD EAX, #6765 ADD w Immediate Reg 4 32 3 1 TEST EDX, #42 Immediate Postbyte TEST w 7 32 1 8
  • 66. Instruction Set Architecture COE 308 – Computer Architecture – KFUPM © Muhamed Mudawar – slide 66 ARM & MIPS Similarities ARM: the most popular embedded core Similar basic set of instructions to MIPS ARM MIPS Date announced 1985 1985 Instruction size 32 bits 32 bits Address space 32-bit flat 32-bit flat Data alignment Aligned Aligned Data addressing modes 9 3 Registers 15 × 32-bit 31 × 32-bit Input/output Memory mapped Memory mapped
  • 67. Instruction Set Architecture COE 308 – Computer Architecture – KFUPM © Muhamed Mudawar – slide 67 Compare and Branch in ARM  Uses condition codes for the result of an arithmetic/logic instruction  Negative, zero, carry, overflow  Compare instructions to set condition codes without keeping the result  Each instruction can be conditional  Top 4 bits of instruction word: condition value  Can avoid branches over single instructions
  • 68. Instruction Set Architecture COE 308 – Computer Architecture – KFUPM © Muhamed Mudawar – slide 68 Instruction Encoding
  • 69. Instruction Set Architecture COE 308 – Computer Architecture – KFUPM © Muhamed Mudawar – slide 69 Fallacies Powerful instruction  higher performance  Fewer instructions required  But complex instructions are hard to implement  May slow down all instructions, including simple ones  Compilers are good at making fast code from simple instructions Use assembly code for high performance  But modern compilers are better at dealing with modern processors  More lines of code  more errors and less productivity
  • 70. Instruction Set Architecture COE 308 – Computer Architecture – KFUPM © Muhamed Mudawar – slide 70 Fallacies  Backward compatibility  instruction set doesn’t change  But they do introduce more instructions x86 instruction set
  • 71. Instruction Set Architecture COE 308 – Computer Architecture – KFUPM © Muhamed Mudawar – slide 71 Summary of Design Principles 1. Simplicity favors regularity  Simple instructions dominate the instruction frequency  So design them to be simple and regular, and make them fast  Use general-purpose registers uniformly across instructions  Fix the size of instructions (simplifies fetching & decoding)  Fix the number of operands per instruction  Three operands is the natural number for a typical instruction 2. Smaller is faster  Limit the number of registers for faster access (typically 32) 3. Make the common case fast  Include constants inside instructions (faster than loading them)  Design most instructions to be register-to-register 4. Good design demands good compromises  Smaller immediate constants in I-type instructions