OCC - CS/CIS CS116-Ch00-Orientation 1 1998 Morgan Kaufmann Publishers ( Augmented & Modified by M.Malaty) 1CS 116 Fall 2003 Not quite finished Creating.

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.
©UCB CS 161 Lecture 4 Prof. L.N. Bhuyan
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.
1 Lecture 4: Procedure Calls Today’s topics:  Procedure calls  Large constants  The compilation process Reminder: Assignment 1 is due on Thursday.
Lecture 6: MIPS Instruction Set Today’s topic –Control instructions –Procedure call/return 1.
SPIM and MIPS programming
Computer Architecture CSCE 350
Csci136 Computer Architecture II Lab#4. - Stack and Nested Procedures
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.
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
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
Computer Structure - The Instruction Set (2) Goal: Implement Functions in Assembly  When executing a procedure (function in C) the program must follow.
Lecture 7: MIPS Instruction Set Today’s topic –Procedure call/return –Large constants Reminders –Homework #2 posted, due 9/17/
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.
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
Topic 2d High-Level languages and Systems Software
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,
Lecture 4: MIPS Instruction Set
Orange Coast College Business Division Computer Science Department CS 116- Computer Architecture Instructions: Part the Last.
MicroComputer Engineering IntroLab1 page 1 Introduction Lab1  A crash course in assembler programming  Learn how a processor works!  Decode a coded.
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.
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
Computer Architecture & Operations I
MIPS Assembly Language Programming
MIPS Instruction Set Advantages
Lecture 4: MIPS Instruction Set
Procedures (Functions)
Procedures (Functions)
Assembly Programming using MIPS R3000 CPU
Topic 2e High-Level languages and Systems Software
CSCI206 - Computer Organization & Programming
Solutions Chapter 2.
MIPS Instructions.
The University of Adelaide, School of Computer Science
COMS 361 Computer Organization
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
Where is all the knowledge we lost with information? T. S. Eliot
Program and memory layout
MIPS function continued
MIPS R3000 Subroutine Calls and Stack
Topic 2b ISA Support for High-Level Languages
Presentation transcript:

OCC - CS/CIS CS116-Ch00-Orientation Morgan Kaufmann Publishers ( Augmented & Modified by M.Malaty) 1CS 116 Fall 2003 Not quite finished Creating assembly – Process Details of the simulator – Loading code – Registers – Kernel – Debugging

OCC - CS/CIS CS116-Ch00-Orientation Morgan Kaufmann Publishers ( Augmented & Modified by M.Malaty) 2CS 116 Fall 2003 Creating Assembly Start with problem description: – Write a program that solves the problem High level language like C or Pascal For each function in the solution – Translate each HLL statement into assembly – Write the procedure entry and exit code For global data – That is data that is accessible from everywhere Such as strings for output – Create a.data section and add globals there

OCC - CS/CIS CS116-Ch00-Orientation Morgan Kaufmann Publishers ( Augmented & Modified by M.Malaty) 3CS 116 Fall 2003 Translating Statements Associate each value with a register – Including temporary results Consider: A*(B+C)-15 A: $a0, B: $a1, C: $a2 B+C: $t0, A+$t0: $t0 Convert each line – Consider if you need to use Immediate form (with constants) Register form – Above example: add $t0, $a1, $a2 mul $t0, $a0, $t0 subi $t0, $t0, 15

OCC - CS/CIS CS116-Ch00-Orientation Morgan Kaufmann Publishers ( Augmented & Modified by M.Malaty) 4CS 116 Fall 2003 Procedures If your HLL code has variables... – Try and assign them to registers – Otherwise, will need stack space If you need stack space... – Assign them an offset from $fp – Load them into a temporary register when needed – Spill (save) the result back to the stack when done

OCC - CS/CIS CS116-Ch00-Orientation Morgan Kaufmann Publishers ( Augmented & Modified by M.Malaty) 5CS 116 Fall 2003 Example load and spill Cosider a local variable x – On the stack, located -28 from the $fp – To use it in an equation: X = X + 15 lw $t0, -28($fp) addi $t0, $t0, 15 sw $t0, -28($fp)

OCC - CS/CIS CS116-Ch00-Orientation Morgan Kaufmann Publishers ( Augmented & Modified by M.Malaty) 6CS 116 Fall 2003 Procedure Entry Procedures must save the state of the processor – Procedure prologue & epilogue Prologue – Adjust stack by size of procedure frame – Put $ra on stack – Put $fp on stack – Save any argument registers (if necessary) – Save any other registers ($s0...$s7, etc)

OCC - CS/CIS CS116-Ch00-Orientation Morgan Kaufmann Publishers ( Augmented & Modified by M.Malaty) 7CS 116 Fall 2003 Procedure finish Epilogue – Pretty much the inverse of the prologue Restore any saved registers ($s0..$s7, etc) Restore argument registers Restore old $fp Restore return address ($ra) Readjust the stack Exit the procedure

OCC - CS/CIS CS116-Ch00-Orientation Morgan Kaufmann Publishers ( Augmented & Modified by M.Malaty) 8CS 116 Fall 2003 Sample Procedure proc_start: subi $sp, $sp, 32 sw $ra, 28($sp) sw $fp, 24($sp) sw $s0, 20($sp) addiu $fp, $sp, 28 (some instructions) proc_end:lw $s0, 20($sp) lw $fp, 24($sp) lw $ra, 28($sp) addi $sp, $sp, 32 jr $ra

OCC - CS/CIS CS116-Ch00-Orientation Morgan Kaufmann Publishers ( Augmented & Modified by M.Malaty) 9CS 116 Fall 2003 A Worked Out Example Please see page A-26 in the book – Walks through all of the steps – Creates a program to calculate the factorial of a given parameter

OCC - CS/CIS CS116-Ch00-Orientation Morgan Kaufmann Publishers ( Augmented & Modified by M.Malaty) 10CS 116 Fall 2003 The Simulator Registers Text (Code) Data segment Error messages

OCC - CS/CIS CS116-Ch00-Orientation Morgan Kaufmann Publishers ( Augmented & Modified by M.Malaty) 11CS 116 Fall 2003 Loading Code

OCC - CS/CIS CS116-Ch00-Orientation Morgan Kaufmann Publishers ( Augmented & Modified by M.Malaty) 12CS 116 Fall 2003 Registers

OCC - CS/CIS CS116-Ch00-Orientation Morgan Kaufmann Publishers ( Augmented & Modified by M.Malaty) 13CS 116 Fall 2003 Kernel Set of software routines for common services – Usually provided by the OS – Interrupts via syscall

OCC - CS/CIS CS116-Ch00-Orientation Morgan Kaufmann Publishers ( Augmented & Modified by M.Malaty) 14CS 116 Fall 2003 Debugging Set a breakpoint at a given address When executing, simulator stops – Examine state of machine – Resume program