Computer Organization CS345 David Monismith Based upon notes by Dr. Bill Siever and notes from the Patterson and Hennessy Text.

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

1 Procedure Calls, Linking & Launching Applications Lecture 15 Digital Design and Computer Architecture Harris & Harris Morgan Kaufmann / Elsevier, 2007.
10/6: Lecture Topics Procedure call Calling conventions The stack
Lecture 6: MIPS Instruction Set Today’s topic –Control instructions –Procedure call/return 1.
Computer Architecture CSCE 350
CPS3340 COMPUTER ARCHITECTURE Fall Semester, /17/2013 Lecture 12: Procedures Instructor: Ashraf Yaseen DEPARTMENT OF MATH & COMPUTER SCIENCE CENTRAL.
Ch. 8 Functions.
CS1104 – Computer Organization PART 2: Computer Architecture Lecture 4 Assembly Language Programming 2.
Procedures II (1) Fall 2005 Lecture 07: Procedure Calls (Part 2)
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
Computer Organization CS345 David Monismith Based upon notes by Dr. Bill Siever and notes from the Patternson and Hennessy Text.
CSCI-365 Computer Organization Lecture Note: Some slides and/or pictures in the following are adapted from: Computer Organization and Design, Patterson.
Computer Organization. This module surveys the physical resources of a computer system. –Basic components CPUMemoryBus I/O devices –CPU structure Registers.
1 Sec (2.3) Program Execution. 2 In the CPU we have CU and ALU, in CU there are two special purpose registers: 1. Instruction Register 2. Program Counter.
Computer Science 210 Computer Organization The Instruction Execution Cycle.
Computer Organization - Syscalls David Monismith Jan. 28, 2015 Based on notes from Patterson and Hennessy Text and from Dr. Bill Siever.
CHAPTER 2 ISA Instructions (logical + procedure call)
CS-2710 Dr. Mark L. Hornick 1 Defining and calling procedures (subroutines) in assembly And using the Stack.
MIPS R3000 Subroutine Calls and Stack Department of Computer Science Southern Illinois University Edwardsville Fall, 2015 Dr. Hiroshi Fujinoki
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.
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.
Procedure Basics Computer Organization I 1 October 2009 © McQuain, Feng & Ribbens Procedure Support From previous study of high-level languages,
April 23, 2001Systems Architecture I1 Systems Architecture I (CS ) Lecture 9: Assemblers, Linkers, and Loaders * Jeremy R. Johnson Mon. April 23,
Computer Organization CS345 David Monismith Based upon notes by Dr. Bill Siever and notes from the Patternson and Hennessy Text.
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:
ITCS 3181 Logic and Computer Systems 2015 B. Wilkinson Slides4-2.ppt Modification date: March 23, Procedures Essential ingredient of high level.
More on Pipelining 1 CSE 2312 Computer Organization and Assembly Language Programming Vassilis Athitsos University of Texas at Arlington.
Computer Organization CS345 David Monismith Based upon notes by Dr. Bill Siever and notes from the Patterson and Hennessy Text.
CS61C L20 Datapath © UC Regents 1 Microprocessor James Tan Adapted from D. Patterson’s CS61C Copyright 2000.
More on Pipelining 1 CSE 2312 Computer Organization and Assembly Language Programming Vassilis Athitsos University of Texas at Arlington.
Computer Organization CS345 David Monismith Based upon notes by Dr. Bill Siever and notes from the Patterson and Hennessy Text.
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.
LECTURE 19 Subroutines and Parameter Passing. ABSTRACTION Recall: Abstraction is the process by which we can hide larger or more complex code fragments.
Computer Organization CS345 David Monismith Based upon notes by Dr. Bill Siever and notes from the Patterson and Hennessy Text.
Computer Organization CS345 David Monismith Based upon notes by Dr. Bill Siever and notes from the Patternson and Hennessy Text.
Computer Science 210 Computer Organization
Computer structure: Procedure Calls
Lecture 5: Procedure Calls
© Craig Zilles (adapted from slides by Howard Huang)
CSCI206 - Computer Organization & Programming
MIPS Procedures.
Procedures (Functions)
Functions and Procedures
Computer Science 210 Computer Organization
Instructions - Type and Format
Computer Science 210 Computer Organization
CSCI206 - Computer Organization & Programming
MIPS Procedures.
MIPS Instructions.
The University of Adelaide, School of Computer Science
MIPS Functions.
MIPS Functions.
Lecture 5: Procedure Calls
Logical and Decision Operations
MIPS Procedures.
MIPS Functions.
Procedures and Calling Conventions
© Craig Zilles (adapted from slides by Howard Huang)
MIPS Functions.
MIPS Functions.
MIPS R3000 Subroutine Calls and Stack
Topic 2b ISA Support for High-Level Languages
Presentation transcript:

