NASM - The Netwide Assembler

NASM Forum => Using NASM => Topic started by: baku on February 03, 2010, 09:04:29 PM

Title: Hello, is it posible to mix C and Nasm code and get raw format?
Post by: baku on February 03, 2010, 09:04:29 PM
Hello, im new with nasm. I wrote a bootloader that searches for a file, loads it and transfer control. I want to try a few things at this point but writing long pieces of code in asm seem too complicated, so i would like to write most of it in c, the critical parts in asm, the main thing is how can i combine c code with nasm code and get raw code which i can execute directly. Is it posible? Can you suggest a c compiler that does it?

Thanks
I appreciate any help
Title: Re: Hello, is it posible to mix C and Nasm code and get raw format?
Post by: Bryant Keller on February 04, 2010, 01:08:37 AM
Sure it's possible, only you can't use the standard c library. The method most commonly seen is people writing low level replacements for the standard c library (like kprintf, kmalloc, etc) and using those to ease development. You should check out OSDever.net and check out Brandon Friesen's kernel development guide. It covers exactly what you're wanting to do and is a great beginner guide to operating system development in general.
Title: Re: Hello, is it posible to mix C and Nasm code and get raw format?
Post by: Keith Kanios on February 04, 2010, 02:24:18 AM
If you are interested in implementing the standard c library, keep a close eye on PDCLib (http://pdclib.rootdirectory.de/), as it is a promising implementation for those interested in low level development.
Title: Re: Hello, is it posible to mix C and Nasm code and get raw format?
Post by: baku on February 04, 2010, 02:43:44 AM
Bryant this is it, the info i needed!!! Thank you!!! I'm already reading a tutorial and looks promising. Keith thank you too, this may speed things up.

Thank you both
Title: Re: Hello, is it posible to mix C and Nasm code and get raw format?
Post by: Bryant Keller on February 04, 2010, 04:10:03 AM
No worries, and good luck on your current venture :)
Title: Re: Hello, is it posible to mix C and Nasm code and get raw format?
Post by: ras on February 24, 2010, 07:59:50 PM
you can use __asm__ in mingw/gcc
but that wont emit flatform binary model files ';]

you can also use djgpp, im sure that supports* __asm__ tags
it's called inline assembly

ALSO, when emitting flat binary files... eg. .com msdos .sys
you could mix asm/c by linking object files together