1
$\begingroup$

If Mac OS, Linux, and Windows (mostly) all use Intel's 8086 64 bit instruction set, why can't we compile 8086 64 assembly from any operating system to any other operating system? (e.g. compile a Mac OS executable from assembly in Windows). Surely it would just be a matter of knowing what the machine code is for any given instruction?

$\endgroup$
3
  • 1
    $\begingroup$ I think some things will be the same such as the registers and opcodes. There are a variety of assemblers and they have different syntax. I used NASM on Linux but there is also the assembler that comes with GCC and its format looks different. Each operating system will have its own system calls and maybe link differently. If you call the C library from assembly you might have code that is somewhat portable. $\endgroup$ Sep 10 '20 at 21:41
  • 1
    $\begingroup$ Most pure computation will work unchanged -- e.g., if you want to compute the FFT of 1000 floating point values beginning at some memory address. But if you want to allocate that memory, or read in the data from a file, or write the results to a file or the screen, that requires interacting with the OS, and so that's different on each OS. $\endgroup$ Sep 10 '20 at 21:52
  • $\begingroup$ The 8086 is an ancient (late 1980's) 16 bit processor. Good luck finding an assembler for that. $\endgroup$
    – gnasher729
    Sep 10 '20 at 23:22
2
$\begingroup$

Porting to a different operating system is about a lot more than the particular assembly language you use. Different operating systems have different system calls, different libraries, and different APIs, and converting from one to another is usually not something that can be done in an automated way -- even if both used exactly the same assembly language. Most programs do need to access the filesystem, the network, display things on the screen, and so forth, and all of those require interaction with the OS and libraries.

$\endgroup$
0
$\begingroup$

While natively assembled program on one OS may not run on another OS as system calls and libraries are different, yet it is possible to cross-compile, i.e., compile on one platform, say Linux to run on another, say MAC OS. It is something quite often done for micro-controllers.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.