For the last several weeks I have been racking my brain to find a solution for a problem with forward referencing that can't be done in Nasm. I'm including a stripped down version of the macros.
[code]; assemble \nasm\bin\NASM -f win32
;link \nasm\bin\golink /console @\nasm\bin\GFL.txt <--- name of DLL's
;+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
; Console program with no import files and def's
; Klod
;++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
%imacro PROC 0-*
%push PROC
%if %0 =0
%assign %$params 0
%assign %$i 0
%assign %$params 0
%assign %$i 0 ;No Args or Params, so no stack frame
%elif %0 >= 1
push ebp
mov ebp,esp
%assign %$i 8
%rep %0
%rotate 1
%xdefine @%1 ebp+%$i
%assign %$i %$i+4
%endrep
%assign %$i 0
%assign %$params %0-1
%endif
%endmacro
%imacro ENDP 0-1
.@End_of_Proc:
%ifctx PROC
%if %$params =0
ret
%else
mov esp,ebp
pop ebp
%assign %$params %$params*4
ret %$params
%endif
%pop
%else
%error "PROC must be used before ENDPROC"
%endif
%endmacro
%macro invke 1-*.nolist
%rep %0-1
%rotate -1
push dword %1
%endrep
%rotate -1
%ifnid %1
%warning %1 'is a label'
%defstr temp, %1 ;remove the square brakets
%substr temp1 temp 4,-2
%deftok _funcname temp1
%warning _funcname 'is a label'
call _funcname
%else
extern %1
%warning defined extern
call %1
%endif
%endmacro
section .data
msg DB 'Press any key to continue...',13,10
DB 'This is the second line'
.len
message db "just a line to output",0
NewLine db 13,10,0
section .bss
hStdIn RESD 1
hStdOut RESD 1
hBuffer RESD 1
hNum RESD 1
hMode RESD 1
;*****************************************************************************************************************************
section .text
start:
invke GetStdHandle, -11 ;STD_OUTPUT_HANDLE
mov dword[hStdOut],eax
invke [Test1],hStdIn,msg
invke StdOut,NewLine
invke StdOut,NewLine
invke [TestProcwithlongname]
invke WriteFile, [hStdOut], DWORD msg, DWORD msg.len-msg, DWORD hNum, DWORD 0
invke GetStdHandle, -10 ;STD_INPUT_HANDLE
mov DWORD[hStdIn], eax
invke GetConsoleMode, eax, DWORD hMode
mov eax, DWORD[hMode]
and al, 1
invke SetConsoleMode, DWORD[hStdIn], eax
invke WaitForSingleObject, DWORD[hStdIn], DWORD 0xFFFFFFFF
invke ReadFile, DWORD[hStdIn], DWORD hBuffer, DWORD 1, DWORD hNum, DWORD 0
invke ExitProcess, DWORD 0
;****************************************************************************************************************************
Test1: Proc con,tre
invke WriteFile, dword[hStdOut], message, 22, DWORD hNum, DWORD 0
ENDP
TestProcwithlongname: Proc
invke WriteFile, dword[hStdOut], message, 22, DWORD hNum, DWORD 0
ENDP
[/code]
There is a small problem I have not been able to find an answer:
if I do:
call TestProcwithlongname works as expected
invke TestProcwithlongname ---> ERROR TestProcwithlongname redefined
invke [TestProcwithlongname] compiles but hangs
I have to remove the [] in the macro to make it work.
Anybody any Idea why?
Regards Klod