Copyright (C) 2000-2012 |
GNU Info (nasm.info)Section 4.9.34.9.3. `%local' Directive ------------------------- The `%local' directive is used to simplify the use of local temporary stack variables allocated in a stack frame. Automatic local variables in C are an example of this kind of variable. The `%local' directive is most useful when used with the `%stacksize' (see *Note Section 4.9.2:: and is also compatible with the `%arg' directive (see *Note Section 4.9.1::). It allows simplified reference to variables on the stack which have been allocated typically by using the `ENTER' instruction (see *Note Section B.4.65:: for a description of that instruction). An example of its use is the following: silly_swap: %push mycontext ; save the current context %stacksize small ; tell NASM to use bp %assign %$localsize 0 ; see text for explanation %local old_ax:word, old_dx:word enter %$localsize,0 ; see text for explanation mov [old_ax],ax ; swap ax & bx mov [old_dx],dx ; and swap dx & cx mov ax,bx mov dx,cx mov bx,[old_ax] mov cx,[old_dx] leave ; restore old bp ret ; %pop ; restore original context The `%$localsize' variable is used internally by the `%local' directive and _must_ be defined within the current context before the `%local' directive may be used. Failure to do so will result in one expression syntax error for each `%local' variable declared. It then may be used in the construction of an appropriately sized ENTER instruction as shown in the example. automatically generated by info2www version 1.2.2.9 |