Local variables - are created and destroyed during a single procedure.
Advantages of local variables include:
LOCAL varlist where varlist is a list of variables of the form label:typeExamples include:
MyProc1 PROC LOCAL v1:BYTE MyProc2 PROC LOCAL temp:DWORD, flag:BYTE MyProc3 PROC LOCAL name[10]:BYTELet's examine the automatic code generation for:
BubbleSort PROC LOCAL temp:DWORD, SwapFlag:BYTEas 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 MainP1: 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.