The MIPS Instruction Set Architecture

Similar documents
MIPS Assembly Language. Today s Lecture

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

Computer Architecture. The Language of the Machine

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

Reduced Instruction Set Computer (RISC)

Reduced Instruction Set Computer (RISC)

MIPS Instruction Reference

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

F. Appendix 6 MIPS Instruction Reference

MIPS Reference Guide

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

MIPS Instruction Set

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

M2 Instruction Set Architecture

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

Computer Architecture. MIPS Instruction Set Architecture

MIPS Instruction Format

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

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

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

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

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

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

EE 109 Unit 8 MIPS Instruction Set

TSK3000A - Generic Instructions

CS 4200/5200 Computer Architecture I

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

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

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

EE108B Lecture 3. MIPS Assembly Language II

CISC 662 Graduate Computer Architecture. Lecture 4 - ISA

Anne Bracy CS 3410 Computer Science Cornell University. See P&H Chapter: , , Appendix B

ECE468 Computer Organization & Architecture. MIPS Instruction Set Architecture

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

Assembly Programming

COMP3211/COMP9211 Computer Architecture. Lecturer: Sri Parameswaran LiC: Oliver Diessel Demonstrators: Liang Tang & George Gong

Mips Code Examples Peter Rounce

CS3350B Computer Architecture MIPS Instruction Representation

MIPS%Assembly% E155%

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

Concocting an Instruction Set

CPS311 - COMPUTER ORGANIZATION. A bit of history

SPIM Instruction Set

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

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

Flow of Control -- Conditional branch instructions

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

Computer Organization & Design

Computer Architecture

Examples of branch instructions

CMPE324 Computer Architecture Lecture 2

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

INSTRUCTION SET COMPARISONS

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

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

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

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

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

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

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

Concocting an Instruction Set

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

Week 10: Assembly Programming

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

Character Is a byte quantity (00~FF or 0~255) ASCII (American Standard Code for Information Interchange) Page 91, Fig. 2.21

ISA and RISCV. CASS 2018 Lavanya Ramapantulu

ece4750-parc-isa.txt

Digital System Design II

Project Part A: Single Cycle Processor

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

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

Midterm Questions Overview

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

Instruction Set Architecture. "Speaking with the computer"

Instructions: MIPS ISA. Chapter 2 Instructions: Language of the Computer 1

Lecture 2. Instructions: Language of the Computer (Chapter 2 of the textbook)

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

COMPSCI 313 S Computer Organization. 7 MIPS Instruction Set

Instruction Set Principles. (Appendix B)

MIPS Assembly Language Programming

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

MIPS Assembly Language

Exam in Computer Engineering

Introduction to the MIPS. Lecture for CPSC 5155 Edward Bosworth, Ph.D. Computer Science Department Columbus State University

Arithmetic for Computers

Instruction Set Design and Architecture

Review: MIPS Organization

Concocting an Instruction Set

ECE260: Fundamentals of Computer Engineering

ICS 233 COMPUTER ARCHITECTURE. MIPS Processor Design Multicycle Implementation

CSc 256 Midterm 2 Fall 2011

Chapter 2. Computer Abstractions and Technology. Lesson 4: MIPS (cont )

Unsigned Binary Integers

Unsigned Binary Integers

Concocting an Instruction Set

Midterm Questions Overview

ENGN1640: Design of Computing Systems Topic 03: Instruction Set Architecture Design

Chapter 2. Instructions: Language of the Computer. Adapted by Paulo Lopes

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

Lecture 3: Instruction Set Architecture

Transcription:

The MIPS Set Architecture CPS 14 Lecture 5 Today s Lecture Admin HW #1 is due HW #2 assigned Outline Review A specific ISA, we ll use it throughout semester, very similar to the NiosII ISA (we will use for programs) categories Specific s Reading Chapter 2, Appendix A (on CD), The Nios Soft Processor Sections 3, 5-8 CPS 14 2

Accumulator: Review: Basic ISA Classes 1 address add A acc acc + mem[a] 1+x address addx A acc acc + mem[a + x] Stack: address add tos tos + next (JAVA VM) General Purpose Register: 2 address add A B A A + B 3 address add A B C A B + C Load/Store: 3 address add Ra Rb Rc Ra Rb + Rc load Ra Rb Ra mem[rb] store Ra Rb mem[rb] Ra CPS 14 3 Review: LOAD / STORE ISA set: add, sub, mult, div, only on operands in registers ld, st, to move data from and to memory, only way to access memory Example: a*b - (a+c*b) (assume in memory) r1, r2, r3 ld r1, c 2,?,? ld r2, b 2, 3,? a bc mult r1, r1, r2 6, 3,? ld r3, a 6, 3, 4 add r1, r1, r3 1, 3, 4 mult r2, r2, r3 1, 12, 4 sub r3, r2, r1 1, 12, 2 7 instructions 4 3 2 CPS 14 4

