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.