I'm trying to write a macro (in x86 assembly) that invokes a function with arguments. Variable number of arguments, that is. The functions is the first macro argument, and function arguments are 2nd-nth macro arguments.
In other words, INVOKE foo, 1, 2, 3 should expand to (stdcall convention):
push arguments
call foo
clean stack
I figured irp should do the trick, and wrote the following:
.intel_syntax noprefix
.arch i386
.data
if: .asciz "%i\n"
.text
.macro INVOKE func, argList
.irp arg,<argList>
push \arg
.endr
call \func
.irp arg,<argList>
add esp, 4
.endr
.endm
And for the test:
.globl main
.extern foo
main:
INVOKE foo, 1, 5, 10, 15
push eax
push offset if
call printf
ret
.end
With a separate c file with foo:
int foo(int a, int b, int c, int d) {
return a + b + c + d;
}
But, compiling this (using GCC) with:
gcc filename.s filename.c -o filename.out
produces the following message:
filename.s: Assembler messages:
filename.s:21: Error: too many positional arguments