data segment
data_a db 'a' ;左边界标志
data_z db 'z' ;右边界标志
info db 'please input the right letter $' ;输入错误后提示信息
data ends
stack segment
stack ends
code segment
assume cs:code,ds:data,ss:stack
start:
mov ax,data
mov ds,ax
mov ah,01h ;调用系统输入单字符功能
int 21h
cmp al,data_a ;如果小于 'a' 则提示错误信息
jb error
cmp al,data_z ;如果大于 'z' 则提示错误信息
ja error
sub al,20h ;小写字母比大写字母的ascii值大20h
mov dl,al ;系统显示单字符功能缓冲区为dl
mov ah,02h ;调用dos的2号功能-显示指定单字符
int 21h
jmp exit ;退出,jmp为无条件转移指令
error:
mov ah,09h
mov dx,offset info ;求得错误提示信息的变量地址并用dx寄存器指定(09号功能显示的是dx指定数据的内容)
int 21h
jmp exit
exit:
mov ah,4ch ;退出
int 21h
code ends
end start
完善版:
data segment
data_a db 'a'
data_z db 'z'
data_space db '------$'
info db 'please input the right letter $'
data ends
stack segment
stack ends
code segment
assume cs:code,ds:data,ss:stack
start:
mov ax,data
mov ds,ax
mov ax,00h
mov ah,01h
int 21h
cmp al,data_a
jb error
cmp al,data_z
ja error
call space
sub al,20h
mov dl,al
mov ah,02h
int 21h
jmp exit
error:
call space
mov ah,09h
mov dx,offset info
int 21h
jmp exit
space:
mov ah,09h
mov dx,offset data_space
int 21h
ret
exit:
mov ah,4ch
int 21h
code ends
end start