Computer Organization CS345 David Monismith Based upon notes by Dr. Bill Siever and notes from the Patterson and Hennessy Text

Overview Last time we looked at – Program Counter – The fetch-decode-execute cycle – Assembly instruction and data memory locations This time, we'll – Review the fetch-decode-execute cycle and memory – Begin coverage of functions, the stack pointer, and the general pointer loops and functions

Program Counter Recall The Program Counter (PC) is a special register that stores the memory location of the next instruction to run. Instructions are executed in the following manner: 1.The address of the next instruction to run is retrieved from the PC 2.The instruction is retrieved (fetched) from instruction memory. 3.The control unit figures out what to do with the instruction (decode) It decides whether to get data from memory or registers. It looks at the opcode to see what instruction to run. If dealing with a math operation it looks at the function code to see what to tell the ALU to do. It tells the program counter whether it should be incremented or a jump should occur. 4.The instruction is executed. 5.The cycle repeats.

New Content A while back we discussed that the stack contains an Activation Record or Stack Frame for each function. Recall that an activation record or stack frame represents the local variables in a function or method. The stack is used to keep track of these variables. For each function/method call, an activation record is created. Each activation record provides a new or fresh set of local variables for a function.

Stack Pointer The stack pointer, $sp, provides access to memory in the stack. We may decrement the stack pointer to obtain local memory for a function. Assembler reads through program and packs into appropriate segments As it finds labels they are added to a table and later the actual numeric address is filled in. We'll come back to the stack pointer soon.

Functions Functions - a group or module of instructions that performs a specific task They typically require input (arguments) or produce output (return values). We want to use functions because they allow us to break up code into manageable parts that are easier to think about (abstract) and they allow us to reuse code. We don't want functions to do weird things, like modifying data that shouldn't be modified. Arguments and return values – Function arguments may be provided with the $a0 to $a3 registers. – Function return values may be provided using the $v0 and $v1 registers.

Functions Contd. You need to find another solution if you need more than 4 arguments or 2 return values. Think about saved registers and memory. You should never expect the temporary registers to remain the same after function calls. You should always expect the saved registers to remain the same, but you might have to return them to their original values. Making a function call – Use jal - Jump and Link to call a function and save the return address. –jal saves the return address so the Program Counter (PC) can be reset to the proper value once you return from the function

Creating a function Use a label to name a function. This is done in the same manner as a loop. label: #The code for your function goes here. Once you've finished writing your code, be sure to restore any saved registers to their original values. Be sure to return from the function, too. To return to the right position in the calling program, call the jr instruction. jr returns to the address provided in the "return address" register $ra is the return address register and works to return to the instruction just after the function call.

Functions Use jr in the following manner: jr $ra #return to the calling method or #function Let's look at an example of a function //A function to add four arguments int addFour(int a, int b, int c, int d){ return a + b + c + d; } //This function could be called from your main //method as follows. int x = addFour(1, 2, 3, 4);

Example in MIPS #in MIPS the code for your function would be coded as follows addFour: add $v0, $a0, $a1 add $v0, $v0, $a2 add $v0, $v0, $a3 jr $ra #in the main method you might make your function call and initializations as follows main: li $a0, 1 li $a1, 2 li $a2, 3 li $a3, 4 jal addFour move $s2, $v0 #assume x is stored in $s2