1. 2 6.1 Simple Procedure Calls jal: performs the control transfer (unconditional jump) to the starting address of procedure, while also saving the return.

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

The University of Adelaide, School of Computer Science
1 Procedure Calls, Linking & Launching Applications Lecture 15 Digital Design and Computer Architecture Harris & Harris Morgan Kaufmann / Elsevier, 2007.
Lecture 6: MIPS Instruction Set Today’s topic –Control instructions –Procedure call/return 1.
The University of Adelaide, School of Computer Science
Computer Architecture CSCE 350
MIPS Function Continued
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
 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.
Register Conventions (1/4) °CalleR: the calling function °CalleE: the function being called °When callee returns from executing, the caller needs to know.
ENEE350 Spring07 1 Ankur Srivastava University of Maryland, College Park Adapted from Computer Organization and Design, Patterson & Hennessy, © 2005.”
S. Barua – CPSC 440 CHAPTER 2 INSTRUCTIONS: LANGUAGE OF THE COMPUTER Goals – To get familiar with.
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/
CHAPTER 2 ISA Instructions (logical + procedure call)
The Stack Pointer and the Frame Pointer (Lecture #19) ECE 445 – Computer Organization The slides included herein were taken from the materials accompanying.
13/02/2009CA&O Lecture 04 by Engr. Umbreen Sabir Computer Architecture & Organization Instructions: Language of Computer Engr. Umbreen Sabir Computer Engineering.
Procedures 2a MIPS code examples Making Use of a Stack.
Lecture 18: 11/5/2002CS170 Fall CS170 Computer Organization and Architecture I Ayman Abdel-Hamid Department of Computer Science Old Dominion University.
Procedure Calls and the Stack (Lectures #18) ECE 445 – Computer Organization The slides included herein were taken from the materials accompanying Computer.
Adapted from Computer Organization and Design, Patterson & Hennessy, UCB ECE232: Hardware Organization and Design Part 7: MIPS Instructions III
Lecture 19: 11/7/2002CS170 Fall CS170 Computer Organization and Architecture I Ayman Abdel-Hamid Department of Computer Science Old Dominion University.
Computer Organization CS224 Fall 2012 Lessons 9 and 10.
FAMU-FSU College of Engineering 1 Computer Architecture EEL 4713/5764, Spring 2006 Dr. Michael Frank Module #7 – MIPS ISA, part 2: Procedures and Data.
Procedure (Method) Calls Ellen Spertus MCS 111 September 25, 2003.
Lecture 4: MIPS Instruction Set
MAL 3 - Procedures Lecture 13. MAL procedure call The use of procedures facilitates modular programming. Four steps to transfer to and return from a procedure:
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.
MIPS Subroutines Subroutine Call – jal subname Saves RA in $31 and jumps to subroutine entry label subname Subroutine Return – jr $31 Loads PC with return.
Function Calling. Mips Assembly Call and Return Steps for procedure calling –Save the return address –Jump to the procedure (function) –Execute the procedure.
DR. SIMING LIU SPRING 2016 COMPUTER SCIENCE AND ENGINEERING UNIVERSITY OF NEVADA, RENO Session 12 Procedure Calling.
Computer Architecture & Operations I
Rocky K. C. Chang Version 0.1, 25 September 2017
Lecture 5: Procedure Calls
MIPS Assembly Language Programming
MIPS Procedures.
Procedures (Functions)
Procedures (Functions)
Instructions - Type and Format
MIPS Procedures.
MIPS Instructions.
ECE232: Hardware Organization and Design
The University of Adelaide, School of Computer Science
MIPS Functions.
MIPS Functions.
Lecture 5: Procedure Calls
Logical and Decision Operations
MIPS Procedures.
Review.
10/4: Lecture Topics Overflow and underflow Logical operations
Part II Instruction-Set Architecture
Computer Instructions
Program and memory layout
Program and memory layout
Computer Architecture
Program and memory layout
Where is all the knowledge we lost with information? T. S. Eliot
Program and memory layout
MIPS Functions.
8/23/
Presentation transcript:

1

2 6.1 Simple Procedure Calls jal: performs the control transfer (unconditional jump) to the starting address of procedure, while also saving the return address in $ra.

3 procedure call 1.Put argument in places known to the procedue (register $a0 - $a3). 2.Transfer control to the procedure, saving the return address (jal). 3.Acquire storage space, if required, for use by the procedure. 4.Perform the desired task. 5.Put results in place known to the calling program (register $v0 - $v1) 6.Return control to calling point (jr) Applicable to procedure call that invokes maximal 4 words of arguments and 2 words of results.

4 Procedure convention A procedure can use registers $v0 - $v1 and $t0 - $t9 freely without having to save their original contents. Division of responsibility between the calling and called program –Caller-saved registers: $v0 - $v1, $t0 - $t9 A calling program should not expect any values placed in these 12 registers to remain unchanged. –Callee-saved registers: $a0 - $a3, $s0 - $s7, $gp, $sp, $fp, $ra A procedure (callee program) that modifies any of these must restore them to their original values before terminating.

5 Figure 6.2 Example of nested procedure calls. Nested Procedure call 1. Procedure abc puts arguments in $a0 - $a3 and save any useful data in $v0 - $v1, $t0 - $t9 2. After return from xyz, procedure abc may transfer to

6 Figure 6.3 Overview of the memory address space in MiniMIPS. 6.2 Using Stack for Data Storage Conventions for using memory address space in MiniMIPS: Second half: memory-mapped I/O First half: First 1M words: system use Next 63M words: text of the program being executed Beginning at 0x : program’s data segment Beginning 0x7ffffffc growing backward: stack

7 Figure 6.4 Effects of push and pop operations on a stack. Push: addi $sp, $sp,-4 sw $t4, 0($sp) Pop: lw $t5, 0($sp) addi $sp, $sp, 4

8 Figure 6.5 Use of the stack by a procedure. 6.3 Parameters and Results 1.How can we pass more than four input parameters to a procedure or receive more than two results? 2.Where does a procedure save its own parameters and intermediate results when calling another procedure (nested calls)?

9 6.4 Data Types MiniMIPS has the following data types:

10 Singed integer: 2’s-complement

11 Table 6.1 ASCII (American Standard Code for Information Interchange) 1, 2

12 Figure 6.6 Load and store instructions for byte-size data elements. Load byte, load byte unsigned, store byte lb$t0,8($s3)# load rt with byte mem[8+$s3]; # signed-extended to fill the register; lbu$t0,8($s3) # load rt with byte mem[8+$s3]; # zero-extended to fill the register; sb$t0,8($s3)# store byte 0 of rt to mem[8+$s3];

13 Figure 6.7 A 32-bit word has no inherent meaning and can be interpreted in a number of equally valid ways in the absence of other cues (e.g., context) for the intended meaning. A bit string, stored in memory or in a register, has no inherent meaning. It can mean different things depending on how it is interpreted.

14 Figure 6.8 Using the indexing method and the pointer updating method to step through the elements of an array. 6.5 Arrays and Pointers 1.Index: use a register that holds the index i and increment the register in each step to effect moving from element i of the list to element i+1. 2.Pointer: use a register that points to the list element being examined and update it in each step to point to the next element.

15 Figure 6.9 One iteration of selection sort. Example 6.4 Selection sort using a max-finding procedure

16 Figure 6.10 The multiply (mult) and divide (div) instructions of MiniMIPS. 6.6 Additional Instructions mult$s0, $s1# set Hi, Lo to ($s0)×($s0) div$s0, $s1# set Hi to ($s0) mod ($s0) # set Lo to ($s0) / ($s0)

17 Figure 6.11 MiniMIPS instructions for copying the contents of Hi and Lo registers into general registers. mfhi$t0# set $t0 to (Hi) mflo$t0, $s1# set $t0 to (Lo)

18 Figure 6.12 The four logical shift instructions of MiniMIPS. sll $t0, $s1, 2# $t0 = ($s1) left-shifted by 2 bits srl $t0, $s1, 2# $t0 = ($s1) right-shifted by 2 bits sllv $t0, $s1, $s0 # $t0 = ($s1) left-shifted by ($s0) srlv $t0, $s1, $s0 # $t0 = ($s1) right-shifted by ($s0) Shift instructions

19 Table 6.2 The 40 MiniMIPS instructions covered in Chapters 5–7.*

20