您好,欢迎访问三七文档
暨南大学本科实验报告专用纸课程名称汇编语言程序设计成绩评定实验项目名称子程序程序设计指导教师实验一、实验目的和要求1)学习子程序的定义和调用方法。2)掌握子程序设计、编制及调试。二、实验内容1)编写一个通用子程序用来将十进制数(从键盘输入)转换为P(从键盘输入)进制数。P可以为2、8或16。2)编写子程序,将字节单元中的二进制数转换成十进制数输出。3)编写子程序,在字符串中第n个字符前插入长度为m的字符串。二、程序流程图(每题分开写)1.暨南大学本科实验报告专用纸(附页)输出提示语调用子程序save_number转为16进制输出提示语,用哪种进制调用子程序change结束子程序change目标输出为几进制调用two子程序调用eight子程序调用sixth子程序2暨南大学本科实验报告专用纸(附页).X=99,BX=X调用子程序AX=BX,BX=10,CX=0DX=0,DIVBX,DL+48转换为十进制DX入栈,CX+1AX=0?DX出栈,输出dlCx=0?结束否是否是3暨南大学本科实验报告专用纸(附页)String1,string2,输入。string6Cl=bl=插入点位置Si=offsetstring1+2Di=offsetstring6[Di]=[si]IncdiIncsiCx=0?Cx=cx-1Si=offsetstring+2[si]为回车符?[di]=[si]IncdiIncsi输出string1结束否是否是子程序暨南大学本科实验报告专用纸(附页)三、源程序(每题分开写)1.DSEGSEGMENT'DATA';addyourdatahere!INPUT_TIPS1DB'PLEASEINPUTANUMBER:',0DH,0AH,'$'INPUT_TIPS2DB0DH,0AH,'HEX(H),OCTAL(O),ORBINARY(B)?:',0DH,0AH,'$'INPUT_TIPS3DB0DH,0AH,'HEX(H)IS:',0DH,0AH,'$'INPUT_TIPS4DB0DH,0AH,'OCTAL(O)IS:',0DH,0AH,'$'INPUT_TIPS5DB0DH,0AH,'BINARY(B)IS:',0DH,0AH,'$'INPUT_NUMBERDB128DUP('0'),'$'TRUE_NUMBERDW0DSEGENDSSSEGSEGMENTSTACK'STACK'db256DUP(0)SSEGENDSCSEGSEGMENT'CODE'STARTPROCFAR;setsegmentregisters:MOVAX,DSEGMOVDS,AXMOVES,AX;addyourcodehere;INPUTTIPSMOVAH,09HMOVDX,OFFSETINPUT_TIPS1INT21HMOVAH,0AHMOVDX,OFFSETINPUT_NUMBERINT21HCALLSAVE_NUMBER;INPUTTIPSMOVAH,09HMOVDX,OFFSETINPUT_TIPS2暨南大学本科实验报告专用纸(附页)INT21HMOVAH,01HINT21HCALLCHANGEFINISH:MOVAX,4C00h;exittooperatingsystem.INT21hSTARTENDP;入口TRUE_NUMBER=数twoPROCNEARPUSHAXPUSHBXPUSHCXPUSHDX;INPUTTIPSMOVAH,09HMOVDX,OFFSETINPUT_TIPS5INT21HMOVCL,15AGAIN2:MOVDX,[TRUE_NUMBER]SHRDX,CLJMPPRINT_IT2NEXT2:CMPCL,0JZtwo_FINISHSUBCL,1JMPAGAIN2PRINT_IT2:ANDDX,01HCMPDX,09HJANOT_ZERO2SUBDX,7HNOT_ZERO2:ADDDX,37HMOVAH,02H暨南大学本科实验报告专用纸(附页)INT21HJMPNEXT2two_FINISH:MOVAH,02HMOVDX,'B'INT21HPOPDXPOPCXPOPBXPOPAXRETTwoENDP;入口TRUE_NUMBER=数eightPROCNEARPUSHAXPUSHBXPUSHCXPUSHDX;INPUTTIPSMOVAH,09HMOVDX,OFFSETINPUT_TIPS4INT21HMOVCL,15AGAIN8:MOVDX,[TRUE_NUMBER]SHRDX,CLJMPPRINT_IT8NEXT8:CMPCL,0JZeight_FINISHSUBCL,3JMPAGAIN8PRINT_IT8:ANDDX,07HCMPDX,09HJANOT_ZERO8SUBDX,7HNOT_ZERO8:暨南大学本科实验报告专用纸(附页)ADDDX,37HMOVAH,02HINT21HJMPNEXT8eight_FINISH:MOVAH,02HMOVDX,'O'INT21HPOPDXPOPCXPOPBXPOPAXRETeightENDP;入口TRUE_NUMBER=数sixthPROCNEARPUSHAXPUSHBXPUSHCXPUSHDX;INPUTTIPSMOVAH,09HMOVDX,OFFSETINPUT_TIPS3INT21HMOVCL,12;每次移4位AGAIN:MOVDX,[TRUE_NUMBER]SHRDX,CLJMPPRINT_ITNEXT:CMPCL,0JZSIXTH_FINISHSUBCL,4JMPAGAINPRINT_IT:ANDDX,0FHCMPDX,09HJANOT_ZERO暨南大学本科实验报告专用纸(附页)SUBDX,7HNOT_ZERO:ADDDX,37HMOVAH,02HINT21HJMPNEXTSIXTH_FINISH:MOVAH,02HMOVDX,'H'INT21HPOPDXPOPCXPOPBXPOPAXRETSIXTHENDP;入口,AL=选择目的进制CHANGEPROCNEARPUSHAXPUSHBXPUSHCXPUSHDXCMPAL,'H'JZHEXJAOCTALJLBINARYHEX:CALLSIXTHJMPCHANGE_TO_SECTION_FINISHOCTAL:CALLeightJMPCHANGE_TO_SECTION_FINISHBINARY:CALLtwoJMPCHANGE_TO_SECTION_FINISHCHANGE_TO_SECTION_FINISH:POPDXPOPCX暨南大学本科实验报告专用纸(附页)POPBXPOPAXRETCHANGEENDP;SAVE_NUMBERPROCNEARPUSHAXPUSHBXPUSHCXPUSHDXMOVCL,[INPUT_NUMBER+1]MOVCH,0MOVBX,CXMOVDL,1;判断是否为负数MOVCH,[INPUT_NUMBER+2]CMPCH,'-'MOVCH,0JNELOOP1DECCX;转16进制存变量中LOOP1:MOVAL,[INPUT_NUMBER+BX+1]SUBAL,30HDECBXCMPDH,0JNZDOUBLEJMPSINGLEDOUBLE:MOVAH,0MOVBX,DXMULDXMOVDX,BXJMPADD_TRUE_NUMBERSINGLE:MULDLADD_TRUE_NUMBER:ADDTRUE_NUMBER,AXMOVAL,DL暨南大学本科实验报告专用纸(附页)MOVDL,10MULDLMOVDX,AXLOOPLOOP1CMPDH,'-'JNESAVE_NUMBER_FINISHMOVAX,[TRUE_NUMBER]NEGAXMOV[TRUE_NUMBER],AXSAVE_NUMBER_FINISH:POPDXPOPCXPOPBXPOPAXRETSAVE_NUMBERENDPCSEGENDSENDSTART;setentrypoint.2.DATASEGMENTXDW66DATAENDSCODESEGMENTASSUMECS:CODE,DS:DATASTART:MOVAX,DATAMOVDS,AXMOVBX,XCALLDISPBX;显示EXIT:MOVAH,4CHINT21H;=============================DISPBXPROCMOVAX,BXMOVBX,10暨南大学本科实验报告专用纸(附页)MOVCX,0ZH1:MOVDX,0DIVBXADDDL,'0'PUSHDXINCCXCMPAX,0JNZZH1MOVAH,2ZH2:POPDXINT21HLOOPZH2MOVDL,''INT21HRETDISPBXENDP;=============================CODEENDSENDSTART3.DSEGSEGMENT'DATA'STRING1db50db0db50dup('$')db'$'STRING2db50db0db50dup('$')db'$'STRING3db'PleaseentertheSTRING1.'db0dh,0ah,'$'STRING4db0dh,0ah,'PleaseentertheSTRING2.'db0dh,0ah,'$'STRING5db0dh,0ah,'PleaseenterthelocationintheSTRING1youwant.'db0dh,0ah,'$'STRING6db50dup('$')DSEGENDSSSEGSEGMENTSTACK'STACK'db256DUP(0)SSEGENDS暨南大学本科实验报告专用纸(附页)CSEGSEGMENT'CODE'STARTPROCFAR;setsegmentregisters:MOVAX,DSEGMOVDS,AXMOVES,AXmovdx,offsetSTRING3;语句1movah,09hint21hmovah,0ahmovdx,offsetSTRING1;输入s1int21hmovdx,offsetSTRING4;语句2movah,09hint21hmovah,0ahmovdx,offsetSTRING2;输入2int21hmovdx,offsetSTRING5;语句3movah,09hint21hmovah,01h;输入插入位置int21hCALLSON;子程序SONPROCsubal,30hmovcx,0movcl,almovbl,almovsi,offsetSTRING1+2movdi,offsetSTRING6first:movdl,byteptr[si]movbyteptr[di],dlincsiincdi暨南大学本科实验报告专用纸(附页)loopfirstmovsi,offsetSTRING2+2second:cmpbyteptr[si],0dhjzthirdnext2:movdl,byteptr[si]movbyteptr[di],dlincsiincdijnzsecondthird:movsi,offsetSTRING1+2movbh,0addsi,bxthird1:cmpbyteptr[si],'$'jzforthnext3:movdx,[si]mov[di],dxincsiincdijnzthird1forth:movsi,offsetSTRING1movdi,offsetSTRING6forth1:cmpbyteptr[di],'$'jzovernext4:movdl,byteptr[di]movbyteptr[si],dlincsiincdijnzforth1over:movdl,0dhmovah,02hint21hmovdl,0ahmovah,02hint21h暨南大学本科实验报告专用纸(附页)movdx,offsetSTRING1movah,09hint21hSONENDPMOVAX,4C00h;exittooperatingsystem.INT21hSTARTENDPCSEGENDSENDSTART;setentrypoint.
本文标题:汇编实验12
链接地址:https://www.777doc.com/doc-4312809 .html