Hi Bryant,
Thanks for your answer.
I have played around with your suggestion and wrote a little test piece, its Windows using c-runtime library for i/o and no macros, so it should be easy to run on U-nix:
BITS 32
EXTERN printf
EXTERN getchar
EXTERN exit
Section .data
nl db 10,13,0
SzPurpose db "Test enter/leave instruction",0
szBar db "-------------------------------",0
format db "%s Stack address %X",0
format1 db "Stack address proc2 %x %x %x",0
format2 db "%s %s %s",0
Section .code
Global Start
Start:
push dword nl
push dword nl
push dword SzPurpose
push format2
call printf
sub esp,4*4
call proc1
push dword nl
push dword szBar
push dword nl
push format2
call printf
sub esp,4*4
call proc2
call getchar
call exit
proc1:
%push
%stacksize flat
%assign %$localsize 0
%assign %$elements 0
%rep 8
%local %[my_array_%{$elements}]:byte
%assign %$elements %$elements + 1
%endrep
enter %$localsize, 0
mov al,65h ;fill array with letter e
lea edi,[my_array_7]
mov ecx, dword 31 ;one less than buffer size
.e:
mov [edi],al
inc edi
dec ecx
cmp ecx,0
jne .e
mov [edi],byte 0 ;apend 0 to end of string
lea eax, [my_array_7]
push dword eax
lea eax, [my_array_7]
push dword eax
push format
call printf
sub esp, 3*4
leave
; %undef my_array_7 <--scope issue
%pop
ret
proc2:
%push
%stacksize flat
%assign %$localsize 0
%assign %$elements 0
%local pr2Arg1:dword
%rep 8
%local %[array_%{$elements}]:byte
%assign %$elements %$elements + 1
%endrep
%warning %$localsize %[array_%{$elements}] %$elements
enter %$localsize, 0
lea eax,[pr2Arg1]
push eax
lea eax,[array_7]
push dword eax
lea eax,[my_array_0]
push dword eax
push format1
call printf
sub esp, 4*4
leave
%pop
ret
NAsm -fwin32; golink /console \entry Start \user32.dll kernel32.dll crtdll.dll
I allocate buffers on the stack as multiple dwords and thought your option would work for my requirements despite that each dword allocated would have its own name. On closer examination I found a scope issue. Nasm will complain if I don't define a local but will not complain if that local was defined in another proc as local. I have never considered this to be a problem since %define x ebp-4 defined in proc1 would not cause conflict in proc2 when %assign x ebp-8.
I have just spent 2 month tracking down the worst bug in my amateur carrier. After upgrading to a windows 7 machine, I transfered all my test code samples/libraries and bugsinga, the antivirus program quarantined dozens of these gems. I tried recompiling them but they were already quarantined before Nasm was finished compiling. The programs would compile and run under my XP setup like on day 1.
A combination proc,local uses call ADDR macro instructions would push an extra argument on the stack for some calls. Combined with an incorrect-scoped argument... I suppose stack overflow is the term?
I decided to continue to manage stack variable manually and consider de-allocating arguments on exit of procs De-allocating above array would be to cumbersome. I will aim to produce “robust” in the future...
Mich