Académique Documents
Professionnel Documents
Culture Documents
› Register indirect:
› Direct:
› Scaled:
› Memory indirect:
Like the PowerPC, MIPS can select either Big Endian or Little Endian
byte ordering.
For example,
DADD R3, R1, R2 Regs[R3] ← Regs[R1] + Regs[R2]
DSUB R3, R1, R2 Regs[R3] ← Regs[R1] – Regs[R2]
MIPS instructions
Here are a few MIPS instructions. The text has another list, and a
comprehensive list (for MIPS IV) can be found at
techpubs.sgi.com/library/manuals/2000/ 007-2597-001/pdf/007-2597-
001.pdf
Logical instructions
Instruction Example Meaning Comments
And AND R1,R2,R3 R1←R2&R3
Or OR R1,R2,R3 R1←R2|R3
And immediate ANDI R1,R2,10 R1←R2&10 and with a constant
Shift left logical SLL R1,R2,10 R1←R2<<10 Shift left by constant
Shift right logical SRL R1,R2,10 R1←R2>>10 Shift right by constant
Load/store
Instruction Example Meaning Comments
Load word LW R1,10(R2) R1←Mem [R2+10] Memory to register
Store word R1,10(R2) Mem[R2+10] ←R1 Register to memory
SW
Load upper Load constant into
LUI R1,10 R1←10×216
immed. upper 16 bits of word
Conditional branch
Instruction Example Meaning
Branch on equal BEQ R1,R2,10 if (R1==R2) goto PC+4+10
Branch on not equal BNE R1,R2,10 if (R1!=R2) goto PC+4+10
Set on less than SLT R1,R2,R3 if (R2<R3) R1←1; else R1=0
Unconditional jump
Instruction Example Meaning Comments
Jump J 1000 goto 1000 Jump to target address
Jump register JR R31 goto R31 For switch or procedure return
R31←PC+4;
Jump and link JAL 1000 For procedure call
goto 1000
Jump and link R31←PC+4;
JALR R1 For procedure call
register PC←R2
Floating-point
Instruction Example Meaning Comments
Add double ADD.D F1,F2,F3 F1←F2+F3 64-bit operation
Subtract single SUB.S F1,F2,F3 F1←F2–F3 32-bit operation
Multiply paired MUL.PS Two 32-bit operations
F1←F2×F3
single F1,F2,F3 simultaneously
Let’s take a look at how frequently these instructions are used. Here
are frequencies for five SPECint2000 programs.
Compare these
frequencies with
the frequencies
for integer
programs.
What differences
do you see in
instruction
frequencies?
.text
.globl main
main:
li $v0,4 # load code for print_string
la $a0, msg1 # address of string to print
syscall # print string
li $v0,5 # load code for read_int
syscall # input N
move $t0,$v0 # save
li $t1, 0 # initialize counter (i)
li $t2, 0 # initialize sum
loop: addi $t1, $t1, 1 # i = i + 1
add $t2, $t2, $t1 # sum = sum + i
beq $t0, $t1, exit # if i = N, continue
j loop
exit: li $v0, 4 # output msg2
la $a0, msg2
syscall
Output
Number of integers (N)? 5
Sum = 15
© 2002 Edward F. Gehringer ECE 463/521 Lecture Notes, Fall 2002 7
Figures from CAQA used with permission of Morgan Kaufmann Publishers. © 2003 Elsevier Science (USA)
Comments on the program
In MIPS, registers have names as well as numbers. Some of the
register names that are used in this program are—