Using Registers to Access Memory Registers can hold memory addresses Given int x; int *p; p = &x; *p = *p + 8; s ld r1, p // r1 <- mem[p] ld r2, r1 // r2 <- mem[r1] add r2, r2, x8 // increment x by 8 st r1, r2 // mem[r1] <- r2 Many different ways to address operands not all sets include all modes x x26cf... p x26d x26cbf CPS 14 5 Making s Machine Readable So far, still too abstract add r1, r2, r3 Need to specify instructions in machine readable form Bunch of Bits s are bits with well defined fields Like a floating point number has different fields Format establishes a mapping from instruction to binary values which bit positions correspond to which parts of the instruction (operation, operands, etc.) CPS 14 6

Example: MIPS Register-Register 31 26 25 21 2 16 15 11 1 6 5 Op Rs1 Register-Immediate Rs2 31 26 25 21 2 16 15 Op Rs1 Rd immediate Branch 31 26 25 Op target Rd Opx 31 26 25 21 2 16 15 Op Rs1 Rs2/Opx immediate Jump / Call CPS 14 7 Stored Program Computer s: a fixed set of built-in operations s and data are stored in the (same) computer memory Fetch-Execute Cycle while (!done) fetch instruction execute instruction This is done by the hardware for speed This is what the NiosII Set Simulator does CPS 14 8

What Must be Specified? Fetch Decode Operand Fetch Execute Result Store Next Format how do we tell what operation to perform? Location of operands and result where other than memory? how many explicit operands? how are memory operands located? which can or cannot be in memory? Data type and Size Operations what are supported Successor instruction jumps, conditions, branches fetch-decode-execute is implicit! CPS 14 9 MIPS ISA Categories Arithmetic add, sub, mul, etc Logical and, or, shift Data Transfer load, store MIPS is LOAD/STORE architecture Conditional Branch implement if, for, while statements Unconditional Jump support method invocation (function call, procedure calls) CPS 14 1

MIPS set Architecture 3-Address Load/Store Architecture. Register and Immediate addressing modes for operations. Immediate and Displacement addressing for Loads and Stores. Examples (Assembly Language): add $1, $2, $3 # $1 = $2 + $3 addi $1, $1, 4 # $1 = $1 + 4 lw $1, 1 ($2) # $1 = Memory[$2 + 1] sw $1, 1 ($2) # Memory[$2 + 1] = $1 lui $1, 1 # $1 = 1 X 216 addi $1, $3, 1 # $1 = $3 + 1 CPS 14 11 MIPS Integer Registers Registers: fast memory, Integral part of the CPU. Programmable storage 2 32 bytes 31 x 32-bit GPRs (R = ) 32 x 32-bit FP regs (paired DP) 32-bit HI, LO, PC r r1 r31 PC lo hi CPS 14 12

MIPS Formats R-type: Register-Register 31 26 25 21 2 16 15 11 1 6 5 Op I-type: Register-Immediate Rs Rt Rd shamt func 31 26 25 21 2 16 15 Op Rs Rt immediate J-type: Jump / Call 31 26 25 Op target Terminology Op = opcode Rs, Rt, Rd = register specifier CPS 14 13 NiosII Formats R-type: Register-Register 31 27 26 22 21 17 16 6 5 A I-type: Register-Immediate J-type: Jump / Call B C OPX Op 31 27 26 22 21 6 5 A B IMMED16 Op 31 6 5 IMMED26 Terminology Op = opcode Rs, Rt, Rd = register specifier Op CPS 14 14

R Type: <OP> rd, rs, rt 31 26 25 21 2 16 15 11 1 6 5 Op Rs Rt Rd shmt func op rs rt rd shmt func a 6-bit operation code. a 5-bit source register. a 5-bit target (source) register. a 5-bit destination register. a 5-bit shift amount. a 6-bit function field. Operand Addressing: Register direct Example: ADD $1, $2, $3 # $1 = $2 + $3 op rs rt rd shmt func 1 11 1 1 CPS 14 15 I-Type <op> rt, rs, immediate 31 26 25 21 2 16 15 Op Rs Rt Immediate Immediate: 16 bit value Operand Addressing: Register Direct and Immediate Add Immediate Example addi $1, $2, 1 # $1 = $2 + 1 op rs rt immediate 1 1 1 11 1 CPS 14 16

