码迷,mamicode.com
首页 > 其他好文 > 详细

stack frame in memory(一)

时间:2016-05-13 13:31:10      阅读:181      评论:0      收藏:0      [点我收藏+]

标签:

The content of this article is from Assembly Language For x86 Processors Sixth Edition By Kip R.Irvine,appended with some understanding of myself.

技术分享


1.Stack Parameters
1.1    Contrast register parameters with stack parameters
技术分享
1.2    Two general types of arguments are pushed on the stack during subroutine calls:
技术分享
技术分享
技术分享
技术分享
2.Accessing Stack Parameters
2.1    prologue & epilogue
技术分享
prologue:
push ebp
mov ebp,esp
epilogue:
pop ebp
ret
 
2.2    clearing the stack
技术分享
技术分享
The illustration above is of vital important to show the right order of the content in the subroutine‘s stack——the return address is must be the fisrt one to be pushed into the stack.
The reason that I emphasize this is because we‘re gonna deal with a tough problem derived from the call of a subroutines.
技术分享
So now let me summerize the whole stuff:First of all,there‘s a successive space in the memory,whose first address is pointed by sp.And the moment when our procedure call the subroutine,which leads to the prologue step as we‘ve mentioned above.Then we substrct the sp,which means to expand the space of the stack,and the space we get now is constant during the calling of the subroutine.sp and bp remain fixed throughout the subroutine,because we always need "somebody" to tell us the exact location of the stack we use.However,we can move si or bx across the stack to get and process the data inside it.
技术分享技术分享

2.3    Passing 8-bit and 16-bit arguments on the stack
技术分享
general way to solve it
技术分享

2.4    Saving & Restoring registers
技术分享
From this illustration we can see that all the parameters and return address are stored upside the EBP&ESP,because they are tranmitted from outside,not produced by the subroutine itself.And we can also see that all the push&pop operators are operated under the ESP and EBP.

stack frame in memory(一)

标签:

原文地址:http://www.cnblogs.com/immortal-worm/p/5487417.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!