Chapter 8 - Advanced Procedures

Global variables - are declared in the .data segment and exist throughout the duration of the program.

Local variables - are created and destroyed during a single procedure.

Advantages of local variables include:

LOCAL directive The LOCAL directive declares one or more local variables and must be placed (if used) immediately following a PROC directive. The general form is:

LOCAL varlist

where varlist is a list of variables of the form label:type
Examples include:

MyProc1 PROC
        LOCAL v1:BYTE

MyProc2 PROC
        LOCAL temp:DWORD, flag:BYTE

MyProc3 PROC
        LOCAL name[10]:BYTE
Let's examine the automatic code generation for:

BubbleSort PROC
           LOCAL temp:DWORD, SwapFlag:BYTE
as described on p. 262

Note: If you are going to have local arrays of any size, make sure you've allocated enough stack space such as: .stack 8192

INVOKE directive The INVOKE directive allows arguments to be passed to the procedure. The general syntax is:

INVOKE procName [,argument(s)]
Let's look at INVOKE AddTwo, val1, val2 on p. 265.

Now let's examine the following program:


TITLE CalcSum Program                   (Csum.asm)

INCLUDE Irvine32.inc

.stack 4096

.data
x1 byte 1
y1 byte 3

.code
CalcSum PROC x:byte, y:byte
  LOCAL temp:byte

  mov al,x
  add al,y
  mov temp,al
  add al,temp
L2:	ret
CalcSum ENDP

main PROC
  mov eax,0
  INVOKE CalcSum , x1, y1
  call WriteDec
  call Crlf
  exit
main ENDP
end Main
P1: Show the stack before the instruction mov al,x is executed.

Let's examine the ArraySum example on p. 269.

a Finally, let's examine passing by value vs passing by reference on p. 270.


©Douglas J. Ryan/ryandj@pacificu.edu