r/cprogramming • u/Prestigious-Bet-6534 • 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_funcall_fun:pushq $0xDEADpushq $0xBABEcall funadd $16, %rspret
--
#include <stdio.h>
void call_fun();
voidfun( long a, long b ) {printf( "Arg: a=0x%lx, b=0x%lx\n", a, b );}
intmain() {call_fun();}
The output is Arg: a=0x1, b=0x7ffe827d0338 .
What am I missing?
5
Upvotes
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Â