资源描述:
《总汇编二进制转十进制,十六进制代码》由会员上传分享,免费在线阅读,更多相关内容在工程资料-天天文库。
1、实用文档特注:代码可以优化,请读者自己思考,运行结果绝对没问题!实验二数制转换程序代码二进制到十进制转换DATASSEGMENTS0DB"pleaseinputabinary(length<16):",0AH,0DH,"$"S1DB18S2DB?;总长度S3DB16DUP(0);存放首地址S4DW?;存放输入的二进制数S5DB"Thenuberisnotabinary!","$"S6DB"Doyouwanttocontinue?(YorN):",0AH,0DH,"$"TEMPDB0BUFDB5DUP(?);此处输入数据段代码DA
2、TASENDSSTACKSSEGMENTDB256DUP(?);初始化堆栈大小为100;此处输入堆栈段代码STACKSENDSCODESSEGMENTASSUMECS:CODES,DS:DATAS,SS:STACKSSTART:MOVAX,DATASMOVDS,AXMOVAX,STACKSMOVSS,AX;---------------------------------------------------;输入一个二进制数LOOPP:CALLCLSCALLHCMOVDX,OFFSETS0;显示字符串s0CALLG9;"plea
3、seinputabinary(length<16):",0AH,0DH,"$"MOVDX,OFFSETS1;申请16个内存空间MOVAH,0AH;将数输入到缓冲区文案大全实用文档INT21H;------------------------------------------------------;将输入的数据整合放到AX中MOVSI,OFFSETS3MOVCL,S2MOVCH,0HMOVAX,0HLOOP1:CMPBYTEPTR[SI],30H;判断是否为二进制数JLEXITCMPBYTEPTR[SI],31HJGEXITM
4、OVBL,[SI]SUBBL,30HMOVBH,0HINCSISHLAX,1ADDAX,BXLOOPLOOP1MOVS4,AXCALLHC;-----------------------------------------------------;二进制转换成十进制MOVSI,5MOVAX,S4MOVCX,5MOVBX,10LP:CWDMOVDX,0DIVBXADDDL,30HMOVBUF[SI-1],DLDECSILOOPLP;-------------------------------------------------;
5、显示结果CALLCOUNT;找到第一个非零元的位置文案大全实用文档MOVAL,TEMPMOVAH,0MOVSI,AXMOVCX,5LOOPPP:MOVDL,BUF[SI]MOVAH,02HINT21HINCSILOOPLOOPPPJMPEXIT1EXIT:CALLHCMOVDX,OFFSETS5;显示字符串S5CALLG9;"Thenuberisnotabinary!","$"EXIT1:CALLHCMOVDX,OFFSETS6;显示字符串S6CALLG9;"Doyouwanttocontinue?(YorN):",0AH,0D
6、H,"$"MOVAH,1INT21HCMPAL,'Y'JELOOPPCMPAL,'y'JELOOPPMOVAH,4CHINT21HCOUNT:;判断第一个非零元的位置MOVTEMP,0MOVSI,0MOVCX,4LOO:MOVDL,BUF[SI]CMPDL,30HJNEEXIT3MOVAL,TEMPADDAL,1文案大全实用文档MOVTEMP,ALINCSILOOPLOOEXIT3:RETG9:MOVAH,9;显示功能调用INT21HCALLHCRETHC:;回车换行MOVDL,0AHMOVAH,2INT21HMOVDL,0DH
7、MOVAH,2INT21HRETCLS:MOVAH,6;屏幕初始化MOVAL,0MOVBH,7HMOVCH,0MOVCL,0MOVDH,24MOVDL,79INT10HMOVBH,0;置光标位子MOVDX,0MOVAH,2INT10HRETCODESENDSENDSTART文案大全实用文档二进制到十六进制转换DATASSEGMENTS0DB"pleaseinputabinary(length<16):",0AH,0DH,"$"S1DB17S2DB?;总长度S3DB16DUP(0);存放首地址S4DW?;存放输入的二进制数S5DB
8、"Thenuberisnotabinary!","$"S6DB"Doyouwanttocontinue?(YorN):",0AH,0DH,"$"S7DB"Thelengthofthenumbeiisnot16","$"DATASENDSSTACKSSEGMENT