Search code examples
assemblyattaddressing-mode

How does "mov (%ebx,%eax,4),%eax" work?


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.


Solution

  • 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.