0

So I was playing around with some assembly today and I noticed when compiling the following code using as -o foo.o foo.s I get a different result than I would expect:

.section .text 
.globl _start 
.intel_syntax noprefix 
_start: 
    mov rsi, rsp
    mov rdx, 0x1234567890ABCDEF
    mov qword [rsi], rdx
    

.. which compiles to:

# objdump -D -M intel foo.o

oo.o:     file format elf64-x86-64


Disassembly of section .text:

0000000000000000 <_start>:
   0:   48 89 e6                mov    rsi,rsp
   3:   48 ba ef cd ab 90 78    movabs rdx,0x1234567890abcdef
   a:   56 34 12 
   d:   48 89 56 08             mov    QWORD PTR [rsi+0x8],rdx

I was wondering why as adds another 0x8 to the memory write (qword [rsi] vs. QWORD PTR [rsi+0x8])??!

Peter Cordes
  • 328,167
  • 45
  • 605
  • 847
milck
  • 592
  • 3
  • 12
  • 1
    I think GAS interprets a bare `qword` as the constant 8 (the size of a qword). The correct syntax for what you want is `mov qword ptr [rsi], rdx`. There might be a duplicate question somewhere around here. – Nate Eldredge Jun 30 '21 at 15:56
  • 1
    `qword` instead of `qword ptr` is NASM syntax. GAS unfortunately doesn't error on it, and has this "failure mode" because it allows `123[reg]` – Peter Cordes Jun 30 '21 at 16:10

0 Answers0