MIPS Instruction Reference

Similar documents
F. Appendix 6 MIPS Instruction Reference

MIPS Reference Guide

The MIPS Instruction Set Architecture

EEM 486: Computer Architecture. Lecture 2. MIPS Instruction Set Architecture

MIPS Instruction Set

MIPS Instruction Format

ECE 2035 Programming HW/SW Systems Spring problems, 6 pages Exam One 4 February Your Name (please print clearly)

Q1: /30 Q2: /25 Q3: /45. Total: /100

Computer Architecture. The Language of the Machine

ECE 2035 Programming HW/SW Systems Fall problems, 7 pages Exam Two 23 October 2013

Week 10: Assembly Programming

MIPS ISA. 1. Data and Address Size 8-, 16-, 32-, 64-bit 2. Which instructions does the processor support

ECE 2035 Programming HW/SW Systems Fall problems, 6 pages Exam One 22 September Your Name (please print clearly) Signed.

CSc 256 Midterm 2 Fall 2011

CSc 256 Midterm 2 Spring 2012

Question 0. Do not turn this page until you have received the signal to start. (Please fill out the identification section above) Good Luck!

SPIM Instruction Set

M2 Instruction Set Architecture

TSK3000A - Generic Instructions

Reduced Instruction Set Computer (RISC)

Assembly Programming

ECE 2035 Programming HW/SW Systems Spring problems, 6 pages Exam Two 11 March Your Name (please print) total

Mark Redekopp, All rights reserved. EE 357 Unit 11 MIPS ISA

CSc 256 Midterm (green) Fall 2018

Overview. Introduction to the MIPS ISA. MIPS ISA Overview. Overview (2)

Reduced Instruction Set Computer (RISC)

Examples of branch instructions

ECE 2035 Programming HW/SW Systems Fall problems, 6 pages Exam One 19 September 2012

ECE232: Hardware Organization and Design. Computer Organization - Previously covered

101 Assembly. ENGR 3410 Computer Architecture Mark L. Chang Fall 2009

Arithmetic for Computers

Flow of Control -- Conditional branch instructions

MIPS Assembly Language. Today s Lecture

Today s Lecture. MIPS Assembly Language. Review: What Must be Specified? Review: A Program. Review: MIPS Instruction Formats

Mips Code Examples Peter Rounce

ECE 2035 Programming HW/SW Systems Fall problems, 6 pages Exam Two 23 October Your Name (please print clearly) Signed.

ECE 2035 Programming HW/SW Systems Fall problems, 6 pages Exam Two 21 October 2016

CSc 256 Final Fall 2016

ECE 2035 A Programming Hw/Sw Systems Fall problems, 8 pages Final Exam 8 December 2014

ECE 2035 Programming HW/SW Systems Spring problems, 6 pages Exam Three 10 April 2013

ECE 2035 A Programming Hw/Sw Systems Spring problems, 8 pages Final Exam 29 April 2015

ECE Exam I February 19 th, :00 pm 4:25pm

Computer Architecture. MIPS Instruction Set Architecture

ece4750-parc-isa.txt

CISC 662 Graduate Computer Architecture. Lecture 4 - ISA MIPS ISA. In a CPU. (vonneumann) Processor Organization

Recap from Last Time. CSE 2021: Computer Organization. Levels of Programming. The RISC Philosophy 5/19/2011

RTL Model of a Two-Stage MIPS Processor

5/17/2012. Recap from Last Time. CSE 2021: Computer Organization. The RISC Philosophy. Levels of Programming. Stored Program Computers

Instruction Set Architecture of. MIPS Processor. MIPS Processor. MIPS Registers (continued) MIPS Registers

The MIPS R2000 Instruction Set

Final Project: MIPS-like Microprocessor

CS 4200/5200 Computer Architecture I

CISC 662 Graduate Computer Architecture. Lecture 4 - ISA

CPS311 - COMPUTER ORGANIZATION. A bit of history

