Why does the syntax matter?
What matters is getting the constraint strings right. The actual instruction between the first pair of quotes doesn't really matter.
This "works" (compiles without complaint)
Code:
$ cat foo.c
#include <stdio.h>
void foo ( unsigned long count, ...)
{
for(;count > 0;count--)
{
int cur_val;
asm("pop %0\n" : :"m"(cur_val) );
printf("Value=%x\n", cur_val);
}
}
int main()
{
foo(3,22,44,66);
return 0;
}
$ gcc -masm=intel foo.c
$ ./a.out
Value=0
Value=8048500
Value=8048500
It doesn't work because the top of the stack are not parameters, but the return address (and other things).
The variadic parameters would be accessible though ebp, not esp.
The generated code around the asm looks like this
Code:
.globl foo
.type foo, @function
foo:
push ebp
mov ebp, esp
sub esp, 24
jmp .L2
.L3:
#APP
# 9 "foo.c" 1
pop DWORD PTR [ebp-4]
# 0 "" 2
#NO_APP
mov eax, DWORD PTR [ebp-4]