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