问题描述
x86-64 汇编中操作数的顺序是什么?:指令目的地,来源或者:指令源、目的地
What is the order of operands in x86-64 assembly?: instruction destination, sourceOr: instruction source, destination
我有三本书和两种不同的方法!
I have three books and two different approaches!
推荐答案
这取决于汇编程序的语法.大多数情况下,我们有两种选择:Intel 和 AT&T 语法.
It depends on the syntax of an assembler. Mostly we have two choices: Intel and AT&T syntaxes.
Intel 语法有多种风格,主要是 NASM (mov dword [symbol_name], 1
) 和 MASM(包括 GAS 的 .intel_syntax noprefix
模式,其中许多GNU 和 Unix 工具都可以使用.)参见 https://stackoverflow.com/tags/intel-syntax/info有关差异的详细信息并区分它们.
There are multiple flavours of Intel syntax, the major ones being NASM (mov dword [symbol_name], 1
) and MASM (including GAS's .intel_syntax noprefix
mode which many GNU and Unix tools can use.) See https://stackoverflow.com/tags/intel-syntax/info for details on the differences and telling them apart.
Intel 语法示例(来自 objdump 反汇编,所以这是 GNU .intel_syntax
,并添加了几个示例):
Intel syntax example (from objdump disassembly, so this is GNU .intel_syntax
, with a couple examples added in):
push rbp # comment character can be # (GAS) or ; MASM/NASM
mov rbp,rsp
mov DWORD PTR [rbp-0x4],edi
mov DWORD PTR [rbp-0x8],esi
mov edx,DWORD PTR [rbp-0x4]
mov eax,DWORD PTR [rbp-0x8]
add eax,edx
pop rbp
ret
add dword ptr [rdi], 1 # size specifier mandatory if neither operand is a reg
imul ecx, [rdi + rax*4 + 20], 12345
AT&T 语法只有一种风格 (https://stackoverflow.com/tags/att/info):
There's only one flavour of AT&T syntax (https://stackoverflow.com/tags/att/info):
push %rbp # comment character is always #
mov %rsp,%rbp
mov %edi,-0x4(%rbp)
mov %esi,-0x8(%rbp)
mov -0x4(%rbp),%edx
mov -0x8(%rbp),%eax
add %edx,%eax
pop %rbp
retq
addl $1, (%rdi) # size suffix b/w/l/q used to indicate operand-size if neither operand is a register
# with more than 2 operands, reverse the whole list
imul $12345, 20(%rdi, %rax, 4), %ecx
AT&T 语法是 Unix 系统固有的.通常,反编译器具有控制输出语法类型的标志.例如 objdump
有 -Mintel
标志,gdb 有 set disassembly-flavor intel
选项.
AT&T syntax is native to Unix systems. Usually, decompilers have flags to control a type of output syntax. For example objdump
has -Mintel
flag, gdb has set disassembly-flavor intel
option.
另外,看看这个有用的站点,您可以在该站点上快速查看无噪音的汇编器输出编译器资源管理器
Also, take a look at this useful site on which you can quickly see assembler output without noise Compiler Explorer
请注意 AT&T 语法对于 x87 非可交换 FP 指令(如带有寄存器操作数的 fsub
和 fsubr
)存在设计错误:请参阅手册:https://sourceware.org/binutils/docs/as/i386_002dBugs.html
Beware that AT&T syntax has a design bug for x87 non-commutative FP instructions like fsub
and fsubr
with register operands: see the manual: https://sourceware.org/binutils/docs/as/i386_002dBugs.html
这篇关于x86-64 操作数的汇编顺序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!