Search code examples
cbootlow-level

How to make a bootable program?


So, the question might seem strange, but let's say that I compile:

int main(void)
{
    int x = 3;
    int y = 4;

    int z = x + y;
}

Is it possible to make the CPU run just that? How? For example, would this allow me to write to the monitor? (If I remember it correctly, there are places in memory in which you can write stuff to be displayed.)


Solution

  • In the case of your program, it does not rely on any operating system services other than getting it started. If it were to additionally do input or output, it would almost certainly rely on the operating system to perform the i/o.

    If you want to replace the operating system with your own code, then you could well do it. Minimalistic operating systems and program loaders exist. But yes, you have a lot to learn.