1

I have a bit of C code that uses Assembly inlines. Supposed there is a simple function like

int f(int arg) {...}

declared in the C code but implemented in assembly. How does GCC pass the arguments and the return values between the C and ASM code? Is it stack push/pop? Registers?

The makefile uses options

gccc -Wall -g -std=c99 -pedantic -g
ArekBulski
  • 4,520
  • 4
  • 39
  • 61
  • 3
    This depends on the [ABI of the platform](https://en.wikipedia.org/wiki/Application_binary_interface). – zx485 May 22 '18 at 18:31
  • Its x86_64 architecture. Would cdelc calling convention be the default for gcc compiler? @zx485 – ArekBulski May 22 '18 at 18:37
  • 2
    @ArekBulski No, the [SYS V x86_64 ABI](https://www.uclibc.org/docs/psABI-x86_64.pdf) is (unless you compile for x32 or x86). You can google it or search it here, there are plenty of QA about it. – Margaret Bloom May 22 '18 at 18:47
  • 1
    @ArekBulski On x86_64, the exact calling convention depends on what operating system you are programming for. – fuz May 22 '18 at 20:09
  • Its compiled and runned on Ubuntu (linux). – ArekBulski May 22 '18 at 22:09
  • (The answer there includes the function calling convention, as well as system-call convention.) – Peter Cordes May 22 '18 at 22:27
  • @ArekBulski In this case, see the documentation linked to by Margaret Bloom. [Wikipedia](https://en.wikipedia.org/wiki/X86_calling_conventions#System_V_AMD64_ABI) has a slightly simpler explanation of how that works. – fuz May 23 '18 at 10:06

0 Answers0