ASM to C

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
MichaelSammels
Posts: 1
Joined: Tue Feb 22, 2011 7:19 am

ASM to C

Post 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.
User avatar
xenos
Member
Member
Posts: 1121
Joined: Thu Aug 11, 2005 11:00 pm
Libera.chat IRC: xenos1984
Location: Tartu, Estonia
Contact:

Re: ASM to C

Post by xenos »

The wiki has lots of information that might be helpful for you.

Rolling Your Own Bootloader
Programmers' Hardware Database // GitHub user: xenos1984; OS project: NOS
User avatar
bewing
Member
Member
Posts: 1401
Joined: Wed Feb 07, 2007 1:45 pm
Location: Eugene, OR, US

Re: ASM to C

Post 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.
User avatar
Chandra
Member
Member
Posts: 487
Joined: Sat Jul 17, 2010 12:45 am

Re: ASM to C

Post 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
Programming is not about using a language to solve a problem, it's about using logic to find a solution !
Post Reply