1

This is a simple NASM 64bit linux assembly program:

_exit:
    mov rax, 60
    mov rdi, 0
    syscall

My computer is AMD ( x86_64 64bit ) and i know this assembly program will working in INTEL 64bit processor too.

but I have these following problems !

  • Will this program work on ( linux ) computer with MIPS 64bit and ARM 64bit architecture?
  • Do only system calls change when an assembly code with the different operating systems?
  • 3
    This isn't `arm` nor `mips` so no, it won't work on a computer with those respective CPU architectures, regardless of the OS. The assembly you've provided is OS-agnostic, such that it should be able to assemble and run on pretty much any OS that has a x86-64 compiler. However, the assembly process leaves artifacts that can be OS-dependent, such as invoking the appropriate loader, file formats, and whatnot. In short, the code is portable across OS's but the assembled binary is not. – h0r53 Jan 05 '21 at 17:10
  • 1
    The AMD x86 is an intel x86 are for the most part compatible, and you are using the same operating system so the instructions and the syscall match. But no other system or architecture will work as they are both incompatible. – old_timer Jan 05 '21 at 17:35

1 Answers1

6

Will this program work on ( linux ) computer with MIPS 64bit and ARM 64bit architecture?

No. MIPS and ARM have entirely different instruction sets. It would be comparable to trying to run JVM Bytecode with the .NET VM. It is just not compatible.

Do only system calls change when an assembly code with the different operating systems?

No. The calling conventions differ, for example. For example windows uses RCX, RDX, R8, and R9 for passing int arguments, SystemV (E.g. Linux) uses RDI, RSI, RDX, RCX, R8, R9 for this. Source

JCWasmx86
  • 3,473
  • 2
  • 11
  • 29
  • 1
    Another difference across operating systems can be object file formats produced by the assembler, such as PE, ELF, etc. I understand this answer doesn't cover everything. Just adding there are multiple OS related artifacts of assembly targets. – h0r53 Jan 05 '21 at 17:19
  • Yes completely right, but I understand OP so, that he only spoke about the assembly code. So what would change, if you take assembly code form e.g. Linux and go to windows. Not about binary files – JCWasmx86 Jan 05 '21 at 17:22
  • Also of course Windows doesn't even have the same system-call *API*, so it's not just a matter of a different ABI for a standard set of system calls. And in fact Windows doesn't have a stable/supported `syscall` interface; the only supported way to make Windows system calls is by calling into DLLs (which do ultimately use `syscall`; for a specific version of Windows you can reverse engineer the call numbers and make non-portable experimental programs on your local system using them: https://j00ru.vexillium.org/syscalls/nt/64/) – Peter Cordes Jan 06 '21 at 06:04