一、从键盘输入一字符,判断该字符是小写字母、大写字母、数字或其它字符。若输入为小写字母,显示“You Input a Lowercase Letter!”;若输入为大写字母,显示“YouInput a Uppercase Letter!”;若输入为数字,显示“You Input a Digit!”;若输入为其它字符,显示“You Input Other Letter!”。
data segment
infor1 db 0ah,0dh,"Please Press Any Key to input a letter:$"
infor2 db 0ah,0dh,"You Input a Lowercase Letter!$"
infor3 db 0ah,0dh,"You Input a Uppercase Letter!$"
infor4 db 0ah,0dh,"You Input a Digit!$"
infor5 db 0ah,0dh,"You Input a Other Letter!$"
data ends
code segment
assume cs:code,ds:data
start:
mov ax,data
mov ds,ax
mov dx,offset infor1
mov ah,09h
int 21h
mov ah,01h
int 21h
cmp al,'0'
jb other
cmp al,'9'
jbe digit
cmp al,'A'
jb other
cmp al,'Z'
jbe upper
cmp al,'a'
jb other
cmp al,'z'
jbe lower
jmp pend
lower: mov dx,offset infor2
mov ah,09h
int 21h
jmp pend
upper: mov dx,offset infor3
mov ah,09h
int 21h
jmp pend
digit: mov dx,offset infor4
mov ah,09h
int 21h
jmp pend
other: mov dx,offset infor5
mov ah,09h
int 21h
jmp pend
pend: mov ah,4ch
int 21h
code ends
end start
二、键盘接收三位数字,输出年龄提示信息并判断年龄段输出字符串提示信息。(0~39: young 40~69: middle-age 70~199: long life 200+: Are You Kidding me?) 当输入‘esc’时程序退出。
data segment
infor1 db 0ah,0dh,"Please Input Your Age(<1000[example:065])and Press 'Esc' to exit!:$"
infor2 db 0ah,0dh,"Your age is:$"
infor3 db 0ah,0dh,"You are young!$"
infor4 db 0ah,0dh,"You are middle-age!$"
infor5 db 0ah,0dh,"You are an old man!$"
infor6 db 0ah,0dh,"Are you kidding me? Do you know PengZu?$"
infor7 db 0ah,0dh,"Congratulations,You are a long life!$"
age db 0,0,0
data ends
code segment
assume cs:code,ds:data
start:
mov ax,data
mov ds,ax
input:
mov dx,offset infor1
mov ah,09h
int 21h
mov bx,offset age
mov ah,01h
int 21h
mov [bx],al
cmp al,27
jz exit
mov bx,offset age
mov cx,2
mov di,0
save:
inc di
mov ah,01h
int 21h
mov [bx+di],al
loop save
mov dx,offset infor2
mov ah,09h
int 21h
mov bx,offset age
mov cx,3
mov di,0
read: mov al,[bx+di]
inc di
mov dl,al
mov ah,02h
int 21h
loop read
cmp [bx],byte ptr 31h
jz cong
cmp [bx],byte ptr 32h
jae jonk
cmp [bx+1],byte ptr 34h
jb young
cmp [bx+1],byte ptr 37h
jb mid
cmp [bx+1],byte ptr 37h
jae old
jmp input
young:
mov dx,offset infor3
mov ah,09h
int 21h
jmp input
mid:
mov dx,offset infor4
mov ah,09h
int 21h
jmp input
old:
mov dx,offset infor5
mov ah,09h
int 21h
jmp input
jonk:
mov dx,offset infor6
mov ah,09h
int 21h
jmp input
cong:
mov dx,offset infor7
mov ah,09h
int 21h
jmp input
exit:
mov ah,4ch
int 21h
code ends
end start
在Ubuntu下DOSBox运行结果显示:
三、在屏幕上显示信息“Are you really want to exit?”,然后从键盘输入一个字符,若输入“Y”或“y”,显示“Thank you for your using!”后程序结束;若输入“N”或“n”,显示“Let’s continue!”后程序结束;若输入其它字符,显示“You press an error key!”后程序结束
data segment
infor1 db 0ah,0dh,"Are you really want to exit?$"
infor2 db 0ah,0dh,"Thank you for your using!$"
infor3 db 0ah,0dh,"Let's continue!$"
infor4 db 0ah,0dh,"You press an error key!$"
data ends
code segment
assume cs:code,ds:data
start:
mov ax,data
mov ds,ax
mov dx,offset infor1
mov ah,09h
int 21h
mov ah,01h
int 21h
cmp al,'Y'
jz exit
cmp al,'y'
jz exit
cmp al,'N'
jz continue
cmp al,'n'
jz continue
mov dx,offset infor4
mov ah,09h
int 21h
jmp pend
exit:
mov dx,offset infor2
mov ah,09h
int 21h
jmp pend
continue:
mov dx,offset infor3
mov ah,09h
int 21h
jmp pend
pend:
mov ah,4ch
int 21h
code ends
end start
四、
在屏幕上显示如下信息:
1------------------------Panda
2------------------------Cat
3------------------------Rabbit
4------------------------Pig
5------------------------EXIT
(Please choose 1,2,3,4or 5)-----
若输入1,显示“I like panda”后程序结束;若输入2,显示“I like cat”后程序结束;若输入3,显示“I like rabbit”后程序结束;若输入4,显示“I don’t like pig”后程序结束;若输入5,程序直接结束;若输入其它字符,显示“You press an error key!”后程序结束
data segment
infor1 db 0ah,0dh,"1--------------------Panada$"
infor2 db 0ah,0dh,"2--------------------Cat$"
infor3 db 0ah,0dh,"3--------------------Rabbit$"
infor4 db 0ah,0dh,"4--------------------Pig$"
infor5 db 0ah,0dh,"5--------------------EXIT$"
infor6 db 0ah,0dh,"(Please choose 1,2,3,4or5)---$"
infor7 db 0ah,0dh,"I like Panada $"
infor8 db 0ah,0dh,"I like Cat $"
infor9 db 0ah,0dh,"I like Rabbit $"
infor10 db 0ah,0dh,"I don't like Pig $"
infor11 db 0ah,0dh,"You press an error key! $"
data ends
code segment
assume cs:code,ds:data
start:
mov ax,data
mov ds,ax
mov dx,offset infor1
mov ah,09h
int 21h
mov dx,offset infor2
mov ah,09h
int 21h
mov dx,offset infor3
mov ah,09h
int 21h
mov dx,offset infor4
mov ah,09h
int 21h
mov dx,offset infor5
mov ah,09h
int 21h
mov dx,offset infor6
mov ah,09h
int 21h
mov ah,1
int 21h
cmp al,'1'
jz panada
cmp al,'2'
jz cat
cmp al,'3'
jz ribbit
cmp al,'4'
jz pig
cmp al,'5'
jmp pend
panada:
mov dx,offset infor7
mov ah,09h
int 21h
jmp pend
cat:
mov dx,offset infor8
mov ah,09h
int 21h
jmp pend
ribbit:
mov dx,offset infor9
mov ah,09h
int 21h
jmp pend
pig:
mov dx,offset infor10
mov ah,09h
int 21h
jmp pend
error:
mov dx,offset infor11
mov ah,09h
int 21h
jmp pend
pend: mov ah,4ch
int 21h
code ends
end start