Announcements. Class 7: Intro to SRC Simulator Procedure Calls HLL -> Assembly. Agenda. SRC Procedure Calls. SRC Memory Layout. High Level Program

Similar documents
Course Administration

Subroutines. int main() { int i, j; i = 5; j = celtokel(i); i = j; return 0;}

Assembly Language: Function Calls

Do-While Example. In C++ In assembly language. do { z--; while (a == b); z = b; loop: addi $s2, $s2, -1 beq $s0, $s1, loop or $s2, $s1, $zero

Assembly Language: Function Calls

Implementing Procedure Calls

CSCI 2121 Computer Organization and Assembly Language PRACTICE QUESTION BANK

CSE Lecture In Class Example Handout

Assembly Language: Function Calls" Goals of this Lecture"

Assembly Language: Function Calls. Goals of this Lecture. Function Call Problems

Assembly Language: Function Calls" Goals of this Lecture"

Lecture 5. Announcements: Today: Finish up functions in MIPS

Systems I. Machine-Level Programming V: Procedures

Admin CS41B MACHINE. Examples from this lecture. CS41B machine 2/16/16 CPU. David Kauchak CS 52 Spring 2016

Princeton University Computer Science 217: Introduction to Programming Systems. Assembly Language: Function Calls

Branch Addressing. Jump Addressing. Target Addressing Example. The University of Adelaide, School of Computer Science 28 September 2015

Functions in MIPS. Functions in MIPS 1

Function Calling Conventions 1 CS 64: Computer Organization and Design Logic Lecture #9

SRC Assembly Language Programming - III

MIPS Procedure Calls. Lecture 6 CS301

Prof. Kavita Bala and Prof. Hakim Weatherspoon CS 3410, Spring 2014 Computer Science Cornell University. See P&H 2.8 and 2.12, and A.

RTN (Register Transfer Notation)

2/16/2018. Procedures, the basic idea. MIPS Procedure convention. Example: compute multiplication. Re-write it as a MIPS procedure

Lectures 5. Announcements: Today: Oops in Strings/pointers (example from last time) Functions in MIPS

Implementing Functions at the Machine Level

Function Calling Conventions 2 CS 64: Computer Organization and Design Logic Lecture #10

EE 109 Unit 15 Subroutines and Stacks

Today. Putting it all together

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

Compiling Code, Procedures and Stacks

CSCE 5610: Computer Architecture

CSC 2400: Computer Systems. Using the Stack for Function Calls

CSE Lecture In Class Example Handout

ECE331: Hardware Organization and Design

CprE 288 Introduction to Embedded Systems ARM Assembly Programming: Translating C Control Statements and Function Calls

Lectures 3-4: MIPS instructions

CSC 8400: Computer Systems. Using the Stack for Function Calls

Using the MIPS Calling Convention. Recursive Functions in Assembly. CS 64: Computer Organization and Design Logic Lecture #10 Fall 2018

CS 61c: Great Ideas in Computer Architecture

Control Instructions. Computer Organization Architectures for Embedded Computing. Thursday, 26 September Summary

Control Instructions

Instruction Set Architectures (4)

Chapter 2A Instructions: Language of the Computer

Function Calls. 1 Administrivia. Tom Kelliher, CS 240. Feb. 13, Announcements. Collect homework. Assignment. Read

CS356: Discussion #6 Assembly Procedures and Arrays. Marco Paolieri

Review of Activation Frames. FP of caller Y X Return value A B C

CSC 2400: Computing Systems. X86 Assembly: Function Calls"

Function Calls. Tom Kelliher, CS 220. Oct. 24, SPIM programs due Wednesday. Refer to homework handout for what to turn in, and how.

6.1. CS356 Unit 6. x86 Procedures Basic Stack Frames

Computer Systems and Networks

CSC 2400: Computer Systems. Using the Stack for Function Calls

CPS311 Lecture: Procedures Last revised 9/9/13. Objectives:

2/6/2018. Let s Act Like Compilers! ECE 220: Computer Systems & Programming. Decompose Finding Absolute Value

Functions and the MIPS Calling Convention 2 CS 64: Computer Organization and Design Logic Lecture #11

CSC 2400: Computing Systems. X86 Assembly: Function Calls

Assembly labs start this week. Don t forget to submit your code at the end of your lab section. Download MARS4_5.jar to your lab PC or laptop.

x86 assembly CS449 Fall 2017

CprE 288 Introduction to Embedded Systems Course Review for Exam 3. Instructors: Dr. Phillip Jones

Lecture 5: Procedure Calls

Procedures and Stacks

MIPS Functions and the Runtime Stack

MIPS Datapath. MIPS Registers (and the conventions associated with them) MIPS Instruction Types

MIPS Programming. A basic rule is: try to be mechanical (that is, don't be "tricky") when you translate high-level code into assembler code.

Wednesday, October 15, 14. Functions

Arguments and Return Values. EE 109 Unit 16 Stack Frames. Assembly & HLL s. Arguments and Return Values

Function Calls COS 217. Reading: Chapter 4 of Programming From the Ground Up (available online from the course Web site)

COMP 303 Computer Architecture Lecture 3. Comp 303 Computer Architecture

Instruction Set Architecture

Rui Wang, Assistant professor Dept. of Information and Communication Tongji University.

CS 31: Intro to Systems Functions and the Stack. Martin Gagne Swarthmore College February 23, 2016

Plan. Regression testing: Demo of how to use the regress.sh script.

ECE232: Hardware Organization and Design

Stack Frames. Compilers use the stack: to store the to to a subroutine for storage of declared in the subroutine and a place to

Midterm 2 Review Chapters 4-16 LC-3

Memory Usage 0x7fffffff. stack. dynamic data. static data 0x Code Reserved 0x x A software convention

Assembly Programming IV

Stacks and Frames Demystified. CSCI 3753 Operating Systems Spring 2005 Prof. Rick Han

Concepts Introduced in Chapter 7

Run-time Environment

Instruction Set Architecture part 1 (Introduction) Mehran Rezaei

Procedure Calls Main Procedure. MIPS Calling Convention. MIPS-specific info. Procedure Calls. MIPS-specific info who cares? Chapter 2.7 Appendix A.

CS 2210 Programming Project (Part IV)

Announcements HW1 is due on this Friday (Sept 12th) Appendix A is very helpful to HW1. Check out system calls

CSCI 402: Computer Architectures. Instructions: Language of the Computer (3) Fengguang Song Department of Computer & Information Science IUPUI.

MIPS Assembly (Functions)

Functions in C. Memory Allocation in C. C to LC3 Code generation. Next.. Complete and submit C to LC3 code generation. How to handle function calls?

CS61C : Machine Structures

Lecture 7: Procedures and Program Execution Preview

Calling Conventions. Hakim Weatherspoon CS 3410, Spring 2012 Computer Science Cornell University. See P&H 2.8 and 2.12

CprE 288 Translating C Control Statements and Function Calls, Loops, Interrupt Processing. Instructors: Dr. Phillip Jones Dr.

ECE260: Fundamentals of Computer Engineering

Thomas Polzer Institut für Technische Informatik

Lecture 4 CIS 341: COMPILERS

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

administrivia today start assembly probably won t finish all these slides Assignment 4 due tomorrow any questions?

Computer Hardware Engineering

Anne Bracy CS 3410 Computer Science Cornell University

The Stack & Procedures

Math 230 Assembly Programming (AKA Computer Organization) Spring 2008

The plot thickens. Some MIPS instructions you can write cannot be translated to a 32-bit number

Transcription:

Fall 2006 CS333: Computer Architecture University of Virginia Computer Science Michele Co Announcements Class 7: Intro to SRC Simulator Procedure Calls HLL -> Assembly Homework #2 Due next Wednesday, Sept. 13 in class Class notes posted on course website 2 Agenda SRC Procedure Calls SRC and Procedure Calls Calling convention discussed here will be used for SRC programming lab Sample problems from Chapter 2 Activation stack layout Activation records Link register r31 for this example Calling conventions -save (other registers) Callee-save ( for this example) 3 4 High Level int arg1 = -5; // argument to pass int output = 0; // result SRC Layout int absolute(int ){ if( <= 0) = -; void main(){ output = absolute(arg1); 5 6

Typical Layout Heap Why Wouldn t This Layout Be As Good? Heap 7 8 Activation Last In First Out (LIFO) Push, pop operations Can be located anywhere in memory Typically started in high memory For SRC, we ll use a different memory layout What is Saved on the? Activation Records Return address Function parameters Local variables Space for s Information associated with a procedure call 9 10 Activation Record vs. Callee Calling function Callee Function being called 11 12

High Level int arg1 = -5; int output = 0; int absolute(int ){ if( <= 0) = -; return ; void main(){ output = absolute(arg1); // argument to pass // result 13 How is a Procedure Call Performed? 1. Stores arguments onto stack 2. Allocates space for output values (return value) 3. Calls the procedure Callee 1. Stores 2. Stores the 3. Retrieves any passed arguments 4. Performs procedure body 5. Saves results 6. Returns to caller 14 15 16 Callee 17 18

Callee 19 20 Assembly (1) arg1:.dc -5 ; global var arg1 = -5 output:.dc 0 ; global var output = 0.org ; start next inst at addi r30, r30, ; set to Main: ld r0, arg1 ; load input, arg1 into r0 addi r30, r30, -4 ; PUSH: adjust down by 4 bytes st r0, (r30) ; PUSH: save arg1 onto the stack addi r30, r30, -4 ; allocate space for the ; output (one result) la r29, Absolute ; load the address of Abs into r29 brl r31, r29 ; call Absolute and save return ; address (PC+4) in r31 21 22 Assembly (2) Assembly (3) ld r0, (r30) st r0, output addi r30, r30, 8 stop ; load output result ; store output result ; restore the ; end of Main program Absolute: addi r30, r30, -4 ; PUSH: adjust st r31, (r30) ; PUSH: save ret addr ; to the stack la r28, Ret ; load address of Ret into r28 ld r0, 8(r30) ; load arg1 from +8 into ; space, r0 brpl r28, r0 ; branch to Ret if arg1 >= 0 Negate: neg r0, r0 ; negate ; (get the absolute value) Ret: st r0, 4(r30) ; store result r0 () ; onto stack ld r29, (r30) ; POP: put the ret addr ; into r29 addi r30, r30, 4 ; POP: adjust br r29 ; return to calling program 23 24

SRC Simulator Demo Question: What if there were 2 params? param2 25 26 What Needs to be Agreed Upon? What You Should Know and Callee need to agree on Size of inputs and outputs Relative position on the stack (of inputs/outputs) Which registers need to be saved by WHOM needs to save any registers that callee might use Whether arguments and/or s are passed through memory or through registers needs to know how to lay out the stack so that the callee knows how to access its parameters Activation stack layout Activation records Link register r31 for this example Calling conventions What actions caller and callee perform -save (other registers) Callee-save ( in this example) Process for converting a HLL program to assembly program 27 28 Calculate Total Traffic Chapter 2 Sample Problems Assumptions: Addresses: 2 bytes Data: 2 bytes Opcodes: 1 byte Calculation Steps Instruction Fetch Instruction Execute Total Reference Figs 2.4-2.7 30

A = (B*C) + D-E Problem 2.22a Modify SRC to include conditional jump instruction, jpr (op=25) Uses relative addressing, rel, instead of branch target register Should only be taken if ra = 0 See text for full problem desc See Table 2.7 for notation meanings Example of RTN for a different inst: add (:= op = 12) R[ra] R[rb] + R[rc]: 31 32 Solution jpr (:= op=25) ((ra=0) PC rel) : 33