问题描述
由于汇编语言实现了CPU指令它们是独立于操作系统,而装配总是在一些操作系统上运行,我想知道怎样语言组装依赖于操作系统的一个象征性的重新presentation?例如,将汇编语言是不同的操作系统相同的CPU一样吗?谢谢!
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 wondering how assembly languages depend on operating systems? For example, will assembly languages be the same for the same CPU with different OSes? Thanks!
推荐答案
正如其他人所指出的,系统调用和中断是不同的。我能想到的其他一些区别。
As others have pointed out, system calls and interrupts are different. I can think of another few differences.
指令集是整个给定的处理器上的所有操作系统一样,但格式的可执行文件可能不是。例如,在x86,Windows使用PE格式,Linux使用ELF和MacOS使用的Mach-O。这意味着,在这些平台装配必须产生它们在这些格式输出,这是有区别的。
The instruction set is the same across all OSes on a given processor, but the executable file format might not be. For example, on the x86, Windows uses the PE format, Linux uses ELF, and MacOS uses Mach-O. That means that assemblers on those platforms must produce their output in those formats, which is a difference.
与此相关的调用约定也可以是在不同的操作系统不同。你在哪里编写汇编code调用或被compiled- code程序调用,或者可能只是问题也许,你在某些编译code编写的内联汇编。调用约定管辖该寄存器用于函数调用中的目的是什么,所以不同的约定需要通过调用不同的使用登记,并呼吁code。他们也提上了堆栈指针的位置,以及各种其他的东西限制。碰巧的是,调用约定历来在许多情况下得到一致性的一个罕见的例子在整个操作系统:我相信Windows和UNIX调用约定是在x86相同的(和都是基于古老的UNIX System V的ABI规范),以及对多数其他架构跨操作系统是一致的。然而,约定现在对x86_64的Windows和UNIX之间是不同的。
Relatedly, the calling convention could also be different across different OSes. That probably only matters where you are writing assembly code that calls or is called by compiled-code routines, or perhaps where you are writing inline assembler in some compiled code. The calling convention governs which registers are used for what purposes during a function call, so different conventions require different use of registers by calling and called code. They also put constraints on the position of the stack pointer, and various other things. As it happens, calling conventions have historically been a rare example of consistency across OSes in many cases: i believe the Windows and UNIX calling conventions are the same on the x86 (and are all based on the venerable UNIX System V ABI specification), and are consistent across OSes on most other architectures. However, the conventions are now different between Windows and UNIX on the x86_64.
在此外,有可能在由汇编语言中使用的语法的差别。再次在x86上,在Windows和Linux编译器中使用不同的语法,使用由英特尔发明了一种语法Windows的汇编,并使用由AT&amp发明了一种传统的UNIX语法在Linux汇编(说真的,GNU汇编);吨。这些语法描述相同的指令集,但被写入不同。如今,GNU汇编程序也可以理解英特尔的语法,所以有较少的差别。
In addition, there may be differences in the syntax used by the assembly language. Again on the x86, the Windows and Linux assemblers used to use different syntax, with the Windows assembler using a syntax invented by Intel, and the Linux assembler (really, the GNU assembler) using a traditional UNIX syntax invented by AT&T. These syntaxes describe the same instruction set, but are written differently. Nowadays, the GNU assembler can also understand the Intel syntax, so there is less of a difference.
这篇关于怎么办汇编语言依赖于操作系统?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!