Number Systems and Their Representations

Programming the processor

CSc 256 Final Spring 2011

EE 109 Unit 13 MIPS Instruction Set. Instruction Set Architecture (ISA) Components of an ISA INSTRUCTION SET OVERVIEW

INSTRUCTION SET COMPARISONS

MIPS Assembly Language

Outline. EEL-4713 Computer Architecture Multipliers and shifters. Deriving requirements of ALU. MIPS arithmetic instructions

Exam in Computer Engineering

Midterm. Sticker winners: if you got >= 50 / 67

ECE 2035 A Programming Hw/Sw Systems Fall problems, 8 pages Final Exam 9 December 2015

Computer Organization & Design

Review. Lecture #9 MIPS Logical & Shift Ops, and Instruction Representation I Logical Operators (1/3) Bitwise Operations

Assembly Language. Prof. Dr. Antônio Augusto Fröhlich. Sep 2006

EE 109 Unit 8 MIPS Instruction Set

Project Part A: Single Cycle Processor

Concocting an Instruction Set

ICS 233 COMPUTER ARCHITECTURE. MIPS Processor Design Multicycle Implementation

A Processor. Kevin Walsh CS 3410, Spring 2010 Computer Science Cornell University. See: P&H Chapter , 4.1-3

MIPS Assembly Language Programming

Mark Redekopp, All rights reserved. EE 352 Unit 3 MIPS ISA

ENCM 369 Winter 2013: Reference Material for Midterm #2 page 1 of 5

ECE 2035 A Programming Hw/Sw Systems Fall problems, 10 pages Final Exam 14 December 2016

MIPS%Assembly% E155%

ECE 2035 Programming Hw/Sw Systems Fall problems, 10 pages Final Exam 9 December 2013

MACHINE LANGUAGE. To work with the machine, we need a translator.

Digital System Design II

EE108B Lecture 3. MIPS Assembly Language II

ECE260: Fundamentals of Computer Engineering

Anne Bracy CS 3410 Computer Science Cornell University. [K. Bala, A. Bracy, E. Sirer, and H. Weatherspoon]

A General-Purpose Computer The von Neumann Model. Concocting an Instruction Set. Meaning of an Instruction. Anatomy of an Instruction

Lec 10: Assembler. Announcements

Computer Architecture Experiment

Kernel Registers 0 1. Global Data Pointer. Stack Pointer. Frame Pointer. Return Address.

software hardware Which is easier to change/design???

Concocting an Instruction Set

ECE260: Fundamentals of Computer Engineering

CS 61c: Great Ideas in Computer Architecture

ECE 15B Computer Organization Spring 2010

Processor. Han Wang CS3410, Spring 2012 Computer Science Cornell University. See P&H Chapter , 4.1 4

Adventures in Assembly Land

Review: MIPS Organization

Introduction to MIPS Processor

Computer Science 61C Spring Friedland and Weaver. Instruction Encoding

ECE468 Computer Organization & Architecture. MIPS Instruction Set Architecture

Review: Organization. CS152 Computer Architecture and Engineering Lecture 2. Review of MIPS ISA and Design Concepts

Part II Instruction-Set Architecture. Jan Computer Architecture, Instruction-Set Architecture Slide 1

Transcription:

