Professional Documents
Culture Documents
Page 1
Instruction Set
Instruction Words of a computer language
Instruction set Collection of instructions
Different computers have different instruction sets
But they have many aspects in common
MIPS (Microprocessor without Interlocked Pipeline
Stages) architecture RISC architecture developed by
MIPS technologies
Page 2
Arithmetic Operations
Consider the notation,
add a, b, c
This adds the two variables b & c & puts the sum in a
All arithmetic operations are of this form
Perform only one operation
Must have exactly three variables
Page 3
Page 4
Page 5
Page 6
Page 7
Register Operands
Arithmetic instructions use register operands
MIPS has 32 X 32-bit registers
Used for frequently accessed data
Numbered from 0 to 31
32-bit data --- Word
Design Principle 2 Smaller is faster
Main memory has millions of locations
Page 8
Page 9
1
0
Memory Operands
Main memory is used for complex data structures like
arrays, structures etc
To perform arithmetic operations
Load values from memory to registers
Store result from register to memory
Memory is a large single dimensional array & is byte
addressed
Each address identifies an 8-bit byte
Page 11
11
12
Page 13
1
0
Store instruction
Copies data from a register to memory
MIPS instruction is sw (store word)
Format is, operation name followed by the register
to be stored, then offset to select the array element &
the base register
Page 14
14
Page 15
1
5
Registers Vs Memory
Registers are faster to access than memory
Keep the most frequently used variables in
registers
Memory operations require load & store
More instructions to be executed
Page 16
1
6
Immediate Operands
Constant data specified in an instruction
MIPS instruction is addi (add immediate)
To add constant 4 to register $s3 we write,
addi $s3, $s3, 4
negative constant
addi $s2, $s1, -2
Page 17
1
7
Page 18
1
8
Page 19
1
9
Page 20
2
0
5 bits
5 bits
5 bits
5 bits
6 bits
op
rs
rt
rd
shamt
funct
2
3
Page 22
op
rs
rt
rd
18
shamt funct
0
32
2
3
For
6 bits
5 bits
5 bits
op
rs
rt
16 bits
constant
Page 23
op
rs
rt
18
17
constant
100
2
4
Page 24
op
rs
rt
35
18
17
constant
100
2
4
instruction
formats
for
different
Page 25
2
4
Format
op
rs
rt
rd
add
reg reg
reg
32
NA
sub
reg reg
reg
34
NA
addi
reg reg NA
NA
NA
Constant
lw
35
reg reg NA
NA
NA
Address
sw
43
reg reg NA
NA
NA
Address
Page 26
shamt funct
address
2
5
Logical Operations
Page 27
Operation
MIPS instruction
sll
srl
Bit-by-bit AND
and, andi
Bit-by-bit OR
or, ori
Bit-by-bit NOT
nor
2
6
Instruction format
op
rs
rt
rd
shamt
funct
Page 28
16
10
2
7
Instruction format
op
rs
rt
rd
shamt
funct
Page 29
16
10
2
7
AND operation
Bit-by-bit operation
Leaves a 1 if both operand bits are 1
For eg, and $s1, $s2, $s3
Machine language version is,
op
rs
rt
rd shamt funct
0
Page 30
18
19
17
36
3
0
OR operation
Bit-by-bit operation
Leaves a 1 if either operand bit is 1
For eg, or $s1, $s2, $s3
Machine language version is,
op
rs
rt
rd shamt funct
0
Page 31
18
19
17
37
2
8
NOT operation
Bit-by-bit operation
Inverts the bit value
MIPS has NOR 3-operand instruction
a NOR b = NOT (a OR b)
For eg, nor $s1, $s2, $s3
Machine language version is,
op
rs
rt
rd shamt funct
0
Page 32
18
19
17
39
2
8
$t1
$t0
Page 33
3
3
$t1
$t0
Page 34
3
4
$t0
Page 35
3
5
3
6
3
7
Compiling if statements
Consider the statement,
if (i == j) f = g + h; else f = g h;
Assume that variables f through j correspond to registers
$s0 through $s4
Compiled MIPS code is,
bne $s3, $s4, Else
add $s0, $s1, $s2
j Exit
Else: sub $s0, $s1, $s2
Exit:
Page 38
3
8
# $t1 = 4 * i
# $t1 = addr of save[i]
# $t0 = save[i]
# if save[i] k, exit
# i = i +1
3
9
op
5 bits
5 bits
16 bits
rs
rt
constant/address
Page 40
17
18
25
4
0
op
26 bits
constant/address
For eg, j L2
Page 41
2500
4
1
Page 42
constant
2500
4
2
Page 43
op
rs
rt
rd
31
shamt funct
0
4
3
Page 44
4
4
Instruction format
op
rs
rt
rd
shamt
funct
Page 45
rs
18
rt
rd
19
17
shamt
0
funct
42
4
5
Page 46
4
6
255
Page 47
4
7
4
8
Page 49
Name
Register No
Usage
$zero
Constant 0
$at
Assembler
$v0-$v1
2-3
$a0-$a3
4-7
Arguments
$t0-$t7
8-15
Temporaries
$s0-$s7
16-23
Saved
$t8-$t9
24-25
Temporaries
$k0-$k1
26-27
Kernel
$gp
28
Global pointer
$sp
29
Stack pointer
$fp
30
Frame pointer
$ra
31
Return address
4
9
Page 50
5
0
Page 51
5
1