0

I have this code in c :

#include <stdio.h>
#include <inttypes.h>
#include <stdlib.h>

extern int64_t myprintf(char* e, int64_t i,...);

int main()
{
    
    myprintf("%s",'H','e','l','l');

    exit(EXIT_SUCCESS);
}

and i compile with this command gcc -no-pie -g fnt.c mp.s -o hello.out

there is my ATT function :

    movq 16(%rsp),%rax  /* format */
    movq 24(%rsp),%rbx  /* 1er param */
    movq 32(%rsp),%r8   /* 2e param */
    movq 40(%rsp),%r9   /* 3e param */
    movq 48(%rsp),%r10  /* 4e param */

and i cant get my C values for example --> get 'e' in %rbx ...

Thank you !

Nate Eldredge
  • 48,811
  • 6
  • 54
  • 82
nonamed
  • 1
  • 1
  • 2
    What is your calling convension? Writing the function `fnt` in C and seeing how it is conveted to assembly via your compiler (`-S` option is useful for gcc) will be helpful. – MikeCAT Feb 20 '21 at 00:34
  • 1
    Or just compiling your `main` function and seeing how the arguments are stored will be useful. – MikeCAT Feb 20 '21 at 00:36
  • didnt really get what you want me to do – nonamed Feb 20 '21 at 01:03
  • I assume you're following SysV calling conventions, since they prevail on most platforms that use gcc/gas. You seem to be assuming that all parameters are passed on the stack, but that's not correct - the first 6 are in registers. See [the ABI](https://stackoverflow.com/questions/18133812/where-is-the-x86-64-system-v-abi-documented). – Nate Eldredge Feb 20 '21 at 02:21
  • MikeCAT is suggesting you look at [the assembly generated by the compiler for `main`](https://godbolt.org/z/WYnYd1), and observe that it is putting all the arguments in registers, none on the stack. – Nate Eldredge Feb 20 '21 at 02:23
  • Neither of the mainstream x86-64 calling conventions pass args on the stack, they use registers for the first 6 integer/pointer args (or on Windows, first 4 args) – Peter Cordes Feb 20 '21 at 02:40

0 Answers0