21,453
社区成员
发帖
与我相关
我的任务
分享
;*******************************************************************
data segment
error_msg db 'Your input is not correct!','$'
data ends
;-------------------------------------------------------------------
stack segment para stack 'stack'
db 20 dup(?)
stack ends
;*******************************************************************
code segment
;-------------------------------------------------------------------
main proc far
assume cs:code , ds:data , ss:stack
start:
mov ax , data
mov ds , ax
mov ax , stack
mov ss , ax
mov sp , 20
mov dx , offset input_first
mov ah , 9h
int 21h
mov ah , 01h
int 21h
call check_if_right
jmp exit
check_if_right:
cmp al , '0'
jb error_delect
cmp al , '9'
jbe right
cmp al , 'A'
jb error_delect
cmp al , 'F'
jbe right
cmp al , 'a'
jb error_delect
cmp al , 'f'
ja error_delect
right:
ret
error_delect:
mov dx , offset error_msg
mov ah , 9h
int 21h
jmp exit
exit:
mov ax , 4c00h
int 21h
main endp
;-------------------------------------------------------------------
code ends
;*******************************************************************
end start
;*******************************************************************
data segment
error_msg db 'Your input is not correct!','$'
input_first db 'Input the first digit :',13,10,'$'
data ends
;-------------------------------------------------------------------
stack segment para stack 'stack'
db 128 dup(?)
stack ends
;*******************************************************************
code segment
;-------------------------------------------------------------------
main proc far
assume cs:code , ds:data , ss:stack
mov ax , data
mov ds , ax
;原文的栈设置不需要,因为系统会自动设置
;mov ax , stack
;mov ss , ax
;mov sp , 20
;输出串
mov dx , offset input_first
mov ah , 9h
int 21h
;从键盘接收字符并回显
mov ah , 01h
int 21h
;调用子程序检查输出字符
call check_if_right
;jmp exit
exit:
mov ax , 4c00h
int 21h
main endp
;---------------------------------------------------------------------
;子程序 check_if_right
;检查al中是不是一个16进制ASCII数字
;---------------------------------------------------------------------
check_if_right PROC near
cmp al , '0'
jb error_delect
cmp al , '9'
jbe right
cmp al , 'A'
jb error_delect
cmp al , 'F'
jbe right
cmp al , 'a'
jb error_delect
cmp al , 'f'
jna right ;error_delect
error_delect:
mov dx , offset error_msg
mov ah , 9h
int 21h
jmp right ;exit
right:
ret
check_if_right endp
;-------------------------------------------------------------------
code ends
;*******************************************************************
end main