汇编语言 子程序结构

整理文档很辛苦,赏杯茶钱您下走!

免费阅读已结束,点击下载阅读编辑剩下 ...

阅读已结束,您可以下载文档离线阅读编辑

资源描述

1第六章子程序结构过程定义伪操作子程序的调用与返回保存与恢复寄存器子程序的参数传送子程序的嵌套与递归21.过程定义伪操作过程名PROCNEAR(FAR)过程名ENDP(1)NEAR属性:调用程序和子程序在同一代码段中(段内调用)(2)FAR属性:调用程序和子程序不在同一代码段中(段间调用)...3codesegmentmainprocfar……callsubr1……retmainendpsubr1procnear……retsubr1endpcodeendssegxsegmentsubtprocfar……retsubtendp……callsubt……segxendssegysegment……callfarptrsubt……segyends4子程序调用:隐含使用堆栈保存返回地址callnearptrsubp(1)保存返回地址(2)转子程序callfarptrsubp(1)保存返回地址(2)转子程序子程序返回:ret2.子程序的调用与返回(SP)→(IP)(IP)(CS)(SP)→53.保存与恢复寄存器subtprocfarpushaxpushbxpushcxpushdx…………popdxpopcxpopbxpopaxretsubtendp6(1)通过寄存器传送参数(2)通过存储器传送参数(3)通过地址表传送参数地址(4)通过堆栈传送参数或参数地址(5)多个模块之间的参数传送4.子程序的参数传送7例:十进制到十六进制的转换(通过寄存器传送参数)decihexSEGMENTASSUMECS:decihexmainprocfarstart:calldecibincallcrlfcallbinihexcallcrlfmovah,1int21hcmpal,27jnzstartmovah,4chint21hmainendpdecihexENDSENDstart参数传递方法18decibinprocnearmovbx,0newchar:movah,1int21hsubal,30hjlexitcmpal,9djgexitcbwxchgax,bxmovcx,10mulcxaddbx,axjmpnewcharexit:retdecibinendpbinihexprocnearmovch,4rotate:movcl,4rolbx,clmoval,blandal,0fhaddal,30hcmpal,3ahjlprintitaddal,7hprintit:movdl,almovah,2int21hdecchjnzrotateretbinihexendpcrlfprocnearmovdl,0dhmovah,2int21hmovdl,0ahmovah,2int21hretcrlfendp9例:累加数组中的元素(通过存储器传送参数)datasegmentarydw1,2,3,4,5,6,7,8,9,10countdw10sumdw?dataendscodesegmentmainprocfarassumecs:code,ds:dataStart:movax,datamovds,axcallproaddmovax,4c00hint21hmainendpcodeendsendstartproaddprocnearpushaxpushcxpushsileasi,arymovcx,countxorax,axnext:addax,[si]addsi,2loopnextmovsum,axpopsipopcxpopaxretproaddendp参数传递方法210如果数据段定义如下:datasegmentarydw1,2,3,4,5,6,7,8,9,10countdw10sumdw?ary1dw10,20,30,40,50,60,70,80,90,100count1dw10sum1dw?dataends如果直接访问内存变量,那么累加数组ary和数组ary1中的元素不能用同一个子程序proadd。11例:累加数组中的元素(通过地址表传送参数地址)datasegmentarydw10,20,30,40,50,60,70,80,90,100countdw10sumdw?tabledw3dup(?);地址表dataendscodesegmentmainprocfarassumecs:code,ds:datapushdssubax,axpushaxmovax,datamovds,axmovtable,offsetarymovtable+2,offsetcountmovtable+4,offsetsummovbx,offsettablecallproaddretmainendp参数传递方法312proaddprocnearpushaxpushcxpushsipushdimovsi,[bx]movdi,[bx+2]movcx,[di]movdi,[bx+4]xorax,axnext:addax,[si]addsi,2loopnextmov[di],axpopdipopsipopcxpopaxretproaddendpcodeendsendmain30d40d50d60d70d80d90d100d10dary20d10dcountsumtable0000001400160018000000140016(bx)(si)(di)550d13例:累加数组中的元素(通过堆栈传送参数地址)datasegmentarydw10,20,30,40,50,60,70,80,90,100countdw10sumdw?dataendsstacksegmentdw100dup(?)toslabelwordstackends参数传递方法414code1segmentmainprocfarassumecs:code1,ds:data,ss:stackstart:movax,stackmovss,axmovsp,offsettosmovax,datamovds,axmovbx,offsetarypushbxmovbx,offsetcountpushbxmovbx,offsetsumpushbxcallfarptrproaddmovax,4c00hint21hmainendpcode1ends15code2segmentassumecs:code2proaddprocfarpushbpmovbp,sppushaxpushcxpushsipushdimovsi,[bp+0ah]movdi,[bp+8]movcx,[di]movdi,[bp+6]code2endsendstartxorax,axnext:addax,[si]addsi,2loopnextmov[di],axpopdipopsipopcxpopaxpopbpret6proaddendp(ip)(cs)sumcountarray(di)(si)(cx)(ax)(sp)(bp)(bp)(bp)+0ah(bp)+8(bp)+6tos

1 / 15
下载文档,编辑使用

©2015-2020 m.777doc.com 三七文档.

备案号:鲁ICP备2024069028号-1 客服联系 QQ:2149211541

×
保存成功