欢迎来到天天文库
浏览记录
ID:43046338
大小:257.71 KB
页数:11页
时间:2019-09-24
《【精品】函数栈分析》由会员上传分享,免费在线阅读,更多相关内容在工程资料-天天文库。
1、首先看看《ComputerSystems》•书中关于函数调用的描述:IA32programsmakeuseoftheprogramstacktosupportprocedurecalls.Thestackisusedtopassprocedurearguments,tostorereturninformation,tosaveregistersforlaterrestoration,andforlocalstorage・Theportionofthestackallocatedforasingleprocedurecalliscalledastackframe・Figure3
2、.16diagramsthegeneralstructureofastackframe・Thetopmoststackframeisdelimitedbytwopointers,withregister%ebpservingastheframepointer,andregister%espservingasthestackpointer.Thestackpointercanmovewhiletheprocedureisexecuting,andhencemostinformationisaccessedrelativetotheframepointer・StackBottom
3、▼CunentFiaineCaller'sFrameIncieasingAddiessFlgiire3.16:StackFrameStructure.Thestackisusedforpassingarguments.forstormgrekimmfbmia-tioiLforsavingregisters,andforlocalstorage.SupposeprocedureP(thecaller)callsprocedureQ(thecallee).TheargumentstoQarecontainedwithinthestackframeforP.Inaddition,w
4、henPcallsQ,thereturnaddresswithinPwheretheprogramshouldresumeexecutionwhenitreturnsfromQispushedonthestack,formingtheendofP'sstackframe・ThestackframeforQstartswiththesavedvalueoftheframepointer(i.e.,%ebp)・followedbycopiesofanyothersavedregistervalues・ProcedureQalsousesthestackforanylocalvar
5、iablesthatcannotbestoredinregisters・Thiscanoccurforthefollowingreasons:1.Therearenotenoughregisterstoholdallofthelocaldata・2.Someofthelocalvariablesarearraysorstructuresandhencemustbeaccessedbyarrayorstructurereferences・3.Theaddressoperator1&'isappliedtooneofthelocalvariables,andhencewemust
6、beabletogenerateanaddressforit.Finally,Qwillusethestackframeforstoringargumentstoanyproceduresitcalls・Asdescribedearlier,thestackgrowstowardloweraddressesandthestackpointer%esppointstothetopelementofthestack・Datacanbestoredonandretrievedfromthestackusingthepushlandpoplinstructions.Spaceford
7、atawithnospecifiedinitialvaluecanbeallocatedonthestackbysimplydecrementingthestackpointerbyanappropriateamount.Similarly,spacecanbedeallocatedbyincrementingthestackpointer.卜・血进入测试过程,我的测试代码如下:#ineludevoidtest(inti){charoutput[8];strcpy(output,Habcdefgn);}
此文档下载收益归作者所有