- Intermediate Procedures Beta Draft Do not distribute © 2001 By Randall Hyde Page 805 Intermediate Pr ocedures Chapter Three 3.1 Chapter

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Intermediate Procedures Beta Draft - Do not distribute © 2001, By Randall Hyde Page 805 Intermediate Pr ocedures Chapter Three 3.1 Chapter Overview This chapter picks up where the chapter “Introduction to Procedures” in V olume Three lea v es of f. That chapter presented a high le v el vie w of procedures, parameters, and local v ariables; this chapter tak es a look at some of the lo w-le v el implementation details. This chapter be gins by discussing the CALL instruction and ho w it af fects the stack. Then it discusses acti v ation records and ho w a program passes parameters to a procedure and ho w that procedure maintains local (automatic) v ariables. Ne xt, this chapter presents an in-depth discussion of pass by v alue and pass by reference parameters. This chapter concludes by discussing procedure v ariables, procedural parameters, iterators, and the FOREA CH..ENDFOR loop. 3.2 Procedures and the CALL Instruction Most procedural programming languages implement procedures using the call/return mechanism . That is, some code calls a procedure, the procedure does its thing, and then the procedure returns to the caller . The call and return instructions pro vide the 80x86’ s pr ocedur e in vocation mec hanism . The calling code calls a procedure with the CALL instruction, the procedure returns to the caller with the RET instruction. F or e xample, the follo wing 80x86 instruction calls the HLA Standard Library stdout.ne wln routine: call stdout.newln; stdout.ne wln prints a carriage return/line feed sequence to the video display and returns control to the instruction immediately following the “call stdout.newln;” instruction. The HLA language lets you call procedures using a high level language syntax. Specifically, you may call a procedure by simply specifying the procedure’s name and (in the case of stdout.ne wln ) an empty parameter list. That is, the follo wing is completely equi v alent to “call stdout.ne wln”: stdout.newln(); The 80x86 CALL instruction does tw o things. First, it pushes the address of the instruction immedi- ately follo wing the CALL onto the stack; then it transfers control to the address of the specifi ed procedure. The v alue that CALL pushes onto the stack is kno wn as the r eturn addr ess . When the procedure w ants to return to the caller and continue e x ecution with the fi rst statement follo wing the CALL instruction, the pro- cedure simply pops the return address of f the stack and jumps (indirectly) to that address. Most procedures return to their caller by e x ecuting a RET (return) instruction. The RET instruction pops a return address of f the stack and transfers control indirectly to the address it pops of f the stack....
View Full Document

This note was uploaded on 08/08/2011 for the course CS 101 taught by Professor Jitenderkumarchhabra during the Summer '11 term at National Institute of Technology, Calicut.

Page1 / 48

- Intermediate Procedures Beta Draft Do not distribute © 2001 By Randall Hyde Page 805 Intermediate Pr ocedures Chapter Three 3.1 Chapter

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online