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.

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
The University of Adelaide, School of Computer Science
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)
Apr. 12, 2000Systems Architecture I1 Systems Architecture I (CS ) Lecture 6: Branching and Procedures in MIPS* Jeremy R. Johnson Wed. Apr. 12, 2000.
Procedure call frame: Hold values passed to a procedure as arguments
EECC250 - Shaaban #1 Lec # 6 Winter Stack-Related Instructions PEA Push Effective Address Calculates an effective address and pushes it.
Functions Functions and Parameters. History A function call needs to save the registers in use The called function will use the registers The registers.
Loops, and sub-routines Interrupts Can be very useful in control applications particularly when the microprocessor must perform two tasks apparently.
Subroutines: Passing Arguments Using the Stack. Passing Arguments via the Stack Arguments to a subroutine are pushed onto the stack. The subroutine accesses.
Faculty of Computer Science © 2006 CMPUT 229 Subroutines - Part 2 Calling Itself.
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:
EECC250 - Shaaban #1 lec #7 Winter Local workspace of a subroutine: A number of temporary memory locations required by the subroutine for temporary.
Stacks and HeapsCS-502 Fall A Short Digression Stacks and Heaps CS-502, Operating Systems Fall 2007 (Slides include materials from Operating System.
CEG 320/520: Computer Organization and Assembly Language ProgrammingThe Stack and Subroutines 1 The Stack and Subroutines.
EECC250 - Shaaban #1 lec #8 Winter Recursive Subroutine Calls Example The purpose of this example is to examine how all parameters, local variables,
CEG 320/520: Computer Organization and Assembly Language ProgrammingFlow Control 1 Flow Control.
CPE/EE 421 Microcomputers: Motorola 68000: Assembly Language and C Instructor: Dr Aleksandar Milenkovic Lecture Notes.
7/23 C Programming in Embedded Systems Computer Science & Engineering Department Arizona State University Tempe, AZ Dr. Yann-Hang Lee
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.
1 Control Abstraction (Section ) CSCI 431 Programming Languages Fall 2003 A compilation of material developed by Felix Hernandez-Campos and Michael.
Passing Parameters using Stack Calling program pushes parameters on the stack one element at a time before calling subroutine. Subroutine Call (jsr, bsr)
Procedure (Method) Calls Ellen Spertus MCS 111 September 25, 2003.
9/20/6Lecture 2 - Prog Model Architecture, Data Types and Addressing Modes.
Computer Architecture CSE 3322 Lecture 4 crystal.uta.edu/~jpatters/cse3322 Assignments due 9/15: 3.7, 3.9, 3.11.
CSC 8505 Compiler Construction Runtime Environments.
Assembly Language Co-Routines
Calling Procedures C calling conventions. Outline Procedures Procedure call mechanism Passing parameters Local variable storage C-Style procedures Recursion.
1 Subroutines Advanced Programming. 2 Top-Down approach to problem solving Algorithm step by step description of how to solve a problem Divide and Conquer.
Chapter 14 Functions.
C Calling Conventions parameters are passed on the run-time or system stack, SP (or A7) parameters pushed on stack in “right to left” order of call A6.
Computer Architecture & Operations I
Computer Science 210 Computer Organization
Figure 8.1 of course package
Subroutines … passing data
Procedures (Functions)
Stack Frames Stack frame = block of memory located in the system stack that contains: return address input parameters (from calling program to subroutine)
Functions and Procedures
Lecture 3 - Instruction Set - Al
Subroutines … a 1st look procedures and functions in high level languages are modeled on subroutines typically, assembly code is very modular with.
Interfacing with I/O Devices
CPE/EE 421 Microcomputers: Motorola 68000: Assembly Language and C
Stack Frame Linkage.
MIPS Instructions.
Passing Parameters Data passed to a subroutine is called a parameter.
The University of Adelaide, School of Computer Science
EECE.3170 Microprocessor Systems Design I
68000 Architecture, Data Types and Addressing Modes
; main program ; main move Param2, -(sp) move Param1, -(sp) Call Sub1
EECE.3170 Microprocessor Systems Design I
EECE.3170 Microprocessor Systems Design I
Figure 8.1 of course package
The MOVE Multiple: MOVEM Instruction
EECE.3170 Microprocessor Systems Design I
Subroutines … passing data
Systems Architecture I
Basic Instruction Cycle
Runtime Environments What is in the memory?.
Computer Architecture
Program Pass I LC Symbol Table Pass II Machine Code ORG $400
Introduction Lab1 A crash course in assembler programming
Ithaca College Machine-Level Programming VII: Procedures Comp 21000: Introduction to Computer Systems & Assembly Lang Spring 2017.
Lecture 3 - Instruction Set - Al
Procedure Support From previous study of high-level languages, we know the basic issues: - declaration: header, body, local variables - call and return.
ECE511: Digital System & Microprocessor
Runtime Stack Activation record for hanoi;
Lecture 3 - Instruction Set - Al
Presentation transcript:

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 in a multitasking or multiuser or multithreaded environment, a single copy of a subroutine may be shared by more than one task/user/thread Reentrant subroutine Task A Task B

Reentrant Code Characteristics requirements: any parameters or local variables must be on the stack frame registers may be used for parameters and local variables but must be saved on or restored from the stack at beginning/end of the subroutine guarantee that each call of the subroutine will create a separate stack frame to maintain data integrity no self-modifying code

Recursion recursive code must be reentrant recursive  reentrant but reentrant  recursive e.g. calculating 3! using recursion main move.w number,D0 pass the number jsr fact start recursive rtn move.w D0,result store the factorial stop #$2700 number dc.w 3 result ds.w 1

fact link A6,#-2 Stack structure move.w D0,-2(A6) subq.w #1,D0 bne push move.w -2(A6),D0 bra return push jsr fact mulu -2(A6),D0 return unlk A6 rts end main SP ->///////

A much more complex example: X: array [0..30] of words Y: longword Z, ALPHA, N: byte call order is S/R demo(X, Y, Z, ALPHA, N ) N is passed/returned by value, all others are passed by reference

demo(X[w:31], Y[l], Z[b], ALPHA[b], N[b]) main CLR.W D2 zero entire word MOVE.B N,D2 N to low byte MOVE.W D2,-(SP) N on stack PEA ALPHA push arguments PEA Z in reverse order PEA Y PEA X JSR demo call the routine MOVE.B ___,___ get returned value ADDA.L #__,SP fix up stack … STOP #$2700

demo(X[w:31], Y[l], Z[b], ALPHA[b], N[b]) => demo local variables: a[l], b[w], c[b] demo LINK A6,#-8 MOVEM.L D1/A1-A2,-(SP) … CLR.W D0 MOVE.B __(A6),D0 ;get N MOVE.W D0,-(SP) ; and pass it PEA __(A6) ;pass c addr MOVE.L __(A6),-(SP) ;pass Z addr PEA __(A6) ;pass a addr MOVE.L __(A6),-(SP) ;pass X addr JSR demo ;call demo(X,a,Z,c,N) ADDA.L #__,SP ;fix stack MOVE.B ;get N …

demo(X[w:31], Y[l], Z[b], ALPHA[b], N[b]) => demo local variables: a[l], b[w], c[b] * how to access some of the variables … MOVEA.L __(__),A0 1st array element MOVE.W ___,__ of X into “b” * Y into a MOVEA.L __(__),A1 MOVE.L ___,__ * access Z MOVEA.L __(__),A2 MOVE.B ___,D1 * change ALPHA MOVEA.L __(__),A3 CLR.B ___

Reading: Expectations: Introduction to Reentrancy [Jack Ganssle, Embedded Systems Design (03/15/01, 01:03:35 PM EST)] -- excellent article that illustrates potential issues with high level languages and the importance of knowing how your high level language will be translated into assembly language Reentrancy [2008 The Ganssle Group] -- excellent article with different examples and discussion of potential issues Reentrancy in Protocol Stacks [T. Sridhar, Embedded Systems Design (11/01/01, 09:42:22 AM EST)] -- very well written but much more advanced discussion due to the networking example used, read only if interested essentially any book on programming for concurrent, parallel, or embedded systems will have a discussion on reentrant code Expectations: you should be able to identify reentrant code you should be able to write reentrant code you should be able to write recursive code