X86 Allocation of Space on Stack for Local Variables

I have a basic function I made in C++:

int __cedcl add(int a, int b){
       return a + b;
}

For practice, I did my best at reversing it in IDA. Here is my result:

push    ebp             ; Store EBP Register
mov     ebp, esp        ; Adjust EBP to be Stack Pointer (Becomes reference to paramaters and such)
sub     esp, 0C0h       ; Allocate C0h Space on Stack
push    ebx             ; Save EBX register
push    esi             ; Save ESI Register
push    edi             ; Save EDI Register
lea     edi, [ebp+var_C0] ; Sets Location to Start Copying at Beginning of Allocated Space
mov     ecx, 30h        ; Stores #Repitions
mov     eax, 0CCCCCCCCh ; Value to store
rep stosd               ; Fill 30h space with CCCCCCCC
mov     eax, [ebp+arg_0] ; Store Argument 1 in EAX Return Register
add     eax, [ebp+arg_4] ; Add argument 2 to EAX Return Register
pop     edi             ; Restore EDI Register
pop     esi             ; Restore ESI Register
pop     ebx             ; Restore EBX Register
mov     esp, ebp        ; Restore Stack Pointer
pop     ebp             ; Restore Base Pointer
retn                    ; Return

However, where I am confused is why it is reserving 0x30 space on the stack when there aren't even local variables being used, as it simply leverages the EAX register since it can perform the necessary operations using the return register. Also, why does it by default store the value of registers that are unused within the function. ie. ebx, esi, and edx register?

I'd appreciate it if someone could clarify these questions or note any errors that I made when reversing the function if they spot them. Thanks!

链接地址: http://www.djcxy.com/p/84356.html

上一篇: javascript无法访问私有属性

下一篇: 堆栈中局部变量的X86空间分配