Page 1 of 9 MIPS Instruction Reference This is a description of the MIPS instruction set, their meanings, syntax, semantics, and bit encodings. The syntax given for each instruction refers to the assembly language syntax supported by the MIPS assembler. Hyphens in the encoding indicate "don't care" bits which are not considered when an instruction is being decoded. General purpose registers (GPRs) are indicated with a dollar sign ($). The words SWORD and UWORD refer to 32-bit signed and 32-bit unsigned data types, respectively. The manner in which the processor executes an instruction and advances its program counters is as follows: 1. execute the instruction at PC 2. copy npc to PC 3. add 4 or the branch offset to npc This behavior is indicated in the instruction specifications below. For brevity, the function advance_pc (int) is used in many of the instruction descriptions. This function is defined as follows: void advance_pc (SWORD offset) { PC = npc; npc += offset; } Note: ALL arithmetic immediate values are sign-extended. After that, they are handled as signed or unsigned 32 bit numbers, depending upon the instruction. The only difference between signed and unsigned instructions is that signed instructions can generate an overflow exception and unsigned instructions can not. The instruction descriptions are given below: ADD Add (with overflow) Adds two registers and stores the result in a register Operation: $d = $s + $t; advance_pc (4); add $d, $s, $t 0000 00ss ssst tttt dddd d000 0010 0000 ADDI -- Add immediate (with overflow) Adds a register and a sign-extended immediate value and stores the result in a register Operation: $t = $s + imm; advance_pc (4); addi $t, $s, imm 0010 00ss ssst tttt iiii iiii iiii iiii

Page 2 of 9 ADDIU -- Add immediate unsigned (no overflow) Adds a register and a sign-extended immediate value and stores the result in a register Operation: $t = $s + imm; advance_pc (4); addiu $t, $s, imm ADDU -- Add unsigned (no overflow) AND -- Bitwise and 0010 01ss ssst tttt iiii iiii iiii iiii Adds two registers and stores the result in a register Operation: $d = $s + $t; advance_pc (4); addu $d, $s, $t 0000 00ss ssst tttt dddd d000 0010 0001 Bitwise ands two registers and stores the result in a register Operation: $d = $s & $t; advance_pc (4); and $d, $s, $t 0000 00ss ssst tttt dddd d000 0010 0100 ANDI -- Bitwise and immediate Bitwise ands a register and an immediate value and stores the result in a register Operation: $t = $s & imm; advance_pc (4); andi $t, $s, imm 0011 00ss ssst tttt iiii iiii iiii iiii BEQ -- Branch on equal Branches if the two registers are equal Operation: if $s == $t advance_pc (offset << 2)); else advance_pc (4); beq $s, $t, offset 0001 00ss ssst tttt iiii iiii iiii iiii BGEZ -- Branch on greater than or equal to zero Branches if the register is greater than or equal to zero Operation: if $s >= 0 advance_pc (offset << 2)); else advance_pc (4); bgez $s, offset

Page 3 of 9 0000 01ss sss0 0001 iiii iiii iiii iiii BGEZAL -- Branch on greater than or equal to zero and link Branches if the register is greater than or equal to zero and saves the return address in $31 Operation: if $s >= 0 $31 = PC + 8 (or npc + 4); advance_pc (offset << 2)); else advance_pc (4); bgezal $s, offset 0000 01ss sss1 0001 iiii iiii iiii iiii BGTZ -- Branch on greater than zero Branches if the register is greater than zero Operation: if $s > 0 advance_pc (offset << 2)); else advance_pc (4); bgtz $s, offset 0001 11ss sss0 0000 iiii iiii iiii iiii BLEZ -- Branch on less than or equal to zero Branches if the register is less than or equal to zero Operation: if $s <= 0 advance_pc (offset << 2)); else advance_pc (4); blez $s, offset 0001 10ss sss0 0000 iiii iiii iiii iiii BLTZ -- Branch on less than zero Branches if the register is less than zero Operation: if $s < 0 advance_pc (offset << 2)); else advance_pc (4); bltz $s, offset 0000 01ss sss0 0000 iiii iiii iiii iiii BLTZAL -- Branch on less than zero and link Branches if the register is less than zero and saves the return address in $31 Operation: if $s < 0 $31 = PC + 8 (or npc + 4); advance_pc (offset << 2)); else advance_pc (4); bltzal $s, offset 0000 01ss sss1 0000 iiii iiii iiii iiii BNE -- Branch on not equal Branches if the two registers are not equal

