已阅读5页,还剩71页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
Chapter6 Procedure过程 Textbook 7ProgramLogicandControl Outline StackPUSHPOPProcedureDirectivesCALLRETSubprogramprogrammingMethodsofpassingparameters 8086Stack8086堆栈 6 1 Stack 堆栈 Stackcontainsanydataandaddressesthattheprogramneedstosavetemporarilyorforusebyyourown called subroutines Thestacksegment SS registeraddressesthestacksegment 堆栈是供程序使用的连续的内存空间 用于保存一些临时数据 MainUse Theprogramcallsasubroutineforspecialprocessing Itsavesthereturnaddressinthestack whichthesubroutinelaterusesforreturning Theprogramthatcallsthesubroutinemayalsopassdatabyplacingitinthestack wherethesubroutineaccessesit Theprogramhastoperformcalculationsthatusetheregisters itcansavethepresentcontentsoftheregistersonthestack makethecalculations andthenrestorethedatafromthestacktotheregisters Stack 堆栈 Thestackdiffersfromothersegmentsinitsmethodofstoringdata Itbeginsstoringdataatthehighestlocationinthesegmentandstoresdatadownward orbackward throughmemory LastinFirstOut是一种具有特殊访问方式的存储空间 特殊性在于 最后进入这个空间的数据 最先出去 PUSH POP Stack Initially thestackisemptyanditlookslikethis Examples movbx 2266Hpushbxmovcx 1122Hpushcxpopaxpopbx PAStackFrame OperationofPUSHBX 1 Initially thestackisemptyanditlookslikethis SS SP 1000 000E Examples SS 1000HSP 000EHbx 2266H PAStackFramePointer OperationofPUSHBX 2 1 DecrementSPby2 000C SP SP 2SS SP 1000 000C Examples PAStackFramePointer OperationofPUSHBX 3 2 StorethecontentsofBX 2266 inthestack Notethesequenceofthestoredbytes Examples SS 1000HSP 000CH storesdatadownward orbackward throughmemory 入栈时 栈顶从高地址向低地址方向增长 stack DecrementsSPby2 000Ah andstoresthecontentsofCXinthestack After state Examples movcx 1122Hpushcx stack RestoresthewordfromwhereSPpointsinthestack 000AH toAXandincrementsSPby2 000CH After state ax 1122H Examples popax PAStackFramePointer stack RestoresthewordfromwhereSPpointsinthestack 000CH toBXandincrementsSPby2 000EH After state bx 2266H Examples popbx PAStackFramePointer OperationofPOPBX 1 Initialstate SS SP1000 000C Examples SS 1000HSP 000CH PAStackFramePointer OperationofPOPBX 2 1 RestoresthewordfromwhereSPpointsinthestack 000CH toBX SS SP1000 000C Examples SS 1000HSP 000CHbx 2266H PAStackFramePointer OperationofPOPBX 3 2 AndincrementsSPby2 000EH SP SP 2SS SP1000 000EBX 2266H Examples PAStackFramePointer OperationofPOPBX 3 Note thePOPinstructionsarecodedinreversesequencefromPUSHinstructions 入栈时 栈顶从高地址向低地址方向增长 Examples PAStackFramePointer Stack 堆栈 Stackcontainsanydataandaddressesthattheprogramneedstosavetemporarily Thestacksegment SS registeraddressesthestacksegment 堆栈是供程序使用的连续的内存空间 用于保存一些临时数据 Instructions PUSH POP PUSH DecrementsSPby2andstoresthecontentsofthesourceoperandinthestack POP RestoresthewordfromwhereSPpointsinthestacktothedestinationoperandandincrementsSPby2 PUSHSRC pushontothestack SRCcanber16 m16 seg reg imm SP SP 2 SS SP r16 m16 seg Operations SP SP 2 SP SCR SP 1 SCR 1 notaffectflag PUSHInstruction POPInstruction Operations DST SP DST 1 SP 1 SP SP 2 POPDes Descanber16 m16 seg reg exceptcs r16 m16 seg SS SP SP SP 2 2 出栈指令POP 现场保护恢复 pushax whenenterasubroutinepushbxpushdx popdx whenexitfromthesubroutinepopbxpopax Examples Note 1 AllowPUSHimm notallowPOPimm 2 AllowPUSHCS notallowPOPCS 3 PUSHinstructionpushesawordontostackanddecrementthespby2 8086or80286 PUSHinstructionpushes2wordsontostackanddecrementthespby4 80386orlater PUSH Summary 1 Stackisalocationspaceinstack segment workaccordingtoFirst in last out 2 Justoneentry exit soonlyoneSP ThecontentofSPpointtothecurrenttop inoroutlocation ofthestackatanytime 3 PUSHorPOPaword notallowbyte 4 Anyaddressing exceptimmediate addressing 5 PUSHandPOPinstructionnotaffectflag bit ProcedureBody CallandReturn过程体 调用和返回 6 2 Procedure AprocedureisablockofcodethatbeginswiththePROCdirectiveandterminateswithENDPdirective Procedure Organizingaprogramintoproceduresprovidessomebenefits 1 Reducestheamountofcodebecauseacommonprocedurecanbecalledfromanynumberofplacesinthecodesegment 2 Encouragesbetterprogramorganization Procedure 3 Facilitatesdebuggingofaprogrambecausedefectscanbemoreclearlyisolated 4 Helpsintheongoingmaintenanceofprogramsbecauseproceduresarereadilyidentifiedformodification Outline ProcedureDirectiveInstructionsCALLRETSubroutineProgramming ProcedureDirectives AcodesegmentcontainsoneormoreproceduresOneprocedurecodedas ProcNamePROC near far entrypointforfirstinstructiontoexecute endaprocedureProcNameENDP ProcedureDirectives Theprocedurename ProcName mustbepresent uniqueandfollowassemblernamingconventions TheprocedureattributecanisNEAR FAR defaultisNEAR thatis within 32K attribute ProcNamePROC near far ProcNameENDP Callingprocedureandprocedure Instructions Format label2 RET pop value label1 CALLproc name Instructions Callinstructionistotransfercontroltoacalledprocedure RETinstructionreturnsfromthecalledproceduretotheoriginalcallingprocedure theinstructionafterCALLinstruction RETshouldbethelastinstructioninthecalledprocedure NearCallandReturn Acalltoaprocedurewithinthesamesegmentisnear Performs 1 bymeansofapushoperation decrementsSPby2 oneword andtransfersIPvalueontothestack 2 insertstheoffsetaddressofthecalledprocedureintoIP NearCallandReturn ARETthatreturnsfromanearprocedurebasicallyreversestheCALLsteps 1 popstheoldIPvaluefromthestackbackintoIP 2 incrementsSPby2 FarCallandReturn Afarcallcallsaprocedurelabeledfar possiblyinanothercodesegment Performs 1 firstpushesthecontentsofCSontothestackandinsertsthenewsegmentaddressinCS 2 thenpushesIPontothestackandinsertsanewoffsetaddressinIP FarCallandReturn TheCS IPpairnowpointstotheaddressofthefirstinstructiontoexecuteinthecalledsubprogram FarCallandReturn Onexitfromthecalledprocedure AfarRETreversestheCALLsteps popsboththeoriginalIPandCSaddressesbackintotheirrespectiveregisters FarCallandReturn TheCS IPpairnowpointstotheaddressoftheinstructionfollowingtheoriginalCALL CALLInstruction Fourtypes JMP CALLlabel Intra segmentdirect段内直接CALLr16 m16 Inter segmentdirect段内间接CALLfarptrlabel Inter segmentdirect段间直接CALLfarptrmem Inter segmentIndirect段间间接 CALLInstruction TheassemblercantellfromtheprocedurewhetherRETisnearorfarandgeneratestheappropriateobjectcode Butyoucanuse nearptr or farptr tosettheattribute CALLInstruction FourtypesofCALL CALLlabel 段内调用 相对寻址 SP SP 2 SS SP IP IP IP 16位位移量CALLr16 m16 段内调用 间接寻址 SP SP 2 SS SP IP IP r16 m16 label theprocedurename Nearcallandreturn Nearcall program beforecall memory stack Figure8 EffectonthestackandIPbyNearcall 0FFF 00031002 CALLInstruction FourtypesofCALL CALLfarptrlabel 段间调用 直接寻址 SP SP 2 SS SP CS SP SP 2 SS SP IP IP label偏移地址 CS label段地址 子程序调用指令 FourtypesofCALLNotethearrangementofthememory CALLfarptrmem 段间调用 间接寻址 SP SP 2 SS SP CS SP SP 2 SS SP IP IP mem CS mem 2 RETInstruction RETinstructionreturnsfromthecalledproceduretotheoriginalcallingprocedure theinstructionafterCALLinstruction Format RET CallingProcedureandCalledProcedure Subprogramprogramming Aprogrammingconventionistoprovidecommentsatthestartofeachproceduretoidentifyitspurposeandregistersused And ifnecessary topushchangedregistersatthestartandtopopthemonexiting subprogram subnameprocpushaxpushbxpushcx procedurebodypopcx note inreverseorderpopbxpopaxretsubnameendp Examples ifnecessary topushchangedregistersatthestartandtopopthemonexiting DisplayCR carriagereturn LF linefeed Examples Examples DisplayCR LF result ParametersandLocalVariable参数和局部变量 6 3 PassingParameters Passingparametersbyvalue theactualdataitem PassvaluesinregistersPassvaluesinstackPassingparametersbyreference theaddressofthedata AddressesinregistersAddressesinstack 例4 11求校验和 子程序计算数组元素的 校验和 校验和是指不记进位的累加入口参数 数组的逻辑地址 传址 元素个数 传值 出口参数 求和结果 传值 Passingparametersinregister 入口参数 cx 元素个数 DS BX 数组的段地址 偏移地址出口参数 al 校验和 Examples Passingparametersinregisters Examples Passingparametersinregisters Passingparametersinvariables 入口参数 count 元素个数 array 数组名 含段地址 偏移地址 出口参数 result 校验和 Examples Passingparametersinvariables Recursion递归 6 4 recursive Arecursi
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 管廊车辆伤害初期处置方案
- 设备噪声处置方案
- 2026年骨外科副主任医师考试大题及答案
- 灯具安装专项施工方案
- 羊水栓塞的护理团队协作
- 特殊部位烧伤的急救处理要点
- 老年护理的科技应用
- 猝死患者急救护理信息化建设
- 肠梗阻的护理效果评价
- 起重设备维护保养方案
- 《贵州劲同矿业有限公司清镇市麦格乡贵耐铝土矿(延续)矿产资源绿色开发利用方案(三合一)》评审意见
- 2026年上海市黄浦区初三语文二模试卷及答案
- 航天军工行业从海外看中国商发产业链前景
- 2026年各地算力统筹与算电协同精细化政策汇编解读
- 光伏产品进出口贸易合同协议(2025年度)
- 发展对象考试试题附答案
- 2026年《职业病防治法》宣传周知识竞赛考试题库附参考答案
- 乐至介绍教学课件
- 原创力文档-用户协议
- 【MOOC】模拟电子技术基础-华中科技大学 中国大学慕课MOOC答案
- 《建筑工程施工许可管理办法》2021年9月28日修订
评论
0/150
提交评论