Memory/Storage Architecture Lab Computer Architecture MIPS Instruction Set Architecture ( Supporting Procedures )

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
MIPS ISA-II: Procedure Calls & Program Assembly. (2) Module Outline Review ISA and understand instruction encodings Arithmetic and Logical Instructions.
MIPS ISA-II: Procedure Calls & Program Assembly. (2) Module Outline Review ISA and understand instruction encodings Arithmetic and Logical Instructions.
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
1 Lecture 4: Procedure Calls Today’s topics:  Procedure calls  Large constants  The compilation process Reminder: Assignment 1 is due on Thursday.
Procedure Calls Prof. Sirer CS 316 Cornell University.
MIPS Calling Convention Chapter 2.7 Appendix A.6.
Lecture 8 Sept 23 Completion of Ch 2 translating procedure into MIPS role of compilers, assemblers, linking, loading etc. pitfalls, conclusions Chapter.
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
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.
CS1104 – Computer Organization PART 2: Computer Architecture Lecture 4 Assembly Language Programming 2.
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 Assembly Language I Computer Architecture CPSC 321 Andreas Klappenecker.
ENEE350 Spring07 1 Ankur Srivastava University of Maryland, College Park Adapted from Computer Organization and Design, Patterson & Hennessy, © 2005.”
Lecture 6: Procedures (cont.). Procedures Review Called with a jal instruction, returns with a jr $ra Accepts up to 4 arguments in $a0, $a1, $a2 and $a3.
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.
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/
Calling Conventions Hakim Weatherspoon CS 3410, Spring 2012 Computer Science Cornell University See P&H 2.8 and 2.12.
13/02/2009CA&O Lecture 04 by Engr. Umbreen Sabir Computer Architecture & Organization Instructions: Language of Computer Engr. Umbreen Sabir Computer Engineering.
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 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,
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.
Procedure (Method) Calls Ellen Spertus MCS 111 September 25, 2003.
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.
COMPUTER ORGANIZATION LECTURE 3: ISA YASSER MOHAMMAD.
1 CS/COE0447 Computer Organization & Assembly Language Chapter 2 Part 3.
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.
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
CSCI206 - Computer Organization & Programming
RISC Concepts, MIPS ISA Logic Design Tutorial 8.
Procedures (Functions)
Procedures (Functions)
Assembly Programming using MIPS R3000 CPU
CSCI206 - Computer Organization & Programming
What's wrong with this procedure?
CSCI206 - Computer Organization & Programming
The University of Adelaide, School of Computer Science
Lecture 5: Procedure Calls
Program and memory layout
Systems Architecture I
Assembly Programming using MIPS R3000 CPU
Computer Architecture
10/6: Lecture Topics C Brainteaser More on Procedure Call
Program and memory layout
MIPS function continued
Topic 2b ISA Support for High-Level Languages
Presentation transcript:

Memory/Storage Architecture Lab Computer Architecture MIPS Instruction Set Architecture ( Supporting Procedures )

Memory/Storage Architecture Lab 22 MIPS Register Naming 0 $zero constant 0 1 $at reserved for assembler 2 $v0 return values 3 $v1 4 $a0 arguments 5 $a1 6 $a2 7 $a3 8 $t0 temporary · · · 15 $t7 16 $s0 permanent · · ·· · · 23 $s7 24 $t8 temporary 25 $t9 26 $k0 OS kernel (reserved) 27 $k1 28 $gp global pointer 29 $sp stack pointer 30 $fp frame pointer 31 $ra return address (For variables in a high-level language program)

Memory/Storage Architecture Lab 33 Calling Convention (Caller Save) save (live) registers set up arguments save return address and jump to the callee restore saved registers allocate stack frame place return value free stack frame restore and jump to the return address Caller Callee

Memory/Storage Architecture Lab 44 Calling Convention (Callee Save) set up arguments save return address and jump to the callee allocate stack frame save registers(that may be modified in the callee) place return value restore saved registers free stack frame restore and jump to the return address Caller Callee

