UT Dallas CS 4337 - #Sebesta ch10 subprogram imp (36 pages)

Previewing pages 1, 2, 17, 18, 19, 35, 36 of 36 page document View the full content.
View Full Document

#Sebesta ch10 subprogram imp



Previewing pages 1, 2, 17, 18, 19, 35, 36 of actual document.

View the full content.
View Full Document
View Full Document

#Sebesta ch10 subprogram imp

40 views


Pages:
36
School:
University of Texas at Dallas
Course:
Cs 4337 - Organization of Programming Languages

Unformatted text preview:

Chapter 10 Implementing Subprograms Chapter 10 Topics The General Semantics of Calls and Returns Implementing Simple Subprograms Implementing Subprograms with Stack Dynamic Local Variables Nested Subprograms Blocks Implementing Dynamic Scoping Copyright 2012 Addison Wesley All rights reserved 1 2 The General Semantics of Calls and Returns The subprogram call and return operations of a language are together called its subprogram linkage General semantics of calls to a subprogram Parameter passing methods Stack dynamic allocation of local variables Save the execution status of calling program Transfer of control and arrange for the return If subprogram nesting is supported access to nonlocal variables must be arranged Copyright 2012 Addison Wesley All rights reserved 1 3 The General Semantics of Calls and Returns General semantics of subprogram returns In mode and inout mode parameters must have their values returned Deallocation of stack dynamic locals Restore the execution status Return control to the caller Copyright 2012 Addison Wesley All rights reserved 1 4 Implementing Simple Subprograms Call Semantics Save the execution status of the caller Pass the parameters Pass the return address to the called Transfer control to the called Copyright 2012 Addison Wesley All rights reserved 1 5 Implementing Simple Subprograms continued Return Semantics If pass by value result or out mode parameters are used move the current values of those parameters to their corresponding actual parameters If it is a function move the functional value to a place the caller can get it Restore the execution status of the caller Transfer control back to the caller Required storage Status information parameters return address return value for functions temporaries Copyright 2012 Addison Wesley All rights reserved 1 6 Implementing Simple Subprograms continued Two separate parts the actual code and the non code part local variables and data that can change The format or layout of the non code part of an executing subprogram is called an activation record An activation record instance is a concrete example of an activation record the collection of data for a particular subprogram activation Copyright 2012 Addison Wesley All rights reserved 1 7 An Activation Record for Simple Subprograms Copyright 2012 Addison Wesley All rights reserved 1 8 Code and Activation Records of a Program with Simple Subprograms Copyright 2012 Addison Wesley All rights reserved 1 9 Implementing Subprograms with Stack Dynamic Local Variables More complex activation record The compiler must generate code to cause implicit allocation and deallocation of local variables Recursion must be supported adds the possibility of multiple simultaneous activations of a subprogram Copyright 2012 Addison Wesley All rights reserved 1 10 Typical Activation Record for a Language with Stack Dynamic Local Variables Copyright 2012 Addison Wesley All rights reserved 1 11 Implementing Subprograms with StackDynamic Local



View Full Document

Access the best Study Guides, Lecture Notes and Practice Exams

Loading Unlocking...
Login

Join to view #Sebesta ch10 subprogram imp and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view #Sebesta ch10 subprogram imp and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?