8

What is the difference between the following statements?

mov %eax,%esp
mov %eax,(%esp)

I'm working on diffusing a binary bomb and am having trouble with a few of the mov and leal commands early on in the assembly.

nrz
  • 10,435
  • 4
  • 39
  • 71
arc
  • 477
  • 2
  • 8
  • 14
  • 2
    One copies the register. The other loads from the memory it points to. – Mysticial Oct 19 '12 at 15:58
  • 5
    @Mysticial: This is AT&T syntax, so everything is backwards -- %esp and (%esp) are the destinations, not the sources. – Jerry Coffin Oct 19 '12 at 16:00
  • @JerryCoffin AHHHH!!! I always fall for that trap... – Mysticial Oct 19 '12 at 16:01
  • Other memory addressing-modes are possible, not just register-indirect. See [A couple of questions about \[base + index\*scale + disp\] and AT&T disp(base, index, scale)](https://stackoverflow.com/q/27936196) – Peter Cordes Aug 07 '22 at 10:09

1 Answers1

12

This copies the value in %eax into %esp.

mov %eax,%esp

This copies the value from %eax to the location in memory that %esp points to.

mov %eax,(%esp)
Dirk Holsopple
  • 8,731
  • 1
  • 24
  • 37