MIPS Instructions.

Slides:



Advertisements
Similar presentations
1 Lecture 3: MIPS Instruction Set Today’s topic:  More MIPS instructions  Procedure call/return Reminder: Assignment 1 is on the class web-page (due.
Advertisements

Branches Two branch instructions:
Slides revised 3/25/2014 by Patrick Kelley. 2 Procedures Unlike other branching structures (loops, etc.) a Procedure has to return to where it was called.
©UCB CS 161 Lecture 4 Prof. L.N. Bhuyan
1 Procedure Calls, Linking & Launching Applications Lecture 15 Digital Design and Computer Architecture Harris & Harris Morgan Kaufmann / Elsevier, 2007.
1 Lecture 4: Procedure Calls Today’s topics:  Procedure calls  Large constants  The compilation process Reminder: Assignment 1 is due on Thursday.
Computer Architecture CSCE 350
1 Nested Procedures Procedures that don't call others are called leaf procedures, procedures that call others are called nested procedures. Problems may.
CPS3340 COMPUTER ARCHITECTURE Fall Semester, /17/2013 Lecture 12: Procedures Instructor: Ashraf Yaseen DEPARTMENT OF MATH & COMPUTER SCIENCE CENTRAL.
Procedures II (1) Fall 2005 Lecture 07: Procedure Calls (Part 2)
The University of Adelaide, School of Computer Science
Apr. 12, 2000Systems Architecture I1 Systems Architecture I (CS ) Lecture 6: Branching and Procedures in MIPS* Jeremy R. Johnson Wed. Apr. 12, 2000.
The University of Adelaide, School of Computer Science
Procedure call frame: Hold values passed to a procedure as arguments
Lecture 8: MIPS Instruction Set
 Procedures (subroutines) allow the programmer to structure programs making them : › easier to understand and debug and › allowing code to be reused.
MIPS Coding. Exercise – the bubble sort 5/8/2015week04-3.ppt2.
Informationsteknologi Saturday, September 29, 2007 Computer Architecture I - Class 41 Today’s class More assembly language programming.
1 Storage Registers vs. memory Access to registers is much faster than access to memory Goal: store as much data as possible in registers Limitations/considerations:
ENEE350 Spring07 1 Ankur Srivastava University of Maryland, College Park Adapted from Computer Organization and Design, Patterson & Hennessy, © 2005.”
Intro to Computer Architecture
Computer Structure - The Instruction Set (2) Goal: Implement Functions in Assembly  When executing a procedure (function in C) the program must follow.
S. Barua – CPSC 440 CHAPTER 2 INSTRUCTIONS: LANGUAGE OF THE COMPUTER Goals – To get familiar with.
28/06/2015CMPUT Functions (2)  Function calling convention  Various conventions available  One is specified by CMPUT229  Recursive functions.
COMPUTER ARCHITECTURE & OPERATIONS I Instructor: Hao Ji.
Lecture 7: MIPS Instruction Set Today’s topic –Procedure call/return –Large constants Reminders –Homework #2 posted, due 9/17/
13/02/2009CA&O Lecture 04 by Engr. Umbreen Sabir Computer Architecture & Organization Instructions: Language of Computer Engr. Umbreen Sabir Computer Engineering.
Functions and Procedures. Function or Procedure u A separate piece of code u Possibly separately compiled u Located at some address in the memory used.
Lecture 18: 11/5/2002CS170 Fall CS170 Computer Organization and Architecture I Ayman Abdel-Hamid Department of Computer Science Old Dominion University.
Lecture 19: 11/7/2002CS170 Fall CS170 Computer Organization and Architecture I Ayman Abdel-Hamid Department of Computer Science Old Dominion University.
6.S078 - Computer Architecture: A Constructive Approach Introduction to SMIPS Li-Shiuan Peh Computer Science & Artificial Intelligence Lab. Massachusetts.
Procedure (Method) Calls Ellen Spertus MCS 111 September 25, 2003.
April 23, 2001Systems Architecture I1 Systems Architecture I (CS ) Lecture 9: Assemblers, Linkers, and Loaders * Jeremy R. Johnson Mon. April 23,
Lecture 4: MIPS Instruction Set
Computer Architecture CSE 3322 Lecture 4 crystal.uta.edu/~jpatters/cse3322 Assignments due 9/15: 3.7, 3.9, 3.11.
Computer Architecture CSE 3322 Lecture 4 Assignment: 2.4.1, 2.4.4, 2.6.1, , Due 2/10/09
Chapter 2 — Instructions: Language of the Computer — 1 Conditional Operations Branch to a labeled instruction if a condition is true – Otherwise, continue.
Function Calling. Mips Assembly Call and Return Steps for procedure calling –Save the return address –Jump to the procedure (function) –Execute the procedure.
CMPUT Computer Organization and Architecture I1 CMPUT229 - Fall 2003 Topic4: Procedures José Nelson Amaral.
Computer Architecture & Operations I
Rocky K. C. Chang Version 0.1, 25 September 2017
Storage Classes There are three places in memory where data may be placed: In Data section declared with .data in assembly language in C - Static) On the.
Computer Science 210 Computer Organization
Computer structure: Procedure Calls
MIPS Assembly Language Programming
Procedures 101: There and Back Again
MIPS Procedures.
Lecture 4: MIPS Instruction Set
RISC Concepts, MIPS ISA Logic Design Tutorial 8.
Procedures (Functions)
Functions and Procedures
Instructions - Type and Format
MIPS Procedures.
Lecture 4: MIPS Instruction Set
MIPS Instruction Encoding
The University of Adelaide, School of Computer Science
MIPS Functions.
MIPS Instruction Encoding
MIPS Functions.
Lecture 5: Procedure Calls
MIPS Procedures.
Review.
MIPS Functions.
Procedures and Calling Conventions
Computer Architecture
Where is all the knowledge we lost with information? T. S. Eliot
Procedure Support From previous study of high-level languages, we know the basic issues: - declaration: header, body, local variables - call and return.
MIPS Functions.
MIPS function continued
MIPS Functions.
Presentation transcript:

