Lecture 3 - Instruction Set - Al

Slides:



Advertisements
Similar presentations
Ch. 7 Local Variables and Parameter Passing From the text by Valvano: Introduction to Embedded Systems: Interfacing to the Freescale 9S12.
Advertisements

The University of Adelaide, School of Computer Science
1 Lecture 4: Procedure Calls Today’s topics:  Procedure calls  Large constants  The compilation process Reminder: Assignment 1 is due on Thursday.
CPS3340 COMPUTER ARCHITECTURE Fall Semester, /17/2013 Lecture 12: Procedures Instructor: Ashraf Yaseen DEPARTMENT OF MATH & COMPUTER SCIENCE CENTRAL.
Ch. 8 Functions.
The University of Adelaide, School of Computer Science
 Procedures (subroutines) allow the programmer to structure programs making them : › easier to understand and debug and › allowing code to be reused.
Procedures and Control Flow CS351 – Programming Paradigms.
COMP3221: Microprocessors and Embedded Systems Lecture 12: Functions I Lecturer: Hui Wu Session 2, 2005.
1 Storage Registers vs. memory Access to registers is much faster than access to memory Goal: store as much data as possible in registers Limitations/considerations:
CSS 372 Lecture 1 Course Overview: CSS 372 Web page Syllabus Lab Ettiquette Lab Report Format Review of CSS 371: Simple Computer Architecture Traps Interrupts.
EECC250 - Shaaban #1 Lec # 5 Winter Stacks A stack is a First In Last Out (FILO) buffer containing a number of data items usually implemented.
Run-Time Storage Organization
Run time vs. Compile time
1 Run time vs. Compile time The compiler must generate code to handle issues that arise at run time Representation of various data types Procedure linkage.
EECC250 - Shaaban #1 lec #7 Winter Local workspace of a subroutine: A number of temporary memory locations required by the subroutine for temporary.
Chapter 8 :: Subroutines and Control Abstraction
13/02/2009CA&O Lecture 04 by Engr. Umbreen Sabir Computer Architecture & Organization Instructions: Language of Computer Engr. Umbreen Sabir Computer Engineering.
Computer Organization CS345 David Monismith Based upon notes by Dr. Bill Siever and notes from the Patterson and Hennessy Text.
Programmer's view on Computer Architecture by Istvan Haller.
Runtime Environments Compiler Construction Chapter 7.
Programming Language Principles Lecture 24 Prepared by Manuel E. Bermúdez, Ph.D. Associate Professor University of Florida Subroutines.
9/20/6Lecture 3 - Instruction Set - Al1 Program Design.
Copyright © 2005 Elsevier Chapter 8 :: Subroutines and Control Abstraction Programming Language Pragmatics Michael L. Scott.
Lesson 13 CDT301 – Compiler Theory, Spring 2011 Teacher: Linus Källberg.
Objective At the conclusion of this chapter you will be able to:
Passing Parameters using Stack Calling program pushes parameters on the stack one element at a time before calling subroutine. Subroutine Call (jsr, bsr)
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:
COMP3190: Principle of Programming Languages
V 1.01 Arrays and Pointers in C A pointer variable is a variable that contains the address of another variable. An array is a collection of like elements,
ITCS 3181 Logic and Computer Systems 2015 B. Wilkinson Slides4-2.ppt Modification date: March 23, Procedures Essential ingredient of high level.
9/20/6Lecture 3 - Instruction Set - Al1 Program Design Examples.
Revised: Aug 1, EE4390 Microprocessors Lessons 11, 12 Advanced Assembly Programming.
7-Nov Fall 2001: copyright ©T. Pearce, D. Hutchinson, L. Marshall Oct lecture23-24-hll-interrupts 1 High Level Language vs. Assembly.
Code Generation Instruction Selection Higher level instruction -> Low level instruction Register Allocation Which register to assign to hold which items?
Storage Allocation Mechanisms
Lecture 7 Macro Review Stack Frames
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.
Run-Time Environments Chapter 7
Computer Science 210 Computer Organization
Figure 8.1 of course package
System Programming and administration
Computer Architecture
Organization of Programming Languages
Run-time organization
Introduction to Compilers Tim Teitelbaum
Programming Fundamentals Lecture #7 Functions
Stack Frames Stack frame = block of memory located in the system stack that contains: return address input parameters (from calling program to subroutine)
Subroutines … a 1st look procedures and functions in high level languages are modeled on subroutines typically, assembly code is very modular with.
Chapter 9 :: Subroutines and Control Abstraction
Program Design Examples
Chap. 8 :: Subroutines and Control Abstraction
Chap. 8 :: Subroutines and Control Abstraction
CSCE Fall 2013 Prof. Jennifer L. Welch.
Passing Parameters Data passed to a subroutine is called a parameter.
The University of Adelaide, School of Computer Science
68000 Architecture, Data Types and Addressing Modes
Reentrant Code a reentrant procedure can have several calls open to it at the same time in an interrupt environment, different ISRs may call the same routine.
Tail Recursion.
Figure 8.1 of course package
Topic 3-a Calling Convention 1/10/2019.
Binding Times Binding is an association between two things Examples:
CSCE Fall 2012 Prof. Jennifer L. Welch.
UNIT V Run Time Environments.
Lecture 6: Assembly Programs
Process.
Where is all the knowledge we lost with information? T. S. Eliot
Computer Organization and Assembly Language
Lecture 3 - Instruction Set - Al
Presentation transcript:

