资源描述:
《微机原理十六进制转十进制程序.doc》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、1.方法一CODESEGMENTMAINPROCFARASSUMECS:CODESTART:CALLHEXIBIN;16-2CALLCRLF;换行CALLBINIDEC;2-10CALLCRLFJMPMAIN;getnextinputRETMAINENDPHEXIBINPROCNEARMOVBX,0;clearBXfornumberNEWCHAR:MOVAH,01H;keyboardinputINT21H;callDOSSUBAL,30H;ASCIItobinaryJLEXIT;jumpif<0CMPAL,10D;isit>9dJLADD_TO;yes,so
2、it'sdigit;notdigit(0-9),maybeletter(atof)SUBAL,27H;convertASCIItobinaryCMPAL,0AH;isit<0ahex?JLEXIT;yes,notletterCMPAL,10H;isit>0fhex?JGEEXIT;yes,notletter;ishexdigit,addtonumberinBXADD_TO:MOVCL,4SHLBX,CLMOVAH,0ADDBX,AXJMPNEWCHAREXIT:RETHEXIBINENDPBINIDECPROCNEARMOVCX,10000DCALLDEC_
3、DIVMOVCX,1000DCALLDEC_DIVMOVCX,100DCALLDEC_DIVMOVCX,10DCALLDEC_DIVMOVCX,1DCALLDEC_DIVRETDEC_DIVPROCNEARMOVAX,BX;numberlowhalfMOVDX,0;zeroouthighhalfDIVCXMOVBX,DX;remainderintoBXMOVDL,AL;quotientintoDL;printthecontentsofDLonscreenADDDL,30H;converttoASCIIMOVAH,02HINT21HRETDEC_DIVENDP
4、BINIDECENDPCRLFPROCNEARMOVDL,0AHMOVAH,02HINT21HMOVDL,0DHMOVAH,02HINT21HRETCRLFENDPCODEENDSENDSTART2.方法二datasegmentmdw10dup(?)recdb5dup(?);记录因子MESSAGE5DB'Welcometothesystem!',13,10,13,10DB'ThefunctionoftheprogramischangingH(16)numbersintoD(10)numbers.',13,10DB'Pleaseenterthenumber..
5、..',13,10,13,10,'$'dataendscodesegmentmainprocfarassumecs:code,ds:datastart:pushdsmovax,datamovds,axmovbx,0LEADX,MESSAGE5MOVAH,09HINT21H;输出提示语newchar:movah,1;键盘输入int21hsubal,30hjlini;<0输出cmpal,10jladd_tosubal,27h;‘a’~‘f’cmpal,0ahjlini;<‘a’输出cmpal,10hjgeini;>’f’输出add_to:movcl,4shlbx
6、,clmovah,0addbx,axmovm,bxjmpnewcharini:movax,mmovbx,10movsi,4change:movdx,0divbxmov[rec+si],dldecsicmpax,0jachangeoutput:incsimovdl,[rec+si]adddl,30hmovah,02hint21hcmpsi,4jboutputmovdl,20hmovah,02hint21hexit:movah,4chint21hmainendpcodeendsendstart