Mips PPT Slides
Mips PPT Slides
Mips PPT Slides
2.1 Introduction
Instruction Set
Simplified implementation
add a, b, c # a gets b + c
All arithmetic operations have this form
Design Principle 1: Simplicity favours
regularity
Arithmetic Operations
Arithmetic Example
C code:
f = (g + h) - (i + j);
# temp t0 = g + h
# temp t1 = i + j
# f = t0 - t1
Assembler names
Register Operands
C code:
f = (g + h) - (i + j);
f, , j in $s0, , $s4
Memory Operands
C code:
g = h + A[8];
g in $s1, h in $s2, base address of A in $s3
lw $t0, 32($s3)
add $s1, $s2, $t0
offset
# load word
base register
C code:
A[12] = h + A[8];
h in $s2, base address of A in $s3
Immediate Operands
Cannot be overwritten
x = x n1 2
+ x n2 2
+ L + x1 2 + x 0 2
Range: 0 to +2n 1
Example
n2
Using 32 bits
0 to +4,294,967,295
Chapter 2 Instructions: Language of the Computer 14
x = x n1 2
+ x n2 2
+ L + x1 2 + x 0 2
Range: 2n 1 to +2n 1 1
Example
n2
Using 32 bits
2,147,483,648 to +2,147,483,647
Chapter 2 Instructions: Language of the Computer 15
Signed Negation
Complement means 1 0, 0 1
x + x = 1111...1112 = 1
x + 1 = x
Example: negate +2
Sign Extension
MIPS instructions
Register numbers
Representing Instructions
op
rs
rt
rd
shamt
funct
6 bits
5 bits
5 bits
5 bits
5 bits
6 bits
Instruction fields
R-format Example
op
rs
rt
rd
shamt
funct
6 bits
5 bits
5 bits
5 bits
5 bits
6 bits
$s1
$s2
$t0
add
17
18
32
000000
10001
10010
01000
00000
100000
000000100011001001000000001000002 = 0232402016
Chapter 2 Instructions: Language of the Computer 21
Hexadecimal
Base 16
0
1
2
3
4
5
6
7
0100
0101
0110
0111
8
9
a
b
1000
1001
1010
1011
c
d
e
f
1100
1101
1110
1111
rs
rt
constant or address
6 bits
5 bits
5 bits
16 bits
op
Instructions represented in
binary, just like data
Instructions and data stored
in memory
Programs can operate on
programs
Standardized ISAs
Java
MIPS
Shift left
<<
<<
sll
Shift right
>>
>>>
srl
Bitwise AND
&
&
and, andi
Bitwise OR
or, ori
Bitwise NOT
nor
Logical Operations
Shift Operations
rs
rt
rd
shamt
funct
6 bits
5 bits
5 bits
5 bits
5 bits
6 bits
op
AND Operations
$t1
$t0
OR Operations
$t1
$t0
NOT Operations
Change 0 to 1, and 1 to 0
a NOR b == NOT ( a OR b )
Register 0: always
read as zero
$t1
$t0
Conditional Operations
j L1
Compiling If Statements
C code:
if (i==j) f = g+h;
else f = g-h;
f, g, in $s0, $s1,
C code:
while (save[i] == k) i += 1;
$t1,
$t1,
$t0,
$t0,
$s3,
Loop
$s3, 2
$t1, $s6
0($t1)
$s5, Exit
$s3, 1
Basic Blocks
Otherwise, set to 0