calling c function from assembly
Posted
by
void
on Stack Overflow
See other posts from Stack Overflow
or by void
Published on 2011-01-13T03:47:48Z
Indexed on
2011/01/13
3:54 UTC
Read the original article
Hit count: 253
I'm trying to use a function in assembly in a C project, the function is supposed to call a libc function let's say printf() but I keep getting a segmentation fault.
In the .c file I have the declaration of the function let's say
int do_shit_in_asm()
In the .asm file I have
.extern printf
.section .data
printtext:
.ascii "test"
.section .text
.global do_shit_in_asm
.type do_shit_in_asm, @function
do_shit_in_asm:
pushl %ebp
movl %esp, %ebp
push printtext
call printf
movl %ebp, %esp
pop %ebp
ret
Any pointers would be appreciated.
as func.asm -o func.o gcc prog.c func.o -o prog
© Stack Overflow or respective owner