;输入4位16进制数,将其以10进制的形式显示
CODE SEGMENT
ASSUME CS:CODE
ORG 100H
START:
JMP BBB
MSG DB 10,13,'please input a number(hex):','$'
T1 DB 0,1,2,3,4,5,6,7,8,9,10,10,11,11,12,12,13,13,14,14,15,15
T2 DB '0','1','2','3','4','5','6','7','8','9'
DB 'a','A','b','B','c','C','d','D','e','E','f','F'
BBB:
PUSH CS
POP DS
PUSH CS
POP ES
LEA DX,MSG
MOV AH,9
INT 21H
;----------------------
MOV AX,0
MOV CX,4
PUSH AX
@0:
MOV AH,1
INT 21H
LEA SI,T2
LEA DI,T1
@1: CMP AL,[SI]
JE @2
INC SI
INC DI
JMP @1
@2: MOV AL,[DI]
MOV AH,0
MOV SI,AX
POP AX
MOV BL,16
MOV BH,0
MUL BX
ADD AX,SI
PUSH AX
LOOP @0
LINE0:
POP AX
CALL DISPNUM
;-------------------------
MOV AH,4CH
INT 21H
; 显示十进制整型数值子程序
DISPNUM PROC NEAR
; 将要显示的数据放入AX中
JMP DISPSUB
Y DB 10,13,0,0,0,0,0,'$'
DISPSUB: MOV DX,0
MOV BX,10
DIV BX
MOV BYTE PTR[Y+6],DL ;保存个位
MOV DX,0
DIV BX
MOV BYTE PTR[Y+5],DL ;保存十位
MOV DX,0
DIV BX
MOV BYTE PTR[Y+4],DL ;保存百位
MOV DX,0
DIV BX
MOV BYTE PTR[Y+3],DL ;保存千位
MOV BYTE PTR[Y+2],AL ;保存万位
;------------------------
MOV AL,BYTE PTR[Y+2]
ADD AL,30H ;万位转ASC2
MOV BYTE PTR[Y+2],AL
;---------------------------
MOV AL,BYTE PTR[Y+3]
ADD AL,30H ;千位转ASC2
MOV BYTE PTR[Y+3],AL
;---------------------------
MOV AL,BYTE PTR[Y+4]
ADD AL,30H ;百位转ASC2
MOV BYTE PTR[Y+4],AL
;--------------------------
MOV AL,BYTE PTR[Y+5]
ADD AL,30H ;十位转ASC2
MOV BYTE PTR[Y+5],AL
;---------------------------
MOV AL,BYTE PTR[Y+6]
ADD AL,30H ;个位转ASC2
MOV BYTE PTR[Y+6],AL
;-----------------------------
MOV DI,1
DISP1:
INC DI
CMP DI,6
JE DISPEXIT
CMP BYTE PTR[Y+DI],'0'
JNE DISPEXIT
MOV BYTE PTR[Y+DI],' '
JMP DISP1
DISPEXIT:
MOV AH,9
LEA DX,Y
INT 21H
RET
DISPNUM ENDP
CODE ENDS
END START