Can you use any compiler, assembler, etc to output code directly for the processor and not for an executable file specific to an OS? How do you determine if you are outputting for an executable for an OS or directly for a processor?

Are the instructions/code part in an exe file the same as the ones executed by the processor, or does the OS interpret and modify them?

2 Years
Discussion Span
Last Post by rubberman

I think this is a simple no. For example if I compile my C# code the exe is not "machine code" entirely. The .net clr is fired up to run the C# byte code. That's not a bad thing.

But since the clr is not an OS the answer is again no.

If I were to change your question to assembler then you get machine code that executes without such overhead. And then again, to do most useful things we would make calls to BIOS or OS so we could be back to no as those could use some sort of interpreter.


You might find the Object File page of the OS Dev wiki helpful here. To sum up, while it is possible to generate a pure executable image from code under some circumstances, it is extremely unusual to do so. No current OS would normally allow that to be done, especially since almost any code would need to link to some kind of library, or make a system call of some kind.

Edited by Schol-R-LEA


The question seems a bit muddled. Almost all programs run directly on the processor, but the operating system does a lot of the heavy listing for them. Generally speaking the only program which:

a.) Is not loaded by the operating system, and
b.) Makes no use of operating system services,

is the operating system itself. The main differences between operating system code and application programs are:

a.) The operating system has to do absolutely everything for itself - such as putting individual pixels on the screen when it wants to display some text, and
b.) It has some special machine instructions available to it, which applications are not allowed to use.

Some compilers, such as gcc, have an option which will allow you to generate operation system independent code, but that option is no real use unless you are yourself writing either an OS, or some kind of embedded software.


You would most likely need to use assembly language to do this, but if you want to perform meaningful I/O, then you still need OS or BIOS support. IE, you might be able to invoke BIOS interrupts to do things like read/write bits to various I/O ports. This is what the OS does for you, since it is a LOT of work to do yourself. Read the Linux system source code, or for something a bit simpler, Minix (what Linus used to learn OS coding). There are a number of good books on the subject (none particularly inexpensive), and some may be available free on the internet. Time for you to do some Google searching I think.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.