2

As I can understand, assembly language is just a symbolic representation of hardware instruction opcodes that a hardware manufacturer has offered/documented, based on the way they have designed their electronics.

Now I saw the term "Windows Assembly" in another post. As I understand, Windows itself is a software that runs on the x64 architecture. So any Windows Assembly must also be x64 assembly?

If I can write x64 assembly directly, doesn't that mean I can run code on the same level as Windows, which would let me circumvent some Windows limitations, and let me talk directly to the hardware?

  • “Windows Assembly” is a term that can describe libraries of code (or even executables) in various states of compilation (from native compilation, to byte code such as used in JITed runtimes like .net framework. – TZHX Mar 16 at 13:12
  • @TZHX Thanks, so why is that called "assembly"? Is this just an unintended same use of word "assembly"? – aderchox Mar 16 at 13:13
  • 2
    It appears to me you missed to read the question which Karl Bielefeld was answering, which was exactly "is there a difference between x86 assembly language on Linux and Windows". And in his answer, he simply used the term "Windows assembly" as a short term for "x86 dialect of assembly language for Windows", to make clear which variant he was talking about. – Doc Brown Mar 16 at 13:50
  • 2
    @Moytaba: no, this question is about different assemblers which compile assembly languages to machine code. There are different assemblers available for Windows and Linux, and there are also different conventions on how to use registers when doing OS calls, which result in different flavors of the overall same x86 assembly language. Read the answers to the other question for more details. – Doc Brown Mar 16 at 14:43
  • 1
    ELI5: x86 assembly has a "call OS function" instruction (actually several). But the kinds of OS functions that you can call depend on the OS. If you have a "write to file" call on Linux and run it on Windows, Windows won't understand it the same way. – immibis Mar 17 at 22:00
7

An instruction set is CPU-specific, not OS specific. An assembly language for a instruction set is just an abstraction for that instruction set, and is not inherently OS-specific either. However, a particular assembler (the software translating from the assembly language to machine code) may only be available on one OS.

Also, what instructions you perform may differ between operating systems. While the language may not be platform-specific, your code certainly is. The most important difference between platforms is the calling convention, which defines how registers may be used, how a call stack may be used, and where you put which argument. In this sense, Windows Assembly is not a real thing, just a dialect or style of writing assembly.

Machine code does not give you more control over the hardware than a high-level language: in the end, the high-level language such as Go or C++ is just compiled to machine code as well.

The operating system protects and restricts every process, no matter how the code for that process was written. The CPU itself provides security levels that cannot be circumvented from a less-privileged level, see Protection rings on Wikipedia. The privileged operating system code runs in an inner ring. The CPU can switch rings via syscall instructions, but that causes a privileged handler to run rather than letting the old process continue in a more privileged mode. This is closely related to memory protection.

However, the instruction set may offer instructions that cannot be used by the high-level language. For example, a high-level language might not (directly) allow you to make syscalls, trigger interrupts, use SIMD instructions, access coprocessors, …. That can make it necessary to write parts of a software in assembly. On the other hand, some languages offer intrinsic functions for these instructions that the compiler knows to compile as that instruction rather than as an ordinary function call.

  • Wow, this answer has cleared many confusions in my head and is really better than everything I expected! Many interesting points in your answer that I really needed, specially the part that you said "Machine code does not give you more control over the hardware than a high-level language: in the end, the high-level language such as Go or C++ is just compiled to machine code as well.". Thank you. – aderchox Mar 16 at 21:44

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.