Search code examples
assemblyx86gnu-assembleratt

Why is mov eax,val not the Intel-syntax equivalent of mov $val,%eax?


I'm trying to understand the differences between Intel syntax and AT&T syntax (I am using GNU as).

I have two files, intel.s:

.intel_syntax noprefix

val:
    mov eax, val

and atandt.s:

val:
    mov $val, %eax

I am trying to convert the AT&T version to the Intel version. But I get different results:

$ objdump -d intel.o

intel.o:     file format elf32-i386


Disassembly of section .text:

00000000 <val>:
   0:   a1 00 00 00 00          mov    0x0,%eax

and

$ objdump -d atandt.o

atandt.o:     file format elf32-i386


Disassembly of section .text:

00000000 <val>:
   0:   b8 00 00 00 00          mov    $0x0,%eax

Why are they different?


Solution

  • The Intel instruction loads the contents of val. To load its address, use

        mov eax, offset val