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?
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.
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.