Advanced Computer Architecture: Mips Instruction-Set Architecture
Advanced Computer Architecture: Mips Instruction-Set Architecture
MIPS
Instruction-Set Architecture
Instructor: Md. Abdur Razzak
Topics
Instructions & MIPS instruction set
Where are the operands ?
Machine language
Assembler
Translating C statements into Assembler
For details see the book (ch 2):
Control flow
Jump
Conditional Branch
Call & Return
Example:
C code: A = B + C
C code: A = B + C + D;
E = F - A;
CPU Memory
register file
IO
University of Global Village 6
Register allocation
Compiler tries to keep as many variables in registers
as possible
stack
1 8 bits of data
2 8 bits of data
3 8 bits of data
4 8 bits of data
5 8 bits of data
6 8 bits of data
...
University of Global Village 8
Memory Organization
Bytes are nice, but most data items use larger "words"
For MIPS, a word is 32 bits or 4 bytes.
0 32 bits of data
8 32 bits of data
...
12 32 bits of data
12
16
20
24
Instruction Meaning
Instruction Format:
op rs rt rd shamt funct
35 18 9 32
op rs rt 16 bit number
Example: if (i==j) h = i + j;
Formats:
R op rs rt rd shamt funct
I op rs rt 16 bit address
J op 26 bit address
University of Global Village 18
Control Flow
We have: beq, bne, what about Branch-if-less-than?
New instruction:
meaning:
if $s1 < $s2 then
$t0 = 1
slt $t0, $s1, $s2 else
$t0 = 0
MIPS Instructions:
1010101010101010 0000000000000000
0000000000000000 1010101010101010
ori
1010101010101010 1010101010101010
Formats:
I op rs rt 16 bit address
J op 26 bit address
I op rs rt 16 bit address
Arithmetic subtract sub $s1, $s2, $s3 $s1 = $s2 - $s3 Three operands; data in registers
add immediate addi $s1, $s2, 100 $s1 = $s2 + 100 Used to add constants
load word lw $s1, 100($s2) $s1 = Memory[$s2 + 100] Word from memory to register
store word sw $s1, 100($s2) Memory[$s2 + 100] = $s1 Word from register to memory
Data transfer load byte lb $s1, 100($s2) $s1 = Memory[$s2 + 100] Byte from memory to register
store byte sb $s1, 100($s2) Memory[$s2 + 100] = $s1 Byte from register to memory
load upper immediate lui $s1, 100 $s1 = 100 * 2
16 Loads constant in upper 16 bits
branch on equal beq $s1, $s2, 25 if ($s1 == $s2) go to Equal test; PC-relative branch
PC + 4 + 100
branch on not equal bne $s1, $s2, 25 if ($s1 != $s2) go to Not equal test; PC-relative
PC + 4 + 100
Conditional
branch set on less than slt $s1, $s2, $s3 if ($s2 < $s3) $s1 = 1; Compare less than; for beq, bne
else $s1 = 0
set less than slti $s1, $s2, 100 if ($s2 < 100) $s1 = 1; Compare less than constant
immediate else $s1 = 0
2. Register addressing
op rs rt rd ... funct Registers
Register
3. Base addressing
op rs rt Address Memory
4. PC-relative addressing
op rs rt Address Memory
PC + Word
5. Pseudodirect addressing
op Address Memory
PC Word
Complexity:
Instructions 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
e.g., ―base or scaled index with 8 or 32 bit displacement‖
Saving grace:
the most frequently used instructions are not too difficult to
build
compilers avoid the portions of the architecture that are slow
Link
insert library code
determine addresses of data and instruction labels
relocation: patch addresses
call main
compiler
Assembly program
assembler
linker
Executable
loader
Memory
University of Global Village 32