MIPS Instructions

J-type Instruction Encoding 12/1/2018 J-type Instruction Encoding We have jump and jump-and-link instructions Note that we have 26 bits for the target fields, which represents the number of instructions (words) instead of bytes In terms of bytes, it represents 28 bits in terms of bytes But PC requires 32 bits Where do we get the other 4 bits? 12/1/2018 week04-3.ppt CDA3100

J-type Instruction Encoding 12/1/2018 J-type Instruction Encoding Pseudo-direct addressing In J-type instructions, the jump address is formed by upper 4 bits of the current PC, 26 bits of the target address field in the instruction, and two bits of 0’s What is the largest program a J-type instruction works properly? 12/1/2018 week04-3.ppt CDA3100

12/1/2018 Peek into the Future 12/1/2018 week04-3.ppt CDA3100

Jump Register Instruction 12/1/2018 Jump Register Instruction Jump register (jr) Unconditionally jump to the address given by register rs 12/1/2018 week04-3.ppt CDA3100

12/1/2018 Big Immediates We know that we can use 16-bit immediate numbers in MIPS instructions such as addi What about large numbers? We also need to load 32 bit addresses in order to use jr Load address (la) Load the address of a label into the register (note: not the content of the address) 12/1/2018 week04-3.ppt CDA3100

MIPS Addressing for 32-bit Immediates 12/1/2018 MIPS Addressing for 32-bit Immediates In MIPS, the immediate field has 16 bits In order to handle 32-bit immediate operands, the MIPS includes load upper immediate (lui) Which sets the upper 16 bits of a constant in a register and fills the lower 16 bits with 0’s Then one can set the lower 16 bits using ori 12/1/2018 week04-3.ppt CDA3100

Example To load the following 32-bit constant in $s0, 12/1/2018 Example To load the following 32-bit constant in $s0, We first need to do lui $s0, 61 Why? Then we need to do ori $s0, $s0, 35072 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 12/1/2018 week04-3.ppt CDA3100

12/1/2018 Branching Far Away Note that for conditional branch instructions the offset is 16 bits What can we do if the branch is further away than the 16-bit offset can represent? 12/1/2018 week04-3.ppt CDA3100

12/1/2018 Branching Far Away Note that for conditional branch instructions the offset is 16 bits What can we do if the branch is further away than the 16-bit offset can represent? We can replace it using a pair of instructions bne $s0, $s1, L2 j L1 L2: 12/1/2018 week04-3.ppt CDA3100

