Author Topic: Hello, is it posible to mix C and Nasm code and get raw format?  (Read 10760 times)

Offline baku

  • Jr. Member
  • *
  • Posts: 2
Hello, is it posible to mix C and Nasm code and get raw format?
« 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

Offline Bryant Keller

  • Forum Moderator
  • Full Member
  • *****
  • Posts: 360
  • Country: us
    • About Bryant Keller
Re: Hello, is it posible to mix C and Nasm code and get raw format?
« Reply #1 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.

About Bryant Keller
bkeller@about.me

Offline Keith Kanios

  • Full Member
  • **
  • Posts: 383
  • Country: us
    • Personal Homepage
Re: Hello, is it posible to mix C and Nasm code and get raw format?
« Reply #2 on: February 04, 2010, 02:24:18 AM »
If you are interested in implementing the standard c library, keep a close eye on PDCLib, as it is a promising implementation for those interested in low level development.

Offline baku

  • Jr. Member
  • *
  • Posts: 2
Re: Hello, is it posible to mix C and Nasm code and get raw format?
« Reply #3 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

Offline Bryant Keller

  • Forum Moderator
  • Full Member
  • *****
  • Posts: 360
  • Country: us
    • About Bryant Keller
Re: Hello, is it posible to mix C and Nasm code and get raw format?
« Reply #4 on: February 04, 2010, 04:10:03 AM »
No worries, and good luck on your current venture :)

About Bryant Keller
bkeller@about.me

Offline ras

  • Jr. Member
  • *
  • Posts: 8
Re: Hello, is it posible to mix C and Nasm code and get raw format?
« Reply #5 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
« Last Edit: March 02, 2010, 01:25:11 AM by ras »