,每次除法所得的商,即是BCD数的千位、百位和十位数,余数是个位数。子程序名:B2TOBCD输入参数:AX=十六位二进制数输出参数:CF=0,则AX=4位压缩型BCD码。CF=1,则要转换的数大于9999,AX不变。使用寄存器:CX:存放除数,DX:存放中间结果。B2TOBCDPROCFARCMPAX,9999;AX>9999,则CF置1JBETRANSTCJMPEXITTRAN:PUSHCXPUSHDXSUBDX,DX;DX清0MOVCX,1000;计算千位数DIVCXXCHGAX,DX;商在DX中,余数在AX中MOVCL,4SHLDX,CL;DX左移4位MOVCL,100;计算百位数DIVCLADDDL,AL;百位数加到DL中,DX左移4位MOVCL,4SHLDX,CLXCHGAL,AH;余数保留在AL中SUBAH,AHMOVCL,10;计算十位数DIVCLADDDL,AL;十位数加到DL中,DX左移4位MOVCL,4SHLDX,CLADDDL,AH;加个位数MOVAX,DX;结果送到AX中POPDXPOPCXEXIT:RETB2TOBCDENDP(2)将AX中4位BCD码顺序乘以1000,100,10和1,然后求和即得。子程序名:BCDTOB2输入参数:AX=4位压缩BCD码输出参数:AX=十六位二进制数使用寄存器:BX:暂存数据,CX:存放乘数,DX:存放中间结果BCDTOB2PROCFARPUSHBXPUSHCXPUSHDXMOVBX,AXMOVCL,4ROLAX,CLANDAX,000FHMOVCX,1000;乘以1000MULCXMOVDX,AXMOVAX,BXMOVCL,8ROLAX,CLANDAX,000FHMOVCL,100;乘以100MULCLADDDX,AXMOVAX,BXMOVCL,4SHRAX,CLANDAX,000FHMOVCL,10;乘以10