Can I use asm() in C instead of asm?

55 Views Asked by At

I want to write a simple operating system for learning purposes. Can I write an operating system using asm() in C instead of assembly language?

Example:

int main()
{
asm("mov ax,70C0h"
    "add ax,520"
    "jmp $");
}
1

There are 1 best solutions below

0
RadoslavL On

You can't write an OS using inline Assembly, as the C compiler is going to compile and link the code on your existing OS. It can only be executed on your OS after that. I recommend writing your OS in Assembly and then compiling it using NASM (a common x86 compiler). I recommend this tutorial for creating your own bootloader. After that you can stick to 16-bit real mode or switch to 32-bit protected mode.