第1个回答 2016-05-10
没太明白。
一般情况下,输入完数据后,按回车,结束输入。
你这按下ESC键,是当什么情况下按下?
难道是:比方说,输入12,这时按下ESC,屏幕上输出OK?
下面是不考虑按ESC情况的程序。
;read a Decimal number, print it Hex
dseg segment
n dw 0
f db 0
t db '0123456789ABCDEF'
msg0 db 'Please input decimal number between 0-65535:$'
msg1 db 'Conversion result is:$'
msg2 db 0dh,0ah,'Input error!',0dh,0ah,'$'
dseg ends
cseg segment
assume cs:cseg, ds:dseg
start:
mov ax, dseg
mov ds, ax
lea dx, msg0
mov ah,9
int 21h
lea si, n
call read10
cmp f,1
je ex0
lea dx, msg1
mov ah,9
int 21h
mov ax,n
call print
ex0:
mov ah,4ch
int 21h
;read a Decimal number
;store it in [si]
;end flag: char not in '0'-'9'
;readflag f:0-success, 1:error
read10 proc near
xor dx,dx
mov bx,10
rd0:
mov ah,1
int 21h
cmp al,'0'
jb rt0
cmp al,'9'
ja rt0
and ax,0Fh
xchg ax,[si]
mul bx
add ax,[si]
jc re0
xchg ax,[si]
jmp rd0
re0:
mov f,1
lea dx,msg2
mov ah,9
int 21h
rt0:
ret
read10 endp
;print (ax) in Hex
print proc near
mov bx,16
xor cx,cx
Q0:
xor dx,dx
div bx
or dx,0e00h
push dx
inc cx
cmp ax,0
jnz Q0
lea bx,t
Q1:
pop ax
xlat
int 10h
loop Q1
mov al,'H'
int 10h
ret
print endp
cseg ends
end start