Memory/Storage Architecture Lab 55 MIPS Calling Convention (Hybrid) save (live) caller-saved registers: $t0~$t9, $a0~$a3, $v0~$v1, $ra set up arguments : first four in $a0~$a3, rest on stack execute jal instruction restore caller-saved registers allocate stack frame: $sp ← $sp – frame size save callee-saved registers (that may be modified in the callee) : $s0~$s7 place return value in $v0~$v1 restore callee-saved registers free stack frame : $sp ← $sp + frame size return by jr $ra Caller Callee

Memory/Storage Architecture Lab 66 MIPS Register Convention 0 $zero constant 0 1 $at reserved for assembler 2 $v0 function return value 3 $v1 (caller saves) 4 $a0 arguments (caller saves) 5 $a1 6 $a2 7 $a3 8 $t0 temporary (caller saves) · · · 15 $t7 16 $s0 permanent (callee saves) · · ·· · · 23 $s7 24 $t8 temporary (caller saves) 25 $t9 26 $k0 OS kernel (reserved) 27 $k1 28 $gp global pointer (caller saves) 29 $sp stack pointer (preserved) 30 $fp frame pointer ($s8 for cc) (callee saves) 31 $ra return address(jal) (caller saves) (For variables in a high-level language program)

Memory/Storage Architecture Lab 77 Compiling a Leaf Procedure C int leaf_example ( int g, int h, int i, int j ) { int f ; f = ( g + h ) – ( i + j ); return f; } Assembly Actually Not needed leaf_example: addi sw add sub add lw addi jr $sp, $sp, -12 $t1, 8($sp) $t0, 4($sp) $s0, 0($sp) $t0, $a0, $a1 $t1, $a2, $a3 $s0, $t0, $t1 $v0, $s0, $zero $s0, 0($sp) $t0, 4($sp) $t1, 8($sp) $sp, $sp, 12 $ra

Memory/Storage Architecture Lab 88 Stack Allocation FIGURE 3.12 Illustration of the stack allocation (a)before, (b)during, and (c)after the procedure call

Memory/Storage Architecture Lab 99 Compiling a Non-Leaf Procedure Assembly int nonleaf_example (int arg) { int result; result = arg + leaf_example(5,4,3,2); return result; } C nonleaf_example: addi sw addi jal lw add lw addi jr $sp, $sp, -12 $s0, 8($sp) $ra, 4($sp) $a0, 0($sp) $a0, $zero, 5 $a1, $zero, 4 $a2, $zero, 3 $a3, $zero, 2 leaf_example $a0, 0($sp) $ra, 4($sp) $s0, $a0, $v0 $v0, $s0, $zero $s0, 8($sp) $sp, $sp, 12 $ra

Memory/Storage Architecture Lab 10 Compiling a Recursive Procedure C int fact ( int n ) { if ( n < 1 ) return (1) ; else return ( n * fact ( n – 1) ); } Assembly fact: L1: slti beq addi jr addi sw addi jal lw addi mult mflo jr $t0, $a0, 1 $t0, $zero, L1 $v0, $zero, 1 $ra $sp, $sp, -8 $ra, 4($sp) $a0, 0($sp) $a0, $a0, -1 fact $ra, 4($sp) $a0, 0($sp) $sp, $sp, 8 $a0, $v0 $v0 $ra

Memory/Storage Architecture Lab 11 Compiling and Starting a Program

Memory/Storage Architecture Lab 12 Object File Example Object file header NameProcedure ANameProcedure B Text size100 hex Text size200 hex Data size20 hex Data size30 hex Text segmentAddressInstructionText segmentAddressInstruction 0lw $a0, 0($gp)0sw $a1, 0($gp) 4jal 04 ………… Data segment0(X)Data segment0(Y) ………… Relocation informationAddressInstruction typeDependencyRelocation informationAddressInstruction typeDependency 0lwX0swY 4jalB4 A Symbol tableLabelAddressSymbol tableLabelAddress X-Y- B-A-

Memory/Storage Architecture Lab 13 MIPS Memory Allocation

Memory/Storage Architecture Lab 14 Executable File Example Executable file header Text size300 hex Data size50 hex Text segmentAddressInstruction hex lw $a0, 8000 hex ($gp) hex jal hex …… hex sw $a1, 8020 hex ($gp) hex jal hex …… Data segmentAddress hex (X) …… hex (Y) ……