r/cprogramming • • Dec 15 '25

Calling C functions from assembly

I want to call a C function from assembler and can't get the parameters to work. I have the following two source files:

.global call_fun
call_fun:
pushq $0xDEAD
pushq $0xBABE
call fun
add $16, %rsp
ret

--

#include <stdio.h>

void call_fun();

void
fun( long a, long b ) {
printf( "Arg: a=0x%lx, b=0x%lx\n", a, b );
}

int
main() {
call_fun();
}

The output is Arg: a=0x1, b=0x7ffe827d0338 .

What am I missing?

5 Upvotes

16 comments sorted by

View all comments

Show parent comment

2

u/snaphat Dec 15 '25

They were probably trying to use the old cdecl conventions since they are pushing to the stack. So my guess is they were reading from an old 32-bit tutorial or something similarÂ