Page 1 of 1

Assembly calling from c and linking

Posted: Wed May 02, 2012 11:54 am
by krix
Hi,

I want some advice, how to call assembly function correctly from C code. For C compiler I use gcc, but for assembly it is nasm. And together I link those object files with gcc linker. But all goes so bad, when I try to call assembly function from C. It can be empty function e.t.c. but in Bosch I got triple fault or hangs random, or in Virtual Box worse - hangs my whole PC :lol: Maybe it is linker issue, lost tags or something? The function even not executed. Botch won't log anything, there are nothing in log except grub logs.


So my code is very simple. I have loader, what is calling, with call _kmain function, from C and it is working wery well.
I can make seperate test assembly file with simple function:

GLOBAL _c_dummy
_c_dummy:

ret

But in C code:

extern void _c_dummy(); I have tried also c_dummy(); strange is that, that nothing changes.
c_dummy(); and at this point all hangs or triple faults.

Internet is full with instructions, how to call assembly from c, but nothing works. Even, when I compile native win32 app, i can't call assembly from that.

Re: Assembly calling from c and linking

Posted: Wed May 02, 2012 11:58 am
by bluemoon
If you linked the code without error, the cause is usually elsewhere. did you tried not to call the asm function and do it triple fault?
So my code is very simple. I have loader, what is calling, with call _kmain function
Are you sure the address is correct? try objdump the executable to verify

Re: Assembly calling from c and linking

Posted: Wed May 02, 2012 1:14 pm
by krix
Hm, looks like I got it work on boch. Strange, I compiled it with dev-cpp compiler.