%warning __NASM_VER__ 2.10rc2-20101123
%macro definem 2+
mac %1,%2
%endmacro
%macro mac 2-*
EXTERN %1
%macro %[%1] 1
push %1
call %?
%endmacro
%endm
definem printf,ptr
definem ExitProcess,NULL
definem scanf,ptr
[BITS 32]
[CPU 486]
%macro definem 2+
mac %1, %2
%endmacro
%macro mac 2-*
%push
EXTERN %1
%assign %$ac (%0 -1)
%macro %[%1] %$ac
%rep %0
%rotate -1
push %1
%endrep
call %?
add esp, (%0 * 4)
%endmacro
%pop
%endmacro
definem printf, format, message
definem exit, errcode
SECTION .text
GLOBAL main
main:
printf dword strFormat, dword strMessage
sub eax, eax
exit eax
SECTION .data
strFormat DB "[+] %s", 10
strMessage DB "Hello, World!", 0
b0x$ nasm -v
NASM version 2.10rc2 compiled on Nov 28 2010
b0x$ nasm -f elf -o klod.o klod.asm
b0x$ cc klod.o -o klod
b0x$ ./klod
[+] Hello, World!
b0x$
Code: [Select]%assign %$ac (%0 -1)
%macro %[%1] %$ac
Works, but requires such a temporary smacro to allow arbitrary computation of the mmacro's parameter count. %macro should accept a critical expression in parentheses (similar to the handling of "section ... align="). I'll prepare a patch when time permits.
[BITS 32]
[CPU 486]
%macro definem 2+
%1: mac %1, %2
%endmacro
%macro mac 2-*
%push
EXTERN %1
%assign %$ac (%0 -1)
%xdefine caller %1
%macro %[%1] 0-%$ac
%rep %0
%rotate -1
push %1
%endrep
call %00
add esp, (%0 * 4)
%endmacro
%pop
%endmacro
definem printf, format, message
definem exit, errcode
SECTION .text
GLOBAL main
main:
printf dword strFormat, dword strMessage
sub eax, eax
exit eax
SECTION .data
strFormat DB "[+] %s", 10, 0
strMessage DB "Hello, World!", 0