实验二循环与子程序程序设计一、实验目的1)加深对循环结构的理解。2)掌握循环程序的设计方法。3)学习子程序的定义和调用方法。4)掌握子程序、子程序的嵌套、递归子程序的结构。5)掌握子程序设计、编制及调试。6)熟练掌握DEBUG的常用命令,学会用DEBUG调试程序。二、实验内容1)编制程序计算S=1+2·3+3·4+4·5+……+N(N+1)+……直到N(N+1)大于200为止,并将结果由屏幕上显示出来。2)将从3000H内存单元开始的100个字节存储单元全部清0。3)编制在屏幕上显示九九乘法表的程序。4)编制在屏幕上显示用*组成的三角形的程序。5)设有五个字数据存放在以BUF为首地址的内存单元中,要求采用调用多个字数据相加的子程序方法编程,和的低位字放在RESULT单元,和的高位字放在RESULT+2单元,并将结果显示在屏幕上。6)编写一个递归子程序,计算指数函数Xn的值,其中X,n从键盘输入。三、源程序EXAM2-1DATASEGMENTBUFDB’S=1+2×3+3×4+4×5+…+N(N+1)+…=’,’$’RESDW4DUP(0),’$’DATAENDSCODESEGMENTASSUMECS:CODE,DS:DATASTART:MOVAX,DATAMOVDS,AXMOVDX,OFFSETBUFMOVAH,09HINT21HMOVDX,1MOVBL,2NEXT:MOVAL,BLINCBLMULBLADDDX,AXCMPAX,200JNANEXTMOVCX,0004HMOVDI,OFFSETRESADDDI,03HNEXT1:MOVAX,DXANDAX,000FHCMPAL,0AHJBNEXT2ADDAL,07NEXT2:ADDAL,30HMOV[DI],ALDECDIPUSHCXMOVCL,04SHRDX,CLPOPCXLOOPNEXT1MOVDX,OFFSETRESMOVAH,09HINT21HMOVAH,4CHINT21HCODEENDSENDSTART执行程序EXAM2-1·EXE,屏幕上显示结果:S=1+2×3+3×4+4×5+…+N(N+1)+…=045FEXAM2-2ORG2000H2000BF0030MOVDI,30002003B164MOVCL,642005C60500MOVBYTEPTR[DI],0200847INCDI2009FEC9DECCL200B75F8JNZ2005200DF4HLTEXAM2-3DATASEGMENTATADDB?,2AH,?,3DH,?,?,20H,'$'ATAD1DB?,2AH,?,3DH,?,?,0DH,0AH,'$'DATAENDSSTACKSEGMENTSTACKDB20HDUP(0)STACKENDSCODESEGMENTASSUMECS:CODE,DS:DATASTART:MOVAX,DATAMOVDS,AXMOVCL,09HMOVBL,00HOKL:MOVAL,00HINCBLOK1:INCALPUSHAXCMPBL,ALJZOKMOVBH,ALMULBLMOVDI,OFFSETATADCALLOKPPOPAXJMPOK1OK:MOVBH,ALMULBLMOVDI,OFFSETATAD1CALLOKPPOPAXLOOPOKLMOVAH,4CHINT21HOKPPROCPUSHAXPUSHBXPUSHCXADDBX,3030HMOV[DI],BHMOV[DI+02H],BLMOVCX,0AHMOVDH,00HOKL2:CMPAX,CXJSOK2ADDCX,0AHINCDHJMPOKL2OK2:SUBCX,0AHSUBAX,CXMOVAH,DHADDAX,3030HMOV[DI+04H],AHMOV[DI+05H],ALMOVDX,DIMOVAH,09HINT21HPOPCXPOPBXPOPAXRETOKPENDPCODEENDSENDSTART执行程序EXAM2-2·EXE,屏幕上显示结果:1*1=011*2=022*2=041*3=032*3=063*3=091*4=042*4=083*4=124*4=161*5=052*5=103*5=154*5=205*5=251*6=062*6=123*6=184*6=245*6=306*6=361*7=072*7=143*7=214*7=285*7=356*7=427*7=491*8=082*8=163*8=244*8=325*8=406*8=487*8=568*8=641*9=092*9=183*9=274*9=365*9=456*9=547*9=638*9=729*9=81EXAM2-4CODESSEGMENTASSUMECS:CODESSTART:XORBX,BXMOVDL,2AHMOVCX,9LOP:PUSHCXINCBLMOVCL,BLMOVDL,2AHLOP2:MOVAH,02HINT21HLOOPLOP2POPCXMOVDL,0AHMOVAH,02HINT21HMOVDL,0DHMOVAH,02HINT21HCMPBL,9JZENDPROLOOPLOPENDPRO:MOVAH,4CHINT21HCODESENDSENDSTART执行程序EXAM2-4·EXE,屏幕上显示结果:*********************************************EXAM2-5STACKSEGMENTSTACKDB1024DUP(0)STACKENDSDATASEGMENTBUFDW0F101H,110DH,52H,100H,456HCOUNT=($-BUF)/2RESULTDW4DUP(?),'$'DATAENDSCODESEGMENTASSUMECS:CODE,DS:DATA,SS:STACKWDADDPROCPUSHDIMOVAX,0MOVDX,0MOVDI,OFFSETBUFNEXT2:ADDAX,[DI]JNCNEXT1INCDXNEXT1:ADDDI,2LOOPNEXT2POPDIRETWDADDENDPSHOWPROCPUSHCXPUSHDIMOVCX,04HMOVDI,OFFSETRESULTMOVBX,AXADDDI,07HBBB:MOVAX,BXANDAX,000FHCMPAL,0AHJBQQQADDAL,07HQQQ:ADDAL,30HMOV[DI],ALDECDIPUSHCXMOVCL,04SHRBX,CLPOPCXLOOPBBBMOVCX,0004HCCC:MOVAX,DXANDAX,000FHCMPAL,0AHJBDDDADDAL,07HDDD:ADDAL,30HMOV[DI],ALDECDIPUSHCXMOVCL,04HSHRDX,CLPOPCXLOOPCCCPOPDIPOPCXRETSHOWENDPBEGIN:MOVAX,DATAMOVDS,AXMOVCX,COUNTCALLWDADDCALLSHOWMOVDX,OFFSETRESULTMOVAH,09HINT21HMOVAH,4CHINT21HCODEENDSENDBEGIN执行程序EXAM2-5·EXE,屏幕上显示结果:000107B6