3

Been working on an assembly assignment, and for the most part I understand assembly pretty well. Or well at least well enough for this assignment. But this mov statement is tripping me up. I would really appreciate if someone could just explain how this mov statement is manipulating the register values.

mov (%ebx,%eax,4),%eax

P.S. I wasnt able to find this specific type of mov statement by basic searches, so I appologize if I just missed it and am re asking questions.

Carl Norum
  • 219,201
  • 40
  • 422
  • 469
Scalahansolo
  • 2,615
  • 6
  • 26
  • 43
  • 1
    This question is definitely a duplicate. Let me look around. Have you checked the [docs](http://www.intel.com/content/www/us/en/processors/architectures-software-developer-manuals.html)? They explain this stuff pretty well. You might want to translate to Intel-format assembly for easier lookup in those books, though. – Carl Norum Feb 15 '13 at 17:45
  • I figured it would be, but I appreciate the help finding the appropriate place to look. – Scalahansolo Feb 15 '13 at 17:48
  • See also [GAS syntax addressing mode syntax](http://en.wikibooks.org/wiki/X86_Assembly/GAS_Syntax#Address_operand_syntax) on wikibooks, and other links in the [x86 tag wiki](https://stackoverflow.com/tags/x86/info) – Peter Cordes Sep 23 '17 at 07:44
  • See also the [AT&T syntax tag wiki](https://stackoverflow.com/tags/att/info) for more details on the syntax, and links to more docs. – Peter Cordes Nov 18 '17 at 17:43

1 Answers1

5

The complete memory addressing mode format in AT&T assembly is:

offset(base, index, width)

So for your case:

offset = 0
base = ebx
index = eax
width = 4

Meaning that the instruction is something like:

eax = *(uint32_t *)((uint8_t *)ebx + eax * 4 + 0)

In a C-like pseudocode.

Carl Norum
  • 219,201
  • 40
  • 422
  • 469
  • why is `uint8_t` here? – 0xAX Feb 03 '15 at 10:57
  • yes, but why especially uint8? all of ebx, eax and etc... registers are 32-bit, whether the information is lost in the upper three bytes? I'm asking because i have: `leal 0x2004(%ebx), %eax` but i see: `leal 0x4(%ebx), %eax` in debugger – 0xAX Feb 03 '15 at 11:19
  • 1
    Because I want the `eax*4` to be in increments of bytes, not 32-bit words. Notice that it's not dereferenced as a byte. – Carl Norum Feb 03 '15 at 14:54
  • casting to `(uintptr_t)` rather than a pointer for the math might be even clearer. – Peter Cordes Sep 23 '17 at 07:42