Program Design (2) - PowerPoint PPT Presentation

1 / 21
About This Presentation
Title:

Program Design (2)

Description:

Title: ECE 765 Microcomputer Structures Author: Joanne E. DeGroat Last modified by: Joanne Degroat Created Date: 9/19/2006 2:40:47 AM Document presentation format – PowerPoint PPT presentation

Number of Views:33
Avg rating:3.0/5.0
Slides: 22
Provided by: Joan102
Category:
Tags: design | program | stack

less

Transcript and Presenter's Notes

Title: Program Design (2)


1
Program Design (2)
2
Lecture Overview
  • Have seen the initial part of
  • Top down design
  • Modular design
  • Now
  • Parameter Passing
  • Stack and Local Variables
  • Structured Programming

3
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.

4
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.

5
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.

6
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

7
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

8
Code example
  • For using the stack to pass by reference.

9
Figures for example
  • Memory contents and The stack

10
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

11
Figures for this example
  • Fig 3.6

12
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

13
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.

14
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

15
Figures
16
Subroutine example
  • Calculate R(P2 Q2)/(P2 Q2)

17
Link Example
  • The stack

18
Structured Programming
  • A semiformal method of program development
  • 3 benefits
  • Inproves programmer productivity
  • Program is easier to read
  • Program is more reliable

19
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

20
GO TO????????????????????
  • All algorithms can be programmed using structured
    programming techniques without using a GO TO!!!

21
Assignment 4
  • Problem 2-62
Write a Comment
User Comments (0)
About PowerShow.com