Page 4 of 9 Operation: if $s!= $t advance_pc (offset << 2)); else advance_pc (4); bne $s, $t, offset 0001 01ss ssst tttt iiii iiii iiii iiii DIV -- Divide Divides $s by $t and stores the quotient in $LO and the remainder in $HI Operation: $LO = $s / $t; $HI = $s % $t; advance_pc (4); div $s, $t 0000 00ss ssst tttt 0000 0000 0001 1010 DIVU -- Divide unsigned Divides $s by $t and stores the quotient in $LO and the remainder in $HI Operation: $LO = $s / $t; $HI = $s % $t; advance_pc (4); divu $s, $t 0000 00ss ssst tttt 0000 0000 0001 1011 J -- Jump Jumps to the calculated address Operation: PC = npc; npc = (PC & 0xf0000000) (target << 2); j target JAL -- Jump and link JR -- Jump register LB -- Load byte 0000 10ii iiii iiii iiii iiii iiii iiii Jumps to the calculated address and stores the return address in $31 Operation: $31 = PC + 8 (or npc + 4); PC = npc; npc = (PC & 0xf0000000) (target << 2); jal target 0000 11ii iiii iiii iiii iiii iiii iiii Jump to the address contained in register $s Operation: jr $s PC = npc; npc = $s; 0000 00ss sss0 0000 0000 0000 0000 1000

Page 5 of 9 A byte is loaded into a register from the specified address. Operation: $t = MEM[$s + offset]; advance_pc (4); lb $t, offset($s) 1000 00ss ssst tttt iiii iiii iiii iiii LUI -- Load upper immediate The immediate value is shifted left 16 bits and stored in the register. The lower 16 bits are zeroes. Operation: $t = (imm << 16); advance_pc (4); lui $t, imm LW -- Load word 0011 11-- ---t tttt iiii iiii iiii iiii A word is loaded into a register from the specified address. Operation: $t = MEM[$s + offset]; advance_pc (4); lw $t, offset($s) 1000 11ss ssst tttt iiii iiii iiii iiii MFHI -- Move from HI The contents of register HI are moved to the specified register. Operation: $d = $HI; advance_pc (4); mfhi $d 0000 0000 0000 0000 dddd d000 0001 0000 MFLO -- Move from LO The contents of register LO are moved to the specified register. Operation: $d = $LO; advance_pc (4); mflo $d 0000 0000 0000 0000 dddd d000 0001 0010 MULT -- Multiply Multiplies $s by $t and stores the result in $LO. Operation: $LO = $s * $t; advance_pc (4); mult $s, $t 0000 00ss ssst tttt 0000 0000 0001 1000

Page 6 of 9 MULTU -- Multiply unsigned Multiplies $s by $t and stores the result in $LO. Operation: $LO = $s * $t; advance_pc (4); multu $s, $t 0000 00ss ssst tttt 0000 0000 0001 1001 NOOP -- no operation Performs no operation. Operation: advance_pc (4); noop 0000 0000 0000 0000 0000 0000 0000 0000 Note: The encoding for a NOOP represents the instruction SLL $0, $0, 0 which has no side effects. In fact, nearly every instruction that has $0 as its destination register will have no side effect and can thus be considered a NOOP instruction. OR -- Bitwise or Bitwise logical ors two registers and stores the result in a register Operation: $d = $s $t; advance_pc (4); or $d, $s, $t 0000 00ss ssst tttt dddd d000 0010 0101 ORI -- Bitwise or immediate Bitwise ors a register and an immediate value and stores the result in a register Operation: $t = $s imm; advance_pc (4); SB -- Store byte ori $t, $s, imm SLL -- Shift left logical 0011 01ss ssst tttt iiii iiii iiii iiii The least significant byte of $t is stored at the specified address. Operation: MEM[$s + offset] = (0xff & $t); advance_pc (4); sb $t, offset($s) 1010 00ss ssst tttt iiii iiii iiii iiii

