0% found this document useful (0 votes)
110 views

A Minimalistic Introduction To MIPS Instruction

The document provides an overview of MIPS instruction set architecture. It describes the general instruction format with fields for operation code, source and destination registers, and a shift amount. It also summarizes the different instruction types including arithmetic, logical, data transfer, conditional branch, and system calls. Key principles of the MIPS design are regularity in instruction formats, using smaller 32-bit registers for faster performance, balancing simplicity with functionality, and optimizing common instructions.
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
110 views

A Minimalistic Introduction To MIPS Instruction

The document provides an overview of MIPS instruction set architecture. It describes the general instruction format with fields for operation code, source and destination registers, and a shift amount. It also summarizes the different instruction types including arithmetic, logical, data transfer, conditional branch, and system calls. Key principles of the MIPS design are regularity in instruction formats, using smaller 32-bit registers for faster performance, balancing simplicity with functionality, and optimizing common instructions.
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

A Minimalistic Introduction to MIPS Instruction

http://www.cs.pitt.edu/~xujie/cs447/MIPS_Instruction.htm

A Minimalistic Introduction to MIPS Instruction


General Format
31 26 21 16 11 6 0 ______ _____ _____ _____ _____ ______ |______|_____|_____|_____|_____|______| OP RS RT RD SHAMT FUNC

op

rs

rt

rd

shamt funct 6 bits

6 bits 5 bits 5 bits 5 bits 5 bits

op Operation code

rs First source register operand

rt Second source register operand

rd Destination register operand

shamt Shift amount - used in shift instructions

funct Select the variant of the operation in the op code field

Specific Instruction Formats Format 6 bits 5 bits 5 bits 5 bits 5 bits 6 bits R op rs rt rd shamt funct Comments Arithmetic

1 of 5

9/28/2011 5:49 PM

A Minimalistic Introduction to MIPS Instruction

http://www.cs.pitt.edu/~xujie/cs447/MIPS_Instruction.htm

I J

op op

rs

rt

address/immediate target address

Transfer, branch,immediate Jump

MIPS Instruction Set


The MIPS instruction set illustrates four underlying principles of hardware design: 1. 2. 3. 4. Simplicity favors regularity. Smaller is faster. Good design demands compromise. Make the common case fast.

Simplicity favors regularity Consider the following example:

Category Instruction Example Meaning Arithmetic Arithmetic add subtract add a,b,c sub a,b,c a=b+c a=b-c

Comments Always 3 operands Always 3 operands

Note that each operand has exactly three operands.

Smaller is faster. MIPS has 32 32-bit registers,$v0,...$v31, a very large number would increase the clock cycle time.

Good design demands compromise. The compromise represented by the MIPS design, was to make all the instructions the same length, thereby requiring different instruction formats.

Make the common case fast. The MIPS instruction set addresses this principal by making constants part of arithmetic instructions. Furthermore, by loading small constants into the upper 16-bits of a register.

MIPS Instruction Set Summary


2 of 5

9/28/2011 5:49 PM

A Minimalistic Introduction to MIPS Instruction

http://www.cs.pitt.edu/~xujie/cs447/MIPS_Instruction.htm

Arithmetic Instructions

Instruction add subtract add immediate add unsigned subtract unsigned

Example add $1,$2,$3 sub $1,$2,$3 addi $1,$2,10 addu $1,$2,$3 subu $1,$2,$3

Meaning

Comments

$1=$2+$3 Always 3 operands $1=$2-$3 Always 3 operands

$1=$2+10 add constant $1=$2+$3 Always 3 operations $1=$2-$3 Always 3 operations

add immed.unsigned addiu $1,$2,10 $1=$2+10 Always 3 operations

Logical Instruction and or and immediate or immediate shift left logical Example and $1,$2,$3 or $1,$2,$3 Meaning $1=$2&$3 $1=$2|$3 Comments 3 register operands 3 register operands AND constant OR constant

andi $1,$2,10 $1=$2&10 or $1,$2,10 sll $1,$2,10 $1=$2|10

$1=$2<<10 Shift left by constant $1=$2>>10 Shift right by constant

shift right logical srl $1,$2,10

Data Transfer Instruction load word store word Example Meaning Comments

lw $1,10($2) $1=Memory[$2+10] memory to register sw $1,10($2) Memory[$2+10]=$1 register to memory $1=10x2^16 load constant into upper 16 bits

load upper immed. lui $1,10

Conditional Branch

3 of 5

9/28/2011 5:49 PM

A Minimalistic Introduction to MIPS Instruction

http://www.cs.pitt.edu/~xujie/cs447/MIPS_Instruction.htm

Instruction branch on equal

Example

Meaning

Comments

beq $1,$2,10 if($1==$2)go to PC+4+10 Equal test Not equal test Less than compare

branch on not equal bne $1,$2,10 if($1!=$2)go to PC+4+10 set on less then slt $1,$2,$3 if($2<$3)$1=1;else $1=0

Unconditional Jump Instruction jump jump register Example j 1000 jr $31 Meaning go to 1000 go to $31 Comments Jump to target address For switch, procedure return

jump and link jal 1000

$31=PC+4;go to 1000 For procedure call

Assembler Syntax Program includes .data and .text Comments begin with #. Rest of line is ignored. Identifier names are sequence of letters, numbers, underbars (_) and dots (.). Labels are declared by putting them at beginning of line followed by colon. Use labels for variables and code locations. Instruction format: op field followed by one or more operands: addi $t0, $t0, 1 Operands may be literal values or registers. Register is hardware primitive, can stored 32-bit value: $s0 Numbers are base 10 by default. 0x prefix indicates hexadecimal. Strings are enclosed in quotes. May include \n=newline or \t=tab. Used for prompts.

System Services in MIPS


To print an integer to the screen: Put the integer into $a0 Set $v0 to 1 syscall To print a string to the screen: Put the address of the string into $a0 Set $v0 to 4 syscall

4 of 5

9/28/2011 5:49 PM

A Minimalistic Introduction to MIPS Instruction

http://www.cs.pitt.edu/~xujie/cs447/MIPS_Instruction.htm

To read an integer from the keyboard Set $v0 to 5 syscall The integer entered will be in $v0 To exit Set $v0 to 10 syscall

5 of 5

9/28/2011 5:49 PM

You might also like