I-Type <op> rt, rs, immediate 31 26 25 21 2 16 15 Op Rs Rt Immediate Register + Memory Base+index Register Load Word Example lw $1, 1($2) # $1 = Mem[$2+1] op rs rt immediate 111 1 1 11 1 CPS 14 17 Successor Fetch Decode Operand Fetch Execute main() { int x,y,same; // $ == always x = 43; // addi $1, $, 43 y = 2; // addi $2, $, 2 same = ; // addi $3, $, if (x == y) same = 1; // execute only if x == y // addi $3, $, 1 } Result Store Next CPS 14 18

The Program Counter (PC) Special register (PC) that points to instructions Contains memory address (like a pointer) fetch is inst = mem[pc] To fetch next sequential instruction PC = PC +? Size of instruction? CPS 14 19 The Program Counter x = 43; // addi $1, $, 43 y = 2; // addi $2, $, 2 same = ; // addi $3, $, if (x == y) same = 1; // addi $3, $, 1 execute if x == y PC is always automatically incremented to next instruction PC x1 x14 x18 x1c Memory x1 addi $1, $, 43 x14 addi $2, $, 2 x18 addi $3, $, x1c addi $3, $, 1 Clearly, this is not correct We cannot always execute both x18 and x1c CPS 14 2

I-Type <op> rt, rs, immediate 31 26 25 21 2 16 15 Op Rs Rt Immediate PC + + Memory PC relative addressing Branch Not Equal Example bne $1, $2, 1 # If ($1!= $2) goto [PC+4+1] +4 because by default we increment for sequential more detailed discussion later in semester op rs rt immediate 11 1 1 11 1 4 CPS 14 21 The Program Counter x = 43; // addi $1, $, 43 y = 2; // addi $2, $, 2 same = ; // addi $3, $, if (x == y) same = 1; // addi $3, $, $1 execute if x == y x = x + y; // addi $1, $1, $2 PC x1 x14 x18 x1c x114 x1 x14 x18 addi $1, $, 43 addi $2, $, 2 addi $3, $, x1c bne $1, $2, 4 x11 addi $3, $, 1 x114 addi $1, $1, $2 Understand branches CPS 14 22

