IntroductionToProcedures - Introduction to Procedures...

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

View Full Document Right Arrow Icon
Introduction to Procedures Beta Draft - Do not distribute © 2001, By Randall Hyde Page 541 Intr oduction to Procedures Chapter Eight 8.1 Chapter Overview In a procedural programming language the basic unit of code is the pr ocedur e . A procedure is a set of instructions that compute some v alue or tak e some action (such as printing or reading a character v alue). The defi nition of a procedure is v ery similar to the defi nition of an algorithm . A procedure is a set of rules to fol - lo w which, if the y conclude, produce some result. An algorithm is also such a sequence, b ut an algorithm is guaranteed to terminate whereas a procedure of fers no such guarantee. This chapter discusses ho w HLA implements procedures. This is actually the fi rst of three chapters on this subject in this te xt. This chapter presents HLA procedures from a high le v el language perspecti v e. A later chapter , Intermediate Procedures, discusses procedures at the machine language le v el. A whole v olume in this sequence, Adv anced Procedures, co v ers adv anced programming topics of interest to the v ery serious assembly language programmer . This chapter , ho we v er , pro vides the foundation for all that follo ws. 8.2 Procedures 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 xam - ple, the follo wing 80x86 instruction calls the HLA Standard Library wln routine 1 : call stdout.newln; The stdout.newln procedure prints a newline sequence to the console device and returns control to the instruction immediately following the “call stdout.newln;” instruction. Alas, the HLA Standard Library does not supply all the routines you will need. Most of the time you’ll have to write your own procedures. To do this, you will use HLA’s procedure declaration facilities. A basic HLA procedure declaration takes the following form: procedure ProcName ; << Local declarations >> begin ; << procedure statements >> end ; Procedure declarations appear in the declaration section of your program. That is, an ywhere you can put a ST A TIC, CONST , TYPE, or other declaration section, you may place a procedure declaration. In the syntax e xample abo v e, Pr ocName represents the name of the procedure you wish to defi ne. This can be an y v alid HLA identifi er . Whate v er identifi er follo ws the PR OCEDURE reserv ed w ord must also follo w the BEGIN and END reserv ed w ords in the procedure. As you’ v e probably noticed, a procedure declaration looks a whole lot lik e an HLA program. In f act, the only dif ference (so f ar) is the use of the PR OCEDURE reserv ed w ord rather than the PR OGRAM reserv ed w ord.
Background image of page 1

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

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the 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 / 28

IntroductionToProcedures - Introduction to Procedures...

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