Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why There is a difference between assembly languages like Windows, Linux?

I am relatively new to all this low level stuff,assembly language.. and want to learn more detail. Why there is a difference between Linux, Windows Assembly languages?

As I understand when I compile a C code Operating system does not really produce pure machine or assembly code, it produces OS dependent binary code.But why ?

For example when I use a x86 system, CPU only understands x86 ASM am I right?.So Why we dont write pure x86 assembly code and why there are different assembly variations based on Operating system? If we would write pure ASM or OS produce pure ASM there wouldn't be binary compatilibty issues between Operating systems or Not ?

I am really wondering all reasons behind them. Any detailed answer, article, book would be great. Thanks.

like image 969
caltuntas Avatar asked Jan 05 '11 14:01

caltuntas


People also ask

Is assembly same for Windows and Linux?

The assembly language is largely the same and similar. However, neither Windows nor Linux would try to execute an arbitrary file. Most modern operating system refuses to execute a program, unless it have the proper executable headers (e.g. PE or ELF).

Is assembly language different for different OS?

Assembly languages don't depend on an OS, but on the CPU's instruction set.

Is all assembly language the same?

Because assembly depends on the machine code instructions, each assembly language is specific to a particular computer architecture. Sometimes there is more than one assembler for the same architecture, and sometimes an assembler is specific to an operating system or to particular operating systems.


2 Answers

There is no difference. The assembly code is the same if the processor is the same. x86 code compiled on Windows is binary compatible with x86 code on Linux. The compiler does not produce OS-dependent binary code, but it may package the code in a different format (e.g. PE vs. ELF).

The difference is in which libraries are used. In order to use OS stuff (I/O for example) you must link against the operating system's libraries. Unsurprisingly, Windows system libraries are not available on a Linux machine (unless you have Wine of course) and vice-versa.

like image 189
OrangeDog Avatar answered Sep 29 '22 11:09

OrangeDog


Well, you don't run straight assembly. The code has to be in some sort of executable format: windows uses PE, most Unices use ELF now (although there have been others, like a.out).

The base assembly instructions are the same, and the functions you create with them are the same.

The problem comes with access to other resources. The processor is really good at calculation, but can't access the hard disk, or print a character to the screen, or connect to a Bluetooth phone. These elements are always in some way operating system dependent. They are implemented in terms of syscalls, where the processor signals the operating system to perform a certain task. Task number 17 on linux isn't necessarily task 17 on windows; they may not even have equivalents.

Since most libraries have some syscalls at their lowest levels, this is why code can't just be recompiled in every case.

like image 25
Michael Lowman Avatar answered Sep 29 '22 11:09

Michael Lowman