Your assembly-language procedure can use the same technique for allocating temporary storage for local data that is used by high-level languages. To set up local data space, decrease the contents of SP just after setting up the stack frame. (To ensure correct execution, always increase or decrease SP by an even number.) Decreasing SP reserves space on the stack for local data. You must restore the space at the end of the procedure as follows:
push bp
mov bp,sp
sub sp,space
In the example above, space is the total size in bytes of the local data you want to allocate. Local variables are then accessed as fixed negative displacements from BP.
In the following example, the entry sequence establishes a stack frame and allocates temporary local storage for two words (4 bytes) of data. Later in the example, the program accesses the local storage, initializing both to 0.
push bp ; Save old stack frame.
mov bp,sp ; Set up new stack frame.
sub sp,4 ; Allocate 4 bytes of local storage.
.
.
.
mov WORD PTR [bp-2],0
mov WORD PTR [bp-4],0
Note that local variables are also called dynamic, stack, or automatic variables.