CS 300 – Lecture 10 Intro to Computer Architecture / Assembly Language Strings and Characters and More.

Slides:



Advertisements
Similar presentations
CML CML CS 230: Computer Organization and Assembly Language Aviral Shrivastava Department of Computer Science and Engineering School of Computing and Informatics.
Advertisements

The University of Adelaide, School of Computer Science
Introduction to SPIM Simulator
The MIPS 32 1)Project 1 Discussion? 1)HW 2 Discussion? 2)We want to get some feel for programming in an assembly language - MIPS 32 We want to fully understand.
1 Procedure Calls, Linking & Launching Applications Lecture 15 Digital Design and Computer Architecture Harris & Harris Morgan Kaufmann / Elsevier, 2007.
ECE 232 L6.Assemb.1 Adapted from Patterson 97 ©UCBCopyright 1998 Morgan Kaufmann Publishers ECE 232 Hardware Organization and Design Lecture 6 MIPS Assembly.
10/6: Lecture Topics Procedure call Calling conventions The stack
MIPS Calling Convention Chapter 2.7 Appendix A.6.
CS3350B Computer Architecture Winter 2015 Lecture 4
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.
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)
1 Computer Architecture MIPS Simulator and Assembly language.
CSE331 W04.1Irwin&Li 2006 PSU CSE 331 Computer Organization and Design Fall 2006 Week 4 Section 1: Mary Jane Irwin (
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
MIPS Assembly Language
MIPS Overview (with comparisons to x86)
MIPS Assembly Language I Computer Architecture CPSC 321 Andreas Klappenecker.
CS 536 Spring Code generation I Lecture 20.
20/06/2015CSE1303 Part B lecture notes 1 Functions, part 2 Lecture B15 Lecture notes, section B15.
Intro to Computer Architecture
28/06/2015CMPUT Functions (2)  Function calling convention  Various conventions available  One is specified by CMPUT229  Recursive functions.
Lecture 7: MIPS Instruction Set Today’s topic –Procedure call/return –Large constants Reminders –Homework #2 posted, due 9/17/
CDA 3101 Fall 2012 Introduction to Computer Organization Instruction Set Architecture MIPS Instruction Format 04 Sept 2013.
Memory/Storage Architecture Lab Computer Architecture MIPS Instruction Set Architecture ( Supporting Procedures )
The Stack Pointer and the Frame Pointer (Lecture #19) ECE 445 – Computer Organization The slides included herein were taken from the materials accompanying.
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.
MIPS function continued. Recursive functions So far, we have seen how to write – A simple function – A simple function that have to use the stack to save.
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,
MIPS Calling Convention. Procedure Calls Procedure must work the same from any call Procedure uses regs that main was using We need a convention to –pass.
Computer Organization CS224 Fall 2012 Lessons 9 and 10.
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.
DR. SIMING LIU SPRING 2016 COMPUTER SCIENCE AND ENGINEERING UNIVERSITY OF NEVADA, RENO Session 7, 8 Instruction Set Architecture.
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
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
MIPS Assembly Language Programming
CSCI206 - Computer Organization & Programming
Procedures (Functions)
Procedures (Functions)
Functions and Procedures
Assembly Programming using MIPS R3000 CPU
CSCI206 - Computer Organization & Programming
MIPS Instructions.
The University of Adelaide, School of Computer Science
Program and memory layout
Systems Architecture I
Assembly Programming using MIPS R3000 CPU
Computer Architecture
Where is all the knowledge we lost with information? T. S. Eliot
Program and memory layout
Introduction Lab1 A crash course in assembler programming
MIPS function continued
MIPS R3000 Subroutine Calls and Stack
Topic 2b ISA Support for High-Level Languages
Presentation transcript:

CS 300 – Lecture 10 Intro to Computer Architecture / Assembly Language Strings and Characters and More

Function Calling Basic ideas: * Parameters passed into function * Return address * Return values * Registers saved / destroyed during the call * Saving other data during the call

The GORY Details So what does a function look like? Initially: * Frame allocation * Save values to the frame (including return address). Usually need to move args there. Save $s0 - $s7 if used later. Finally: * Put return values in proper registers. * Resture $s0 - $s7 * Deallocate the frame * Branch to the return address ("jr") Calling other functions: * Push needed information that is not in the stack frame or a saved register * Perform "jal" * Pop the stack

Aside: MIPS Register Convention NameRegister Number UsagePreserve on call? $zero0constant 0 (hardware)n.a. $at1reserved for assemblern.a. $v0 - $v12-3returned valuesno $a0 - $a34-7argumentsyes $t0 - $t78-15temporariesno $s0 - $s716-23saved valuesyes $t8 - $t924-25temporariesno $gp28global pointeryes $sp29stack pointeryes $fp30frame pointeryes $ra31return addr (hardware)yes

Example Factorial: f(x) = if x <= 0 then 1 else x*f(x-1) fact: addi $sp, $sp, -8 # Make frame sw $ra, 4($sp) # save ra, a1 sw $a0, 0($sp) slti $t0, $a0, 1 # a0 < 1? beq $t0, $zero, L1 addi $v0, $zero, 1 # return 1 addi $sp, $sp, 8 jr $ra

Factorial L1: addi $a0, $a0, -1 jal fact lw $a0, 0($sp) lw $ra, 4($sp) addi $sp, $sp, 8 mul $v0, $a0, $v0 jr $ra

And Now for the Pentium … _fact: pushl%ebp movl%esp, %ebp subl$8, %esp cmpl$0, 8(%ebp) jneL2 movl$1, -4(%ebp) jmpL1 %ebp = $fp esp = $sp From "gcc –S" See 2.16 for more

And Now for the Pentium … L2:movl8(%ebp), %eax decl%eax movl%eax, (%esp) call_fact imull8(%ebp), %eax movl%eax, -4(%ebp) L1:movl-4(%ebp), %eax leave ret

More About $fp Why have both $sp and $fp? * Stack use varies within a function (why?). Using $fp, we always know where locals are * $fp allows for the creation of chained environments. This is needed in Java for nested objects. * $fp can accept incoming parameters from the stack top Note that you often don't need $fp at all.