给定以下代码:
swap:
push ebp ; back up the base pointer,
mov ebp, esp
; push the context of the registers on the stack
push eax
push ebx
push ecx
push edx
mov eax, [ebp+8] ; address of the first parameter
mov ebx, [ebp+12] ; address of the second parameter
mov dl, [eax]
mov cl, [ebx]
mov [eax], cl
mov [ebx], dl
; restore the context of the registers from the stack
pop edx
pop ecx
pop ebx
pop eax
; restore the ebp
pop ebp
ret
(这只是方法。之前,我们将第一个参数和第二个参数推送到堆栈上。)
我的问题是:为什么要在基指针上加8才能到达第一个参数的地址,然后再加12?
我知道它们都是双字,所以每个参数都是4个字节大小。从ebp + 8到ebp + 12,这样做是有意义的。但为什么第一个参数是ebp + 8?因为如果ESP指向堆栈的顶部,mov ebp,esp表示EBP指向堆栈的顶部。然后,我们在堆栈上推送4个值:eax,ebx,ecx和edx。为什么EBP + 8指向第一个参数?