-
-
[翻译]Say hello to x86_64 Assembly [part 6]
-
发表于: 2020-1-14 11:01 6825
-
最近在学习x64汇编,在github上面找到了一点学习资料,入门级别的,因为想细致的学习一下,所以顺便久把作者的内容都翻译了一下,也不知道自己翻译的是否合适,请大家看看有问题的地方请批评指正.第一次做翻译,做的不好请大家原谅,
这是Say hello to x86_64 Assembly的第六部分,在这里我们将研究AT&T汇编程序语法。以前我们在所有部分都使用nasm assembler,但是还有其他一些具有不同语法的汇编程序fasm、yasm和其他。正如我在上面写的,我们将研究gas(GNU汇编程序)及其语法和nasm之间的区别。GCC使用GNU汇编程序,因此如果您在汇编程序输出中看到简单的hello world:
It is sixth part of Say hello to x86_64 Assembly and here we will look on AT&T assembler syntax. Previously we used nasm assembler in all parts, but there are some another assemblers with different syntax, fasm, yasm and others. As i wrote above we will look on gas (GNU assembler) and difference between it’s syntax and nasm. GCC uses GNU assembler, so if you see at assembler output for simple hello world:
您将看到以下输出:
You will see following output:
看起来与nasm不一样的Hello world,让我们看看有些什么不同。
Looks different then nasm Hello world, let’s look on some differences.
AT&T syntax
Sections
我不知道你怎么样,但当我开始编写汇编程序时,通常是从节定义开始的。让我们看一个简单的例子:
I don’t know how about you, but when I start to write assembler program, usually I’m starting from sections definition. Let’s look on simple example:
你可以在这里注意到两个小小的区别:
-节定义以开头以.符号
-主程序定义使用.globl,而不是像我们在nasm中那样使用global
gas还使用另一个指令来定义数据:
You can note two little differences here:
Also gas uses another directives for data defintion:
操作数顺序使用nasm编写汇编程序时,数据操作的一般语法如下:
Operands order When we write assembler program with nasm, we have following general syntax for data manipulation:
GNU 汇编有着相反的操作方向,即:
With GNU assembler we have back order i.e.:
举例:
For example:
另外,不能在这里使用%symbol注册开始元素。如果使用的是直接操作数,则需要使用$
符号:
Also you can not here that registers starts with % symbol. If you’re using direct operands, need to use $
symbol:
Size of operands and operation syntax
有时当我们需要获得部分内存时,例如64寄存器的第一个字节,我们使用以下语法:
Sometimes when we need to get part of memory, for example first byte of 64 register, we used following syntax:
在gas中进行此类操作还有另一种方法。我们不在操作数中定义大小,而是在指令中定义大小:
There is another way for such operations in gas. We don’t define size in operands but in instruction:
GNU汇编程序有6个操作后缀:
GNU assembler has 6 postfixes for operations:
这个规则不仅是mov指令,而且还适用于所有其他指令,如addl、xorb、cmpw等…
This rule is not only mov instruction, but also for all another like addl, xorb, cmpw and etc…
Memory access
您可以注意到,我们在前面的示例中使用了()括号,而在nasm示例中使用了[]。要解引用括号中的值,请使用GAS:(%rax),例如:
You can note that we used () brackets in previous example instead [] in nasm example. To dereference values in parentheses are used GAS: (%rax), for example:
Jumps
GNU汇编程序支持以下运算符用于远跳转函数调用和跳转:
GNU assembler supports following operators for far functions call and jumps:
远跳转-跳转到位于不同于当前代码段但处于相同权限级别的段中的指令,有时称为段间跳转。
Far jump - a jump to an instruction located in a different segment than the current code segment but at the same privilege level, sometimes referred to as an intersegment jump.
Comments
GNU汇编程序支持3种类型的注释:
GNU assembler supports 3 types of comments: