Pergunta

When I read some disassembly code, for I am not up on AT&T syntax, I do not know what some code like (%esp,1) means.

11      printf("%x", a);
0x401386        <main+182>:    movl  $0x1,0x4(%esp,1)
0x40138e        <main+190>:    movl  $0x40300d,(%esp,1)
0x401395        <main+197>:    call  0x401810 <printf>

Could someone tell what it does mean? Thank you!

Foi útil?

Solução

This wikibook seems to have some information about the GNU assembler and its AT&T syntax:

http://en.wikibooks.org/wiki/X86_Assembly/GAS_Syntax

I also found these two sources of documentation on Gas, but they don't seem to be very clear or useful:

  1. http://webster.cs.ucr.edu/AsmTools/Gas/GasDoc/as_toc.html
  2. http://sourceware.org/binutils/docs-2.17/as/index.html

Outras dicas

                              ; Decompiled, sort of, back to C
                              ; ==============================
    movl  $0x1,0x4(%esp,1)    ; %esp[1] = 1 (the "1" really means, "add 4")
    movl  $0x40300d,(%esp,1)  ; %esp[0] = "%x"
    call  0x401810 <printf>   ; push return address and branch to printf

It seems that the compiler knows that a is equal to 1, and that it already has adjusted the stack pointer downward to make room for the arguments. Perhaps it combined pushing space onto the stack with the function prologue.

In general, the addressing modes look like...

r    ; register
(r)  ; memory, register contains the address
8(r) ; memory, displacement of 8 off the register
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top