0

I have to make a work for collegue in which I have to write everything in assembly lenguage for the AMD64.

I'm allowed to import some C functions from C Standar Library (as a matter of facts, some are compulsory), yet I have no idea how to make the VA_LIST work. (Which I've been informed is necessary to make some of those functions work)

Here you have what some other user of StackOverflow gently suggested me to see: What is the format of the x86_64 va_list structure?

And this is what I did so far:

section .data
va_list: 

    dd 0; gp
    dd 0; fp
    dq 0; overflow
    dq 0; reg

    <code>
    mov [va_list+16], _direction_of_the_int_I_want_to_pass;
    mov rdx, va_list
    call _function_I_want_to_call        

This for some reason isn't working. Should I create the va_list structure in a different way? Should the other data be different than 0? (I mean, I don't use any stack on my function)

Community
  • 1
  • 1
NacOverflow
  • 97
  • 1
  • 2
  • 8
  • I suspect you're mistaken about needing to make a va_list. Unless you're calling the v-prefixed function that takes a va_list (like `vfprintf`) rather than the variadic one (like `fprintf`), you never need to use a va_list. – R.. GitHub STOP HELPING ICE Sep 12 '12 at 05:03
  • If you think you need to pass a `va_list`, try finding a version of the function that is variadic (as @R.. says, usually the function with the `v` left off). Variadic functions are easier to call from assembly and don't require mucking around with `va_list`. – nneonneo Sep 12 '12 at 05:06
  • That's weird... a little while ago I was told that I needed to use val_list for functions like fprintf. (In here http://stackoverflow.com/questions/12377777/in-assembler-amd64-i-call-fprintf-but-it-keeps-looping-infinitely) However, the guy seems to have deleted it, so I guess he was wrong. -__- – NacOverflow Sep 12 '12 at 05:06
  • 1
    `fprintf` is variadic. Just follow the standard C calling convention for your ABI to add as many arguments as you need. – nneonneo Sep 12 '12 at 05:07
  • Yes, he was wrong. See my comments on your other question for ideas what might be wrong. – R.. GitHub STOP HELPING ICE Sep 12 '12 at 05:10

0 Answers0