help understanding this assembly code
I have the following assembly code:
Code:
Dump of assembler code for function phase_1: |
Assuming that code is following standard conventions, for x86-32, function parameters are usually pushed onto the stack in reverse order.
The extra space on the stack is either for alignment, or other shenanigans related to maintaining stack frames that happens when you call functions (such as dealing with %EBP correctly). It's been a while since I looked into the detail of this so I'm a bit vague on the details (especially for 32bit which I haven't used in a long time). I'd suggest you google to find some official documentation on 32bit linux calling conventions if you want to understand this fully. this may help https://en.wikibooks.org/wiki/X86_Di...ng_Conventions |
Code:
0x08048b53 <+3>: movl $0x804a2e8,0x4(%esp) // Uses bytes 4..7 above %esp Quote:
|
Quote:
|
It's a start point.
sp+4 to sp+7 4 bytes sp+0 to sp+3 4 bytes. = 8 bytes. |
Quote:
|
If the phase_1 function started a new stack frame with the usual prologue:
push %ebp mov %esp, %ebp then, yes, 4(%esp) would then be the return address, because %esp would have been incremented by 4 due the push. In this case however, it seems saving of %ebp is being skipped, so on entry %esp will contain the return address. Thus, %esp - 0x1c + 0x20 will point to the first 32bit value above the return address, which should be the first (or only) argument passed to the function. Unless I'm mistaken, this code is comparing 4(%esp at entry) to whatever is at 0x804a2e8 |
Quote:
|
because it's already grown the stack by subtracting the 0x1c, so it doesn't need to make the stack any bigger, it's just backfilling.
I don't think a human would write the code like that. It looks like compiler optimisations at play to me. |
Quote:
|
char arrays a.k.a. strings are pass by reference. The value passed is the address of the string, not the string itself.
|
All times are GMT -5. The time now is 01:17 AM. |