Successor Fetch Decode Operand Fetch Execute Result Store Next int equal(int a1, int a2) { int tsame; tsame = ; if (a1 == a2) tsame = 1; // only if a1 == a2 return(tsame); } main() { int x,y,same; // r == always x = 43; // addi $1, $, 43 y = 2; // addi $2, $, 2 same = equal(x,y); // need to call function // other computation } CPS 14 23 The Program Counter Branches are limited to 16 bit immediate Big programs? x = 43; // addi $1, $, 43 y = 2; // addi $2, $, 2 same = equal(x,y); x1 x14 x18 addi $1, $, 43 addi $2, $, 2 go execute equal x348 addi $3, $, x34c beq $1, $2, 8 x341 addi $3, $, 1 return $3 CPS 14 24

J-Type: <op> target 31 26 Op Target Address PC $31 + 4 Jump and Link Example JAL 1 # PC<- 1, $31<-PC+4 $31 set as side effect, used for returning, implicit operand op Target 11 11 111 1 CPS 14 25 R Type: <OP> rd, rs, rt 31 26 25 21 2 16 15 11 1 6 5 Op Rs Rt Rd shamt func Jump Register Example jr $31 # PC <- $31 op rs rt rd shmt func 1 1 1 1 CPS 14 26

s for Procedure Call and Return int equal(int a1, int a2) { int tsame; tsame = ; if (a1 == a2) tsame = 1; return(tsame); } main() { int x,y,same; x = 43; y = 2; same = equal(x,y); // other computation } x1 x14 x18 addi $1, $, 43 addi $2, $, 2 jal x348 x1c?? x348 addi $3, $, x34c bne $1, $2, 4 x341 addi $3, $, 1 x3414 jr $31 PC $31 x1?? x14?? x18?? x348 x1c x34c x1c x341 x1c x3414 x1c x1c x1c CPS 14 27 MIPS Arithmetic s Example Meaning Comments add add $1,$2,$3 $1 = $2 + $3 3 operands subtract sub $1,$2,$3 $1 = $2 $3 3 operands add immediate addi $1,$2,1 $1 = $2 + 1 + constant add unsigned addu $1,$2,$3 $1 = $2 + $3 3 operands subtract unsigned subu $1,$2,$3 $1 = $2 $3 3 operands add imm. unsign. addiu $1,$2,1 $1 = $2 + 1 + constant multiply mult $2,$3 Hi, Lo = $2 x $3 64-bit signed product multiply unsigned multu $2,$3 Hi, Lo = $2 x $3 64-bit unsigned product divide div $2,$3 Lo = $2 $3, Lo = quotient, Hi = $2 mod $3 Hi = remainder divide unsigned divu $2,$3 Lo = $2 $3, Unsigned quotient Hi = $2 mod $3 Usigned remainder Move from Hi mfhi $1 $1 = Hi Used to get copy of Hi Move from Lo mflo $1 $1 = Lo Used to get copy of Lo Which add for address arithmetic? Which for integers? CPS 14 28

MIPS Logical s Example Meaning Comment and and $1,$2,$3 $1 = $2 & $3 Bitwise AND or or $1,$2,$3 $1 = $2 $3 Bitwise OR xor xor $1,$2,$3 $1 = $2 $3 Bitwise XOR nor nor $1,$2,$3 $1 = ~($2 $3) Bitwise NOR and immediate andi $1,$2,1 $1 = $2 & 1 Bitwise AND reg, const or immediate ori $1,$2,1 $1 = $2 1 Bitwise OR reg, const xor immediate xori $1, $2,1 $1 = ~$2 &~1 Bitwise XOR reg, const shift left logical sll $1,$2,1 $1 = $2 << 1 Shift left by constant shift right logical srl $1,$2,1 $1 = $2 >> 1 Shift right by constant shift right arithm. sra $1,$2,1 $1 = $2 >> 1 Shift right (sign extend) shift left logical sllv $1,$2,$3 $1 = $2 << $3 Shift left by var shift right logical srlv $1,$2, $3 $1 = $2 >> $3 Shift right by var shift right arithm. srav $1,$2, $3 $1 = $2 >> $3 Shift right arith. by var CPS 14 29 MIPS Data Transfer s SW R3, 5(R4) SH R3, 52(R2) SB R2, 41(R3) Comment Store word Store half Store byte LW R1, 3(R2) Load word LH R1, 4(R3) Load halfword LHU R1, 4(R3) Load halfword unsigned LB R1, 4(R3) Load byte LBU R1, 4(R3) Load byte unsigned LUI R1, 4 Load Upper Immediate (16 bits shifted left by 16) Why do we need LUI? LUI R5 R5 CPS 14 3

Compare and Branch MIPS Compare and Branch beq rs, rt, offset if R[rs] == R[rt] then PC-relative branch bne rs, rt, offset <> Compare to zero and Branch blez rs, offset if R[rs] <= then PC-relative branch bgtz rs, offset > bltz rs, offset < bgez rs, offset >= bltzal rs, offset if R[rs] < then branch and link (into R 31) bgeal rs, offset >= Remaining set of compare and branch take two instructions Almost all comparisons are against zero! CPS 14 31 MIPS jump, branch, compare instructions Example Meaning branch on equal beq $1,$2,1 if ($1 == $2) go to PC+4+1 Equal test; PC relative branch branch on not eq. bne $1,$2,1 if ($1!= $2) go to PC+4+1 Not equal test; PC relative set on less than slt $1,$2,$3 if ($2 < $3) $1=1; else $1= Compare less than; 2 s comp. set less than imm. slti $1,$2,1 if ($2 < 1) $1=1; else $1= Compare < constant; 2 s comp. set less than uns. sltu $1,$2,$3 if ($2 < $3) $1=1; else $1= Compare less than; natural numbers set l. t. imm. uns. sltiu $1,$2,1 if ($2 < 1) $1=1; else $1= Compare < constant; natural numbers jump j 1 go to 1 Jump to target address jump register jr $31 go to $31 For switch, procedure return jump and link jal 1 $31 = PC + 4; go to 1 For procedure call CPS 14 32

Signed v.s. Unsigned Comparison R1= 1 R2= 1 R3= 1 11 1111 1111 1111 1111 After executing these instructions: slt r4,r2,r1 slt r5,r3,r1 sltu r6,r2,r1 sltu r7,r3,r1 What are values of registers r4 - r7? Why? r4 = ; r5 = ; r6 = ; r7 = ; CPS 14 33 Summary MIPS has 5 categories of instructions Arithmetic, Logical, Data Transfer, Conditional Branch, Unconditional Jump 3 Formats NiosII Soft Processor and ISA Reference Next Time Assembly Programming Reading Ch. 2, Appendix A, NiosII Soft Processor HW #2 CPS 14 34