19

From what I've read about mov, it copies the second argument into the first argument. Then, what does this do?

movl    8(%ebp),    %edx

It copies whatever is in edx to the first parameter of the function (since an offset of +8 from ebp is a parameter)?

I feel like what this really means is moving the first parameter into the edx register, but I read on Wikipedia that it is the other way around?

Peter Cordes
  • 328,167
  • 45
  • 605
  • 847
hut123
  • 445
  • 3
  • 7
  • 14

1 Answers1

30
movl 8(%ebp), %edx

is in "AT&T Syntax"; in this syntax, the source comes first and the destination second. So yes, your belief is correct. Most documentation uses the "Intel Syntax", which has the reverse ordering. This is a source of considerable confusion for people new to x86 assembly.

In Intel Syntax, your instruction would be written:

mov edx, [ebp + 8]

Note the absence of % before the register names, and the use of square brackets instead of parentheses for the address, and the lack of an l suffix on the instruction. These are dead giveaways to know which form of assembly you are looking at.

Stephen Canon
  • 103,815
  • 19
  • 183
  • 269
  • What is the reason for having 2 different dilects of assembly? As you noted, this can be a common source of confusion for newcomers since they use completely different conventions. – greatwolf May 07 '11 at 21:58
  • @Victor T.: Intel syntax is what Intel specified originally; AT&T syntax is an adaptation of a Bell Labs assembly syntax intended to be used on multiple platforms. – Stephen Canon May 07 '11 at 22:37
  • @Stephen: There is an error with Intel Synax. There must be `mov [ebp + 8], edx` :) – Ilya Matveychikov Jul 12 '11 at 11:12
  • 2
    @Ilya: that would be a store, not a load. The argument order in Intel syntax is reversed from AT&T syntax. – Stephen Canon Jul 12 '11 at 14:04
  • pardon me, the same `movl 8(%ebp), %edx`, op said 'it copies the second argument into the first argument', so it is `1 <- 2`, but here says 'in this syntax, the source comes first and the destination second', so it is `1 -> 2`, and then `So yes, your belief is correct`, totally confused now – http8086 Nov 24 '21 at 03:45