Why does first parameter in x86 assembly starts from offset 8?

若如初见. 提交于 2019-12-01 20:49:33

问题


I'm trying to develop understanding of Assembly language. I understand that when function creates stack frame, it pushes current EBP, than copies stack pointer value to the EBP. First (and only) function parameter is accessed by EBP + 8. But why 8? Next value after pushed EBP is logically offset 4. I read many webpages, but it seems I don't understand this part.


回答1:


The "missing" DWORD is the return address. The call stack looks like:

ebp     : saved ebp
ebp + 4 : return address
ebp + 8 : pushed parameter

And then if the function uses local variables, since stack space is (typically) reserved for those after the stack frame, they are referenced as ebp - xx:

ebp - 8 : second local
ebp - 4 : first local
ebp     : saved ebp
ebp + 4 : return address
ebp + 8 : pushed parameter


来源:https://stackoverflow.com/questions/42771550/why-does-first-parameter-in-x86-assembly-starts-from-offset-8

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!