MIPS Assembly Instructions 12/1/2018 MIPS Assembly Instructions 12/1/2018 week04-3.ppt CDA3100 week04-3.ppt

Procedures and Functions 12/1/2018 Procedures and Functions We programmers use procedures and functions to structure and organize programs To make them easier to understand To allow code to be reused 12/1/2018 week04-3.ppt CDA3100 week04-3.ppt

12/1/2018 A Simple Example Note that there are steps involved in the calling function as well as in the one being called 12/1/2018 week04-3.ppt CDA3100 week04-3.ppt

MIPS Calling Conventions 12/1/2018 MIPS Calling Conventions MIPS assembly follows the following convention in using registers $a0 - $a3: four argument registers in which to pass parameters $v0 - $v1: two value registers in which to return values $ra: one return address register to return to the point of origin 12/1/2018 week04-3.ppt CDA3100 week04-3.ppt

12/1/2018 Registers Remember that the same registers are used by both the caller and callee What do we need to do in order to guarantee the correctness of the program? For the following code for example, what do we need to do? 12/1/2018 week04-3.ppt CDA3100 week04-3.ppt

12/1/2018 Register Spilling The callee has to save all the registers it uses and restore the values before it returns By storing them on the stack At the beginning Then restoring them At the end 12/1/2018 week04-3.ppt CDA3100 week04-3.ppt

12/1/2018 Simple Example 12/1/2018 week04-3.ppt CDA3100 week04-3.ppt

The Stack Pointer 12/1/2018 12/1/2018 week04-3.ppt CDA3100 week04-3.ppt

MIPS Calling Conventions - more 12/1/2018 MIPS Calling Conventions - more MIPS software divides 18 of the registers into two groups $t0 - $t9: 10 temporary registers that are not preserved by the callee on a procedure call These are caller-saved registers since the caller must save the ones it is using $s0 - $s7: 8 saved registers that must be preserved on a procedure call These are callee-saved registers since the callee must save the ones it uses 12/1/2018 week04-3.ppt CDA3100 week04-3.ppt

Caller Must Do Before it calls a procedure/function, it must 12/1/2018 Caller Must Do Before it calls a procedure/function, it must Pass parameters Up to four parameters are passed by $a0 - $a3 Save caller-saved registers on the stack It includes $a0 - $a3 (since the callee may change these values), $s0 - $s9, and $ra Why $ra? Execute a jal instruction, which jumps to the callee’s first instruction and save the next instruction in $ra 12/1/2018 week04-3.ppt CDA3100 week04-3.ppt

Caller Must Do – cont. After the procedure/function call, it needs to 12/1/2018 Caller Must Do – cont. After the procedure/function call, it needs to Read the returned values from $v0 and $v1 Restore caller-saved registers 12/1/2018 week04-3.ppt CDA3100 week04-3.ppt

12/1/2018 Callee Must Do Before it does its calculations, the callee must do the following Allocate memory for its frame by subtracting its frame size from the stack pointer Save callee-saved registers in the frame It must save $s0 - $s7, $fp, $ra before changing them $ra needs to be saved if the callee itself makes a call When needed, establish the frame pointer $fp by loading $sp to it In this case, $fp must be saved 12/1/2018 week04-3.ppt CDA3100 week04-3.ppt

Allocating Space for Local Data on Stack 12/1/2018 Allocating Space for Local Data on Stack In MIPS, local variables are also stored on the stack The segment of the stack containing a procedure’s saved registers and local variables is called a procedure frame (or activation record) 12/1/2018 week04-3.ppt CDA3100 week04-3.ppt

12/1/2018 Callee Must Do After its calculations and before it returns to the caller, the callee must Place the return values in $v0 and $v1 (if needed) Restore all the callee-saved registers that were saved at the procedure entry Pop the stack frame by adding the frame size to $sp Return by jumping to the address in register $ra using jr 12/1/2018 week04-3.ppt CDA3100 week04-3.ppt

12/1/2018 Earlier Example 12/1/2018 week04-3.ppt CDA3100 week04-3.ppt

12/1/2018 Revised Version 12/1/2018 week04-3.ppt CDA3100 week04-3.ppt