Lecture 3 - Instruction Set - Al Program Design (2) 9/20/6 Lecture 3 - Instruction Set - Al

Lecture 3 - Instruction Set - Al Lecture Overview Have seen the initial part of Top down design Modular design Now Parameter Passing Stack and Local Variables Structured Programming 9/20/6 Lecture 3 - Instruction Set - Al

Parameter Passing to Modules Modules (subroutines) should have no side effects Receive (access) only the data passed to it Modify and store/update only parameters in its formal output list Some subroutines trigger an event such as sounding an alarm, running a pump, etc. 9/20/6 Lecture 3 - Instruction Set - Al

Parameter passing example Subroutine PUT_CHAR displays a single character on the monitor. Main program action Push character on stack Call subroutine BSR PUT_CHAR PUT_CHAR knows the location, and as only 1 byte, the data might be passed in a data register More formal method places the data on the stack It can use 4(A7) or 6(A7) to access the character. 9/20/6 Lecture 3 - Instruction Set - Al

Parameter passing in Registers Works when the quantity of data is small or the processor has many, many registers. Passing arguments in registers is code that is position independent and reentrant. Position independent as no absolute address location involved in data transfer Reentrant as the registers would be saved before they are reused. 9/20/6 Lecture 3 - Instruction Set - Al

Mechanisms for Parameter Passing Ways in which parameters are passed. Pass-by-value: The current value of the variable at the time the subroutine call is made, is passed to the subroutine Pass-by-reference: The address of the variable is passed to the subroutine, i.e., a pointer. This allows modification of the variable back in the calling routine, by the subroutine. Mechanisms Registers - Memory Location - Stack 9/20/6 Lecture 3 - Instruction Set - Al

Lecture 3 - Instruction Set - Al Pass by Reference Subroutine to search a region of memory Text in memory Want to check for sequence of characters Info needed by subroutine Starting and ending address of text Start and ending address of the string Subroutine receives addresses when called Information in call – what string to find Note: Code is not reentrant and cannot be used by an interrupt routine 9/20/6 Lecture 3 - Instruction Set - Al

Lecture 3 - Instruction Set - Al Code example For using the stack to pass by reference. 9/20/6 Lecture 3 - Instruction Set - Al

Lecture 3 - Instruction Set - Al Figures for example Memory contents and The stack 9/20/6 Lecture 3 - Instruction Set - Al

Parameter Passing on the Stack Can use the stack to transfer the actual data Can be used to pass the addresses for pass-by-reference 9/20/6 Lecture 3 - Instruction Set - Al

Figures for this example 9/20/6 Lecture 3 - Instruction Set - Al

Stack and Local Variables Subroutines need access to space for local variables Possible that they fit in register but may not Allocate local storage space on stack. Keeps the subroutine reentrant Also bind the variables not only to the subroutine, but to the specific invocation 9/20/6 Lecture 3 - Instruction Set - Al

Lecture 3 - Instruction Set - Al Stack frame Allocation space on the stack LEA -200(SP),SP To restore stack prior to return LEA 200(SP),SP Refer to Fig 3.6 of text. 9/20/6 Lecture 3 - Instruction Set - Al

Lecture 3 - Instruction Set - Al Simplification LINK and UNLINK A instruction to specifically do this MOVE.L D0-D7,/A3-A6, -SP Save the specified registers on the stack LINK A1, #-64 Allocate 64 bytes (16 longwords) of on this stack frame Start subroutine 9/20/6 Lecture 3 - Instruction Set - Al

Lecture 3 - Instruction Set - Al Figures 9/20/6 Lecture 3 - Instruction Set - Al

Lecture 3 - Instruction Set - Al Subroutine example Calculate R=(P2 + Q2)/(P2 – Q2) 9/20/6 Lecture 3 - Instruction Set - Al

Lecture 3 - Instruction Set - Al Link Example The stack 9/20/6 Lecture 3 - Instruction Set - Al

Structured Programming A semiformal method of program development 3 benefits Inproves programmer productivity Program is easier to read Program is more reliable 9/20/6 Lecture 3 - Instruction Set - Al

Three fundamental components These are the basic elements of all high level functional programming languages. Sequence Action A, then action B, then action C, etc. A looping mechanism Finite loop – a set number of iterations Conditional loop – exit when condition occurs A decision mechanism If (condition) THEN action A ELSE action B 9/20/6 Lecture 3 - Instruction Set - Al

Lecture 3 - Instruction Set - Al GO TO???????????????????? All algorithms can be programmed using structured programming techniques without using a GO TO!!! 9/20/6 Lecture 3 - Instruction Set - Al

Lecture 3 - Instruction Set - Al Assignment 4 Problem 2-62 9/20/6 Lecture 3 - Instruction Set - Al