0

I curious how os work and I have a question. OS file in harddisk when it loaded to RAM , that file is machine code right ? it will can execute without compiler or assembler ?

(This is why I asked this question when we developed OS we wrote in high language so it need to compile but what about OS file that saved in harddisk or SSD I think it was compiled before so it will be machine code store in memory.)

Thank you ( sorry my English is not good)

1
  • 1
    Most executables, including machine code, are compiled prior to being installed to a computer. Commented Jan 10, 2023 at 5:35

3 Answers 3

1

The "base" of the OS (bootloader, kernel) has to be compiled to machine code, as it needs to deal with various CPU-architecture-specific bits, and because there's no pre-existing bytecode interpreter for anything else except machine code at that point.

Usually things like drivers and services are also compiled to machine code, for various reasons. On Windows or Linux, for example, most drivers are loaded into the kernel so they have to be compiled to machine code; system-provided libraries (.dll's) are loaded into various random processes so they can't rely on a pre-existing runtime either. (Efficiency is another reason.)

On the other hand, services that run in their own processes can rely on a runtime or interpreter. For example, if Windows wanted to have some services written in C# and running on the .NET CLR, it could do that (although I believe that's deliberately avoided for efficiency reasons). Large parts of Android "OS" are written in Java/Kotlin, for example.

0

All files are stored in binary, which I'm guessing what you call machine code. There are certain binary patterns(file formats) that are generally ubiquous like text but that's because of the OS and the supporting libraries/binaries. It's up to the developer how they gonna represent their data in binary. More info on file formats in the wiki.

https://en.wikipedia.org/wiki/File_format

Executable files simply differ in the format of the binary data. It's os dependent. If memory serves me right Linux is ELF format for the machine code. and I definitely don't remember Windows/Mac. Here's a quick wiki search on executable format and how developers or their tools structure the binary.

https://en.wikipedia.org/wiki/Executable_and_Linkable_Format

When you read a file programmatically you load the binary load (usually not all at once)in the memory and then it's another variable for you to do as you please.

0
0

File on the hard drive contain arbitrary binary data.

Only some of them contain executable code.

The file system doesn't care what is in the file, and unless you ask the operating system to open said file the OS doesn't care either.

Only a small fraction of the files on your hard drive are actually executable.

JPG,PNG,DOC,DOCX,HTML and most other files don't contain executable data.

In general, the most common type is an EXE files and some COM file are directly executable.

Some languages like PHP or python are interrupted and NOT compiled so the code has to be re-evaluated every time.

If you program in C or another language with an actually compiler the result in an executable that is independently execute.

This code can be executed without a compiler or interrupter, but a JPG or another file is NOT executable.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .