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?

amon
  • 132,749
  • 27
  • 279
  • 375
aderchox
  • 184
  • 8
  • “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 '19 at 13:12
  • @TZHX Thanks, so why is that called "assembly"? Is this just an unintended same use of word "assembly"? – aderchox Mar 16 '19 at 13:13
  • Wow, I think I can at least await a good comment per downvote! – aderchox Mar 16 '19 at 13:18
  • Your question is unclear. Are you asking what Karl Bielefeldt's definition of "Windows Assembly" is? Or are you asking what restrictions are in place when writing assembly under Windows? Also, please make sure that your question is self-explaining, free-standing, and complete without having to follow any links. At the moment, it is impossible to understand your question without following the link. Case in point: @TZHX's comment has absolutely nothing whatsoever to do with the usage of the term in your link, it's talking about something completely different. – Jörg W Mittag Mar 16 '19 at 13:27
  • 2
    It appears to me you missed to read [the question](https://softwareengineering.stackexchange.com/questions/215003/is-there-much-difference-between-x86-assembly-language-on-windows-and-linux) 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 '19 at 13:50
  • @DocBrown Thanks, his answer is definitely a reliable one (considering his high credit on the website) but what confuses me is that he says "assembly languages might differ even between platforms", so that means that OSs like Linux and Microsoft add an additional layer on the underlying X64 assembly provided by the CPU manufacturer(e.g. Intel)? Or maybe the manufacturer provides various flavors of their own assembly language to be used on giant OSs? I think if I get my hands dirty with some X86 such confusions will go away so sorry if my question is unclear I just got curious and asked this. – aderchox Mar 16 '19 at 14:22
  • 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 '19 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. – user253751 Mar 17 '19 at 22:00

1 Answers1

9

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.

amon
  • 132,749
  • 27
  • 279
  • 375