Search code examples
assemblyx86att

Arbitrary number of parameters in Assembler (x86, att)


I'm creating a function with the following signature:

int function_test (char *something, ...);

Let's suppose that on *something there's something that will allow me to know how many parameters were passed (just like printf does with '%').

So I store the current parameter number in %ebx as a multiple of 4, starting from 8, so I can get 8(%ebp), 12(%ebp), etc.

How do I do to get the content of that parameter? When I try:

movl %ebx(%ebp),variable

I get an error(junk %ebp after register).

How can I get the content of that parameter? And what would be the syntax to increment its value?


Solution

  • movl (%ebp, %ebx), %eax. Note you can't have two memory references, so if you want that in variable you will have to do it in two steps. To increment obviously use inc not mov.