Mixing C and nasm

Programming, for all ages and all languages.
Post Reply
jaswax
Posts: 23
Joined: Sat Jan 19, 2008 11:26 am
Location: Texas

Mixing C and nasm

Post by jaswax »

Hello all. I am newly registered here but I have read many posts, searched for many things and have had many questions answered.

I am sorry if this has already been asked but my searches yielded no good results. So now for my first question here!!!

I am developing under Linux using gcc, nasm and ld

I would like to know how to mix NASM with C. Can someone point me to a tutorial for this? or just lay it out for me in a reply? (either is ok)

Example of what I am trying to do:

Code: Select all

; File: Readchr.asm
global rdchr
rdchr:
  mov eax, 0x01
  ...
ret
C file:

Code: Select all

; File: Main.c
extern void rdchr;
int main()
{
  rdchr();
}
I want to be able call functions created in nasm from C.

Thanks in advance for the any help.
User avatar
JamesM
Member
Member
Posts: 2935
Joined: Tue Jul 10, 2007 5:27 am
Location: York, United Kingdom
Contact:

Post by JamesM »

Hi,

If you remove the "extern ..." line, that code should compile in C. Just add rdchr as a function prototype beforehand, and bob's your uncle!
jaswax
Posts: 23
Joined: Sat Jan 19, 2008 11:26 am
Location: Texas

My problem is solved.

Post by jaswax »

Thank you. That solved my problem. I like the simple answer. Cheers!
Post Reply