Note : I use that answer to be able to say more than it is possible through a remark, and using gcc.
First, just doing g++ testing.c
g++ is not able to link with the assembler file which is not specified, so of course helloWorld is missing.
If I have the file hw.c :
int helloWorld()
{
return 123;
}
I ask to produce the source assembler through the option -S
(I also use -O
to reduce the assembler source size), so I do not have to write the assembler file by hand and I am sure it is compatible with gcc :
/tmp % gcc -O -S hw.c
That produced the file hw.s :
/tmp % cat hw.s
.file "hw.c"
.text
.globl helloWorld
.type helloWorld, @function
helloWorld:
.LFB0:
.cfi_startproc
movl $123, %eax
ret
.cfi_endproc
.LFE0:
.size helloWorld, .-helloWorld
.ident "GCC: (GNU) 4.4.7 20120313 (Red Hat 4.4.7-16)"
.section .note.GNU-stack,"",@progbits
/tmp %
Also having the file m.c :
#include <stdio.h>
extern int helloWorld();
int main()
{
printf("%d\n", helloWorld());
return 0;
}
I can do :
/tmp % gcc m.c hw.s
/tmp % ./a.out
123
I propose you to do the same as, write helloWorld in C then generate the assembler with option -S
, doing that you are sure to follow the gcc requirements in the function definition