I want to copy the value at a certain address in memory to a register using AT&T style assembly. I know this shouldn't be hard, and I think in Intel style it's something like:
mov rdi, [0xdeadbeef]
But I don't know much about the AT&T style (or assembly in general). I searched about it but all the examples about
mov that I got didn't include this one.
So can anyone tell me how that instruction looks like?
Also, where can I find a complete list of x86_64 assembly instructions in AT&T style?
To copy the value at a certain address in memory to a register in 32-bit mode we use
mov edi, [0xdeadbeef] ; Intel movl 0xdeadbeef, %edi ; AT&T
But in x86_64 64-bit absolute addressing is not allowed, so you can't use
movq 0xdeadbeef, %rdi like above. The only instruction that has 64-bit immediate is
movabs in gas), which can assign a 64-bit constant to any registers, or move value at a 64-bit absolute address to Areg
mov rax, [0xdeadbeef] ; Intel movabs 0xdeadbeef, %rax ; AT&T
If you really need to move the value from a 64-bit absolute address to a register different from Areg you must use indirect addressing instead
mov rdi, 0xdeadbeef ; Intel mov rdi, [rdi] movq $0xdeadbeef, %rdi ; AT&T movq (%rdi), %rdi
or if you want the value to be copied to both rax and rdi then
mov rax, [0xdeadbeef] ; Intel mov rdi, rax movabs 0xdeadbeef, %rax ; AT&T movq %rax, %rdi
q suffix means quadword (64-bit) registers
In AT&T syntax the size of memory operands is determined from the last character of the instruction mnemonic. Mnemonic suffixes of
qspecify byte (8-bit), word (16-bit), long (32-bit) and quadruple word (64-bit) memory references. Intel syntax accomplishes this by prefixing memory operands (not the instruction mnemonics) with
qword ptr. Thus, Intel
mov al, byte ptr foois
movb foo, %alin AT&T syntax.
In 64-bit code,
movabscan be used to encode the
movinstruction with the 64-bit displacement or immediate operand.
More information about 64-bit
mov instruction here: Difference between movq and movabsq in x86-64. As you can see there's no version for moving from a 32-bit absolute address to a 64-bit register, so even in rare cases when the address fits in 32 bits like 0xdeadbeef, you still have to use
movabs Areg, moffs64
User contributions licensed under CC BY-SA 3.0