You could do this by writing a simple bootloader. This OSdev article shows you one way to go about it.
Regarding languages: Any compiled language (C/C++) gets compiled into machine code, which again is 1-1 mappable to assembly instructions. So, in principle you could write most of the bootloader in C/C++.
Printing: The challenge with "booting your own code" is of course that you won't have any drivers or any standard library (so, no printf
-function or cout
). In x86, however, certain parts of low memory (starting at 0xa0000
) is directly mapped to video memory when you boot, meaning that the bytes you write to this part of memory will atuomagically appear on the screen, as text.
Choice of assembler: This is really only a matter of taste. For a simple assembly-language bootloader, you'll want to avoid any particular formatting of the resulting binary. nasm -f bin myfile.asm -o myBootsector
will just assemble the code into a raw binary.
This post has more details.