Executables and the operating system

In summary, the conversation discusses the difference between compiled, executable computer programs and IL code or Bytecode. It is determined that executable files are in a format intended for use by the OS or by the CPU, depending on the specific OS and CPU being used. The process of creating a process and executing code is explained, with the input and output going through the operating system. In the early days of computers, accessing input and output devices was done by writing data to specific memory locations or executing machine-language instructions, but this is no longer common practice except for game consoles and embedded devices. However, there are some PC game studios that still use this approach for graphics performance.
  • #1
DwithQs
11
0
Hello,

I am curious about compiled. executable computer programs. That can be in any format, EXE, ELF, etc. I am not referring to IL code or Bytecode, but files that are considered to be in "Native" code or "Binaries".

Are executable files in a format intended for use by the OS or by the CPU? I know executable files are not portable from one OS to another, so I am assuming that an executable really isn't machine code, but is instead code meant to be interpreted by an OS and formed into machine code. Otherwise, is there a combination of OS level interpreted code and actual machine code in an executable file?

I'm also curious of how you could go about issuing actual commands to a CPU from inside of an OS, or is that impossible and always up to interpretation by the OS?
 
Technology news on Phys.org
  • #2
Consider a program that asks for some input from the user, reads that input, does some calculations, and then displays the results or writes them to a file.

The binary code for the calculations depends on the type of processor being used, and in principle at least, does not depend on the operating system. However, all the input and output goes through the operating system, via calls to subroutine libraries that are part of the OS. So that stuff depends on the OS.

In the early days of computers, you could access input and output devices by writing data to specific memory locations, and/or executing specific machine-language instructions, but those days are long gone, at least for general-purpose computers. Maybe it's still done with small processors that are embedded into hardware systems.
 
  • #3
DwithQs said:
Are executable files in a format intended for use by the OS or by the CPU?
This depends on the OS and CPU. For Windows / Intel, an executable file contains some tables used by the OS, data sections and code sections. The code sections contain mostly machine language code left unmodified unless there's an addressing conflict (this normally only happens when using DLLs (dynamic link libraries)). Example wiki article:

http://en.wikipedia.org/wiki/Portable_Executable
 
  • #4
A native executable file does contain machine code, but it is packed in a way that the linking loader (which is arguably a part of the operating system) can figure out how to create a process (that is load the program into memory, initialize it's variables, and schedule a thread of code to start executing). So the .exe file, just for example, is input to the linking loader, which "interprets" its "instructions" in order to create a process and start it running. The "code" inside the executable file is the instructions for the linking loader. The "data" inside the executable file is the machine code for the program you wrote.
 
  • #5
It is difficult to find, but if you can find it, read the documentation for the operating system's linking loader. I figured this all out, once a long ways back, by spending a few days wrestling to understand the linking loader documentation for UNIX. It solved a thousand mysteries. I'm sure it's still very similar for Linux, and somewhat different for Windows, but the basic principles still apply. A native executable file is input to a loader program, whose job it is to create a process and schedule it for execution (with the code to the executed). Hope this helps.
 
  • #6
jtbell said:
In the early days of computers, you could access input and output devices by writing data to specific memory locations, and/or executing specific machine-language instructions, but those days are long gone, at least for general-purpose computers. Maybe it's still done with small processors that are embedded into hardware systems.

It's called "direct to metal" or coding "close to the metal". As you say it has fallen out of favour with PC developers but it's certainly alive and kicking on game consoles (they all have the same hardware) and embedded devices. I think there's a couple of PC game studios that live close to metal, Crytek for example. The reason it's not liked on PC is that you'd do it for graphics performance but they all have different graphics cards. Having said this I have seen some very dirty hacks used to save power on mobile devices and there's increasing crossover between mobile and desktop code.
 

Related to Executables and the operating system

1. What is an executable file?

An executable file is a type of computer file that contains instructions for the computer to perform a specific task. It is also known as a program or application and can be opened and run by the operating system.

2. How do executables work with the operating system?

Executables work with the operating system by using the resources and services provided by the OS to execute the instructions contained within the file. The OS manages the execution of the executable and ensures that it has the necessary resources to run properly.

3. What is the difference between a 32-bit and 64-bit executable?

The main difference between 32-bit and 64-bit executables is the amount of memory they can access. 32-bit executables can access up to 4GB of memory, while 64-bit executables can access much more, depending on the operating system and hardware. Additionally, 64-bit executables can handle larger numbers, resulting in improved performance for certain tasks.

4. Can an executable file harm my computer?

In most cases, an executable file cannot harm your computer unless it is infected with malware. However, it is always important to exercise caution when downloading and running executable files from unknown sources. It is recommended to use antivirus software to scan any downloaded executable files before running them.

5. How can I create my own executable file?

To create your own executable file, you will need to use a programming language or tool that can compile your code into an executable format. Some popular options include C++, Java, and Python. Once your code is written and compiled, you can run the executable on any computer with the appropriate operating system and dependencies.

Similar threads

  • Programming and Computer Science
Replies
29
Views
2K
  • Programming and Computer Science
Replies
4
Views
925
  • Programming and Computer Science
Replies
17
Views
2K
  • Programming and Computer Science
Replies
5
Views
1K
  • Programming and Computer Science
Replies
1
Views
3K
  • Programming and Computer Science
Replies
7
Views
1K
Replies
6
Views
1K
Replies
6
Views
1K
  • Programming and Computer Science
Replies
12
Views
9K
  • Computing and Technology
Replies
31
Views
2K
Back
Top