Page 1 of 1

ASM to C

Posted: Tue Feb 22, 2011 7:21 am
by MichaelSammels
Firstly, if this is in the wrong location then I apologise.

I was wondering, does anyone have links to tutorials or example code which I could look at? I am interested in programming my kernel in C, but I need to find a way to jump from my 512-byte bootloader to another ASM file, which then loads the C code. Yes, it is a simple task, but I really am stuck.

Re: ASM to C

Posted: Tue Feb 22, 2011 8:28 am
by xenos
The wiki has lots of information that might be helpful for you.

Rolling Your Own Bootloader

Re: ASM to C

Posted: Tue Feb 22, 2011 2:46 pm
by bewing
All versions of C support something called "function pointers". They are ugly things to declare, but it sounds like they would work for your purpose. You would need to use casting to declare a constant address to be a function pointer, and then call it. Alternately, to use single lines of ASM code within a C program you can use compiler-dependent thingies called "inline ASM". All compilers support it, but it ties your code to that compiler forever. Last, you can write ASM routines in files that are completely in assembler, compile it with the assembler, and then use the loader/linker to link that ASM code together into one executable with other C programs.

So, start with the search terms: inline assembly (in the osdev wiki works well), and "function pointers". Linking ASM object files requires a knowledge of your assembler and linker.

Re: ASM to C

Posted: Sat Feb 26, 2011 9:14 am
by Chandra
You may need to "pause" the OS Development task and learn 'C' first. There are lots of tutorials available across the web so, grab one and get going. Once you feel you are ready, you can continue smooth 'OS Development'.
Generally, 'Learning language with OS Development' is considered BAD IDEA so, I'm recommending it. But again, that's your choice.

Best Regards,
Chandra