Page 7 of 9 Shifts a register value left by the shift amount listed in the instruction and places the result in a third register. Zeroes are shifted in. Operation: $d = $t << h; advance_pc (4); sll $d, $t, h 0000 00ss ssst tttt dddd dhhh hh00 0000 SLLV -- Shift left logical variable Shifts a register value left by the value in a second register and places the result in a third register. Zeroes are shifted in. Operation: $d = $t << $s; advance_pc (4); sllv $d, $t, $s 0000 00ss ssst tttt dddd d--- --00 0100 SLT -- Set on less than (signed) If $s is less than $t, $d is set to one. It gets zero otherwise. Operation: if $s < $t $d = 1; advance_pc (4); else $d = 0; advance_pc (4); slt $d, $s, $t 0000 00ss ssst tttt dddd d000 0010 1010 SLTI -- Set on less than immediate (signed) If $s is less than immediate, $t is set to one. It gets zero otherwise. Operation: if $s < imm $t = 1; advance_pc (4); else $t = 0; advance_pc (4); slti $t, $s, imm 0010 10ss ssst tttt iiii iiii iiii iiii SLTIU -- Set on less than immediate unsigned If $s is less than the unsigned immediate, $t is set to one. It gets zero otherwise. Operation: if $s < imm $t = 1; advance_pc (4); else $t = 0; advance_pc (4); sltiu $t, $s, imm 0010 11ss ssst tttt iiii iiii iiii iiii SLTU -- Set on less than unsigned If $s is less than $t, $d is set to one. It gets zero otherwise. Operation: if $s < $t $d = 1; advance_pc (4); else $d = 0; advance_pc (4); sltu $d, $s, $t

Page 8 of 9 0000 00ss ssst tttt dddd d000 0010 1011 SRA -- Shift right arithmetic Shifts a register value right by the shift amount (shamt) and places the value in the destination register. The sign bit is shifted in. Operation: $d = $t >> h; advance_pc (4); sra $d, $t, h 0000 00-- ---t tttt dddd dhhh hh00 0011 SRL -- Shift right logical Shifts a register value right by the shift amount (shamt) and places the value in the destination register. Zeroes are shifted in. Operation: $d = $t >> h; advance_pc (4); srl $d, $t, h 0000 00-- ---t tttt dddd dhhh hh00 0010 SRLV -- Shift right logical variable Shifts a register value right by the amount specified in $s and places the value in the destination register. Zeroes are shifted in. Operation: $d = $t >> $s; advance_pc (4); srlv $d, $t, $s 0000 00ss ssst tttt dddd d000 0000 0110 SUB -- Subtract Subtracts two registers and stores the result in a register Operation: $d = $s - $t; advance_pc (4); sub $d, $s, $t 0000 00ss ssst tttt dddd d000 0010 0010 SUBU -- Subtract unsigned Subtracts two registers and stores the result in a register Operation: $d = $s - $t; advance_pc (4); subu $d, $s, $t 0000 00ss ssst tttt dddd d000 0010 0011 SW -- Store word

Page 9 of 9 The contents of $t is stored at the specified address. Operation: MEM[$s + offset] = $t; advance_pc (4); sw $t, offset($s) 1010 11ss ssst tttt iiii iiii iiii iiii SYSCALL -- System call Generates a software interrupt. Operation: advance_pc (4); syscall 0000 00-- ---- ---- ---- ---- --00 1100 The syscall instruction is described in more detail on the System Calls page. XOR -- Bitwise exclusive or Exclusive ors two registers and stores the result in a register Operation: $d = $s ^ $t; advance_pc (4); xor $d, $s, $t 0000 00ss ssst tttt dddd d--- --10 0110 XORI -- Bitwise exclusive or immediate Bitwise exclusive ors a register and an immediate value and stores the result in a register Operation: $t = $s ^ imm; advance_pc (4); xori $t, $s, imm 0011 10ss ssst tttt iiii iiii iiii iiii Updated on September 10, 1998