1.从键盘输入一字符,判断该字符是小写字母、大写字母、数字或其它字符。若输入为小写字母,显示“You Input a Lowercase Letter!“;若输入为大写字母,显示“You Input 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 Other Letter!$"
data ends
code segment
assume cs:code,ds:data
START:
;输出字符串信息宏定义
OUTINF MACRO INFOR
MOV DX,OFFSET INFOR
MOV AH,09H
INT 21H
ENDM
MOV AX,DATA
MOV DS,AX
OUTINF INFOR1
MOV AH,01H
INT 21H
CMP AL,'0'
JB OTHER ;jump below(<)
CMP AL,'9'
JBE DIGIT ;jump below or equal(≤)
CMP AL,'A'
JB OTHER
CMP AL,'Z'
JBE UPPER
CMP AL,'a'
JB OTHER
CMP AL,'z'
JBE LOWER
JMP OTHER
LOWER:
OUTINF INFOR2 ;宏调用
JMP PEND
UPPER:
OUTINF INFOR3
JMP PEND
DIGIT:
OUTINF INFOR4
JMP PEND
OTHER:
OUTINF INFOR5
JMP PEND
PEND:
MOV AH,4CH
INT 21H
code ends
end start
2.在屏幕上显示信息“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:
OUTINF MACRO INFOR
MOV DX,OFFSET INFOR
MOV AH,09H
INT 21H
ENDM
MOV AX,DATA
MOV DS,AX
OUTINF INFOR1 ;Are you really want to exit?
MOV AH,01H
INT 21H
CMP AL,'Y'
JZ EXIT ;jump if zero,即零标志(ZF)为1就跳转,一般与cmp连用,用以判断两数是否相等
CMP AL,'y' ;je=jump if equal,jz和je的作用是完全一样的
JZ EXIT
CMP AL,'N'
JZ CONTINUE
CMP AL,'n'
JZ CONTINUE
JMP OTHER
EXIT:
OUTINF INFOR2 ;Thank you for your using!
JMP PEND
CONTINUE:
OUTINF INFOR3 ;Let's continue!
JMP PEND
OTHER:
OUTINF INFOR4 ;You press an error key!
JMP PEND
PEND:
MOV AH,4CH
INT 21H
code ends
end start
3.在屏幕上显示如下信息:
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
INFOR0 DB 0AH,0DH,"1--------------------PANADA"
DB 0AH,0DH,"2--------------------CAT"
DB 0AH,0DH,"3--------------------RABBIT"
DB 0AH,0DH,"4--------------------PIG"
DB 0AH,0DH,"5--------------------EXIT"
DB 0AH,0DH,"(PLEASE CHOOSE 1,2,3,4OR5)---$"
INFOR1 DB 0AH,0DH,"I like panada $"
INFOR2 DB 0AH,0DH,"I like cat $"
INFOR3 DB 0AH,0DH,"I like rabbit $"
INFOR4 DB 0AH,0DH,"I don't like pig $"
INFOR5 DB 0AH,0DH,"You press an error key! $"
data ends
code segment
assume cs:code,ds:data
START:
OUTINF MACRO INFOR
MOV DX,OFFSET INFOR
MOV AH,09H
INT 21H
ENDM
MOV AX,DATA
MOV DS,AX
OUTINF INFOR0
MOV AH,01H
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'
JZ PEND
JMP OTHER
PANADA: ;1
OUTINF INFOR1
JMP PEND
CAT: ;2
OUTINF INFOR2
JMP PEND
RIBBIT: ;3
OUTINF INFOR3
JMP PEND
PIG: ;4
OUTINF INFOR4
JMP PEND
OTHER: ;输入错误
OUTINF INFOR5
JMP PEND
PEND: ;5
MOV AH,4CH
INT 21H
code ends
end start