一个程序同时实现十进制到二进制转换和十六进制到二进制的转换,通过在输入的数字后面加不加“H”来确定是10进制还是16进制,用int 16中断。求高手帮忙。最好能有源代码和注释,小弟再次谢过
------解决方案--------------------------------------------------------
data SEGMENT
ALTER DB 0ah,0dh
DB 0ah,0dh
DB 'Please alter your option',0AH,0DH
DB ' 1:Decimal number change into binary number',0AH,0DH;十进制转化为二进制
DB ' 2:Binary number change into decimal number',0AH,0DH;二进制转化为十进制
DB ' 3:Decimal number change into hexadecimal number',0AH,0DH;十进制转化为十六进制
DB ' 4:Hexadecimal number change into decimal number',0AH,0DH;十六进制转化为十进
DB ' 5:Binary number change into hexadecimal number',0AH,0DH;二进制转化为十六进制
DB ' 6:Hexadecimal number change into binary number',0AH,0DH;十六进制转化为二进制
DB ' 7:EXIT',0AH,0DH,'$'
SHI DB 'Please input a decimal number',0AH,0DH,'$';输入十进制数
ER DB 'Please input a Binary number',0AH,0DH,'$';输入二进制数
SLIU DB 'Please input a Hexadecimal number',0AH,0DH,'$';输入十六进制数
WRO DB 'You have input a wrong number,please input again!',0AH,0DH,'$'
RES DB 'The result is:',0AH,0DH,'$'
data ENDS
code SEGMENT
ASSUME CS:code,DS:data
start:
MOV AX,data
MOV DS,AX
MOV DL,0AH
MOV AH,2
INT 21h
disp MACRO m
LEA DX,m
MOV AH,9
INT 21h
ENDM
ltol:
LEA DX,ALTER;显示输入选择
MOV AH,9
INT 21h
MOV AH,1;输入选择
INT 21h
CMP AL,'1';如果是第一项跳转到子程序Onechange
JZ LAB1
CMP AL,'2';如果是第二项跳转到子程序Twochange
JZ LAB2
CMP AL,'3';如果是第三项跳转到子程序Therechange
JZ LAB3
CMP AL,'4';如果是第四项跳转到子程序Fourchange
JZ LAB4
CMP AL,'5'
JZ LAB5;如果是第五项跳转到子程序Fivechange
CMP AL,'6'
JZ LAB6;如果是第五项跳转到子程序Fivechange
CMP AL,'7';如果是第七项跳转到子程序EXIT
;JZ alt
CALL WRONG
;jmp START
;alt: LEA DX,str1
JMP start
LAB1 : CALL Onechange;跳转到子程序Onechange
JMP ltol
LAB2:CALL Twochange;跳转到子程序Twochange
JMP ltol
LAB3:CALL Threechange;跳转到子程序Threechange
JMP ltol
LAB4:CALL Fourchange;跳转到子程序Fourchange
JMP ltol
LAB5:CALL Fivechange;跳转到子程序Fivechange
JMP ltol
LAB6:CALL Sixchange;跳转到子程序Fivechange
JMP ltol
EXIT:MOV AH,4ch;退出DOS界面
INT 21h
; 子程序 Onechange
;功能:把十进制转化为二进制数
Onechange PROC NEAR
MOV DL,0AH
MOV AH,2
INT 21h
LEA DX,SHI;显示输入十进制数
MOV AH,9
INT 21h
MOV BX,0
MOV SI,16
newchar7:
MOV AH,1
INT 21h
SUB AL,30h
JL show1
CMP AL,9d
JG show1
CBW
XCHG AX,BX
MOV CX ,10d
MUL CX
XCHG AX,BX
ADD BX,AX
JMP newchar7
show1:
MOV DL,0AH
MOV AH,2
INT 21h
LEA DX,RES
MOV AH,9
INT 21h
show7:
ROL BX,1
MOV AL,BL
AND AL,1h
ADD AL,30h
MOV DL,AL
MOV AH,2
INT 21h
DEC SI
JNZ show7
RET
Onechange ENDP
; 子程序 Twochange
;功能:把二进制转化为十进制数
Twochange PROC NEAR
MOV DL,0AH
MOV AH,2
INT 21h
LEA DX,ER;显示输入二进制数
MOV AH,9
INT 21h
MOV BX,0
MOV SI,16
newchar2:
MOV AH,1
INT 21h
SUB AL,30h
JL show3
CMP AL,10d
JL add_to4
JMP show3
add_to4:
MOV CL,1
SHL BX,CL
MOV AH,0
ADD BX,AX
JMP newchar2
show3:
MOV DL,0AH
MOV AH,2
INT 21h
LEA DX,RES; 显示输出结果
MOV AH,9
INT 21h
MOV CX,10000d
CALL dec_div4
MOV CX,1000
CALL dec_div4
MOV CX,100
CALL dec_div4
MOV CX,10
CALL dec_div4
MOV CX,1
CALL dec_div4
RET
dec_div4 PROC NEAR
MOV AX,BX
MOV DX,0
DIV CX
MOV BX,DX
MOV DL,AL
ADD DL,30h
MOV AH,2
INT 21h