Assembly calling from c and linking

Programming, for all ages and all languages.
Post Reply
krix
Posts: 2
Joined: Wed May 02, 2012 10:56 am

Assembly calling from c and linking

Post 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.
User avatar
bluemoon
Member
Member
Posts: 1761
Joined: Wed Dec 01, 2010 3:41 am
Location: Hong Kong

Re: Assembly calling from c and linking

Post 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
krix
Posts: 2
Joined: Wed May 02, 2012 10:56 am

Re: Assembly calling from c and linking

Post by krix »

Hm, looks like I got it work on boch. Strange, I compiled it with dev-cpp compiler.
Post Reply