Lect07 MIPS1
Lect07 MIPS1
sg/~cs2100/
Lecture #7
MIPS
Part I: Introduction
Lecture #1: Introduction 1-2
Details
• Notes Credit:
• All notes are by A/P Aaron Tan
• Lecture Link (Please bookmark):
https://nus-
sg.zoom.us/j/84884962542?pwd=NEF6SVdQUUgwWmRw
UmgvSy9WTlNDQT09
Recap
§ You write programs in high level
programming languages, e.g.,
C/C++, Java:
A + B
§ Compiler translates this into
assembly language statement:
add A, B
Software
(to be translated to
the instruction set)
§ Assembly language
§ Symbolic version of machine code
§ Human readable
§ add A, B is equivalent to 1000110010100000
§ Assembler translates from assembly language to machine code
§ Assembly can provide ‘pseudo-instructions’ as syntactic sugar
§ When considering performance, only real instructions are counted.
Lecture #7: MIPS Part 1: Introduction 9
Processor Memory
Bus
Perform Bridge between the Storage of code
computations two components and data
Lecture #7: MIPS Part 1: Introduction 11
Processor Memory
………..
Lecture #7: MIPS Part 1: Introduction 12
Inst ………..
Bus res ß res + i
r0 i ßi+1
r1 if i < 10,
ALU
.. …
………
i 1
res 0
………..
Lecture #7: MIPS Part 1: Introduction 13
………..
Lecture #7: MIPS Part 1: Introduction 16
………..
Lecture #7: MIPS Part 1: Introduction 17
………..
Lecture #7: MIPS Part 1: Introduction 18
………..
Lecture #7: MIPS Part 1: Introduction 19
………..
Lecture #7: MIPS Part 1: Introduction 20
………..
Lecture #7: MIPS Part 1: Introduction 21
………..
Lecture #7: MIPS Part 1: Introduction 22
………..
Lecture #7: MIPS Part 1: Introduction 23
Register Register
Name Usage Name Usage
number number
$zero 0 Constant value 0 More
$t8-$t9 24-25
Values for results temporaries
$v0-$v1 2-3 and expression $gp 28 Global pointer
evaluation $sp 29 Stack pointer
$a0-$a3 4-7 Arguments $fp 30 Frame pointer
$t0-$t7 8-15 Temporaries $ra 31 Return address
$s0-$s7 16-23 Program variables
Source 2
Operation (op) Source 1
Destination
(gets the result)
$s0 = $s1 + $s2
Naturally, most of the MIPS arithmetic/logic operations
have three operands: 2 sources and 1 destination
Lecture #7: MIPS Part 1: Introduction 28
±
Lecture #7: MIPS Part 1: Introduction 33
±
Lecture #7: MIPS Part 1: Introduction 34
AND a b a AND b OR a b a OR b
0 0 0 0 0 0
0 1 0 0 1 1
1 0 0 1 0 1
1 1 1 1 1 1
$t2
±
Lecture #7: MIPS Part 1: Introduction 38
$t0
Notes:
The and instruction has an immediate version, andi
±
Lecture #7: MIPS Part 1: Introduction 41
±
Lecture #7: MIPS Part 1: Introduction 42
±
Lecture #7: MIPS Part 1: Introduction 43
n Strange Fact 2:
n There is no NORI, but there is XORI in MIPS
n Why?
±
Lecture #7: MIPS Part 1: Introduction 44
1010101010101010 0000000000000000
ori 0000000000000000 1111000011110000
1010101010101010 1111000011110000
Lecture #7: MIPS Part 1: Introduction 45
End of File