How do assembly languages depend on operating systems?

前端 未结 7 2057
余生分开走
余生分开走 2020-12-14 04:38

As An assembly language implements a symbolic representation of CPU instructions which are independent on OSes while assemblers are always running under some OS, I was wonde

7条回答
  •  甜味超标
    2020-12-14 05:13

    The instructions available (and each instruction's semantics, of course) depends on the CPU, not on the OS - so in a way, you are right.

    But for most tasks of interest (I/O for example), you have to talk to the OS (making system calls). Cross-platform abstractions over these things don't exist at that level (well, you could try to use libc for instance, but even then you need to know the calling convention used, which can differ between platforms, etc. - in the end, you'd have to put quite some work into building such an abstraction yourself, so AFAIK few of the few people who program in assembly bother to try), to do something not possible with the (OS-independent) CPU instructions, you have to know what OS you're programming for and how to tell that OS to do it.

    This doesn't apply as heavily for inline assembly code in e.g. C code, as it is mostly used to make purely CPU-bound computations in a smarter/faster way than the compiler is expected to).

提交回复
热议问题