The LOCAL directive defines local stack variables from within a code procedure.
Syntax
LOCAL Local-Spec [, [LineBreak] Local-Spec ...]
Local-Spec:
The LOCAL assembler directive can only appear within the body of a procedure. If used, the LOCAL directive(s) must immediately follow the PROC statement that encloses them, and they must appear before any instructions, code labels, or directives that modify the location counter. Multiple LOCAL directives may appear in succession.
Each Local-Name is defined as a Numeric-EquateName that is visible only from within the body of the procedure. The value assigned to the variable name is an expression that defines the type of the variable and its location on the stack relative to the value of the frame pointer (the BP or EBP register). The assembler reserves space on the stack for each local variable and automatically calculates their locations. After all Local-Spec entries have been processed, the assembler allocates the space by generating instructions to adjust the stack pointer. The assembler also generates instructions to restore the state of the stack and frame pointers when the procedure exits.
The optional [Count] entry can be used to indicate that the variable is a simple "array" of values, where Count is a constant expression. If used, the square brackets surrounding the Count must be specified. Use of this notation is discouraged however, because it does not associate a "true array" data type with the variable, and cannot be viewed as such from within a symbolic debugger. ALP allows the variable to be associated with a "true array" data type through use of the native Type-Declaration syntax.
The Type-Declaration field specifies the data type to be associated with the Local-Name. If this field is omitted, the data type defaults to WORD if the procedure is defined within a USE16 segment, and DWORD if the procedure is defined within a USE32 segment.
; bootdrv.asm : Returns value of OS/2 boot drive as exit code
; assemble as : alp +Od bootdrv.asm
; link as : link386 /de bootdrv;
.386 ; Assemble for 32-bit processors
.model flat,syscall ; OS/2 flat model/calling convention
.stack 4096
EXTERN DosExit:PROC ; OS/2 DosExit() API
EXTERN DosQuerySysInfo:PROC ; OS/2 DosQuerySysInfo() API
INCLUDELIB os2386.lib ; link with these routines
; These are values taken from OS/2 API headers. See the OS/2 Toolkit
; Control Program Programming Guide and Reference for more information.
EXIT_PROCESS EQU 1 ; for DosExit
QSV_BOOT_DRIVE EQU 5 ; For DosQuerySysInfo
ULONG TYPEDEF DWORD ; use OS/2 type convention
.code ; open code segment
main PROC
LOCAL BootDrive:ULONG ; place to put value of boot drive
; Push parameters to DosQuerySysInfo onto the stack
PUSH sizeof BootDrive ; arg 4: size of output buffer
LEA EAX,BootDrive ; arg 3: Address of buffer
PUSH EAX
PUSH QSV_BOOT_DRIVE ; arg 2: last ordinal value to return
PUSH QSV_BOOT_DRIVE ; arg 1: first ordinal, same as last
CALL DosQuerySysInfo ; invoke API
ADD ESP,DWORD * 4 ; remove the parameters from the stack
CMP EAX,0 ; Did the API succeed?
MOV EAX,0 ; if not, use zero as a return code
JNZ SomeKindOfError ; and skip around to the exit logic
MOV EAX,BootDrive ; else, return the boot drive value
SomeKindOfError:
push EAX ; exit code
push EXIT_PROCESS ; terminates all threads
call DosExit ; exit to calling process
RET ; never executed
main ENDP
END main