understanding assembly language lea instruction -


i don't understand why line 8 performed, can explain please? on line 10 strcpy called, 0x80482c4 doesn't contain reference 'hello world' (checked gdb). thinking esp pointing starting memory address of 'hello world' , esp being executed when strcpy called? guess @ line 9 is setting enough space 'hello world' char array in code initialized 20.

1.  push     ebp 2.  mov      ebp,esp 3.  sub      esp,0x38 // why happen? 4.  ,      esp, 0xfffffff0 5.  mov      eax,0x0 6.  sub      esp,eax 7.  mov      dword ptr [esp+4],0x80484c4 //contains 'h' 8.  lea      eax,[ebp-40] // going on here? why ebp-40 bytes? 9.  mov      dword ptr [esp], eax  10. call     0x80482c4 <strcppy@plt> 11. lea      eax,[ebp-40] 12. mov      dword ptr [esp],eax 13. call     0x80482d4 <printf@plt> 14. leave 15. ret 

c equivalent: #include #include

int main() { char str_a[20];  strcpy(str_a, "hello, world!\n"); printf(str_a); } 

0x80482c4 doesn't contain reference 'hello world' (checked gdb)

you must have checked wrong. printed first letter, h (or h). it's 99% sure that's hello world string.

line 3 setting space local variables, , compiler has chosen place str_a @ ebp-40. lea loading address.

it's hard tell why compiler chooses specific stack layout, long there space everything, doesn't matter.


Comments

Popular posts from this blog

How has firefox/gecko HTML+CSS rendering changed in version 38? -

javascript - Complex json ng-repeat -

jquery - Cloning of rows and columns from the old table into the new with colSpan and rowSpan -