What is the order of operands in x86-64 assembly?: instruction destination, source Or: instruction source, destination
I have three books and two different approaches!
What is the order of operands in x86-64 assembly?: instruction destination, source Or: instruction source, destination
I have three books and two different approaches!
It depends on the syntax of an assembler. Mostly we have two choices: intel-syntax and AT&T att syntaxes. See their respective tag wikis, intel-syntax and att.
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 the Intel syntax tag wiki for details on the differences and telling them apart.
Intel syntax example (from objdump -drwC -Mintel
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
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 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. GCC has -masm=intel
which affects how inline asm("" :::)
statements are assembled, as well as the asm the compiler feeds to the assembler.
Also, take a look at this useful site on which you can quickly see assembler output without noise Compiler Explorer
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
Related:
-masm=intel
. –
Seethrough © 2022 - 2024 — McMap. All rights reserved.
cmd source, dest
while with Intel it iscmd dest, source
so it is assembler dependent. – Inconsonantfsubr
vs.fsub
being reversed for some register-register operands. sourceware.org/binutils/docs/as/i386_002dBugs.html). Other than for x87, I don't have a problem with it after getting my brain into AT&T mode. – Seethrough