;--------------------------------------------------------------------
;name:top2o2.asm
;
;purpose:show the capital or lowercase letter,leader letter and
; the follow-up letter which based on the letter given by user
;--------------------------------------------------------------------
assume cs:code,ds:data
data segment
out1 db 'please input a letter:','$'
out2 db 'the capital/lowercase letter is:','$'
out3 db 'the leader letter is:','$'
out4 db 'the follow-up letter is:','$'
out5 db 'press ESC to exit,or any other key to continue!','$'
c db 0
c1 db 0
leader db 0
followup db 0
data ends
code segment
start:mov ax,data
mov ds,ax
s:
lea dx,out1
mov ah,09
int 21h
mov ah,01
int 21h
mov ds:[c],al
mov dl,0dh ;换行
mov ah,02
int 21h
mov dl,0ah
mov ah,02
int 21h
mov bh,ds:[c]
cmp bh,27 ;如果是ESC键,退出循环
jz e1
jmp e2
e1:jmp e
e2:cmp bh,'a' ;判断是否大于'a'
jz s0 ;等于时跳转到s0执行另一个分支
cmp bh,'a' ;
jnc s3 ;大于'a'时跳转到s1判断是否小于'z'
jmp s0 ;不符合条件时跳转到s0
s3:cmp bh,'z' ;判断是否小于'z'
jc s1 ;小于'z'时跳转到s1
jmp s0
s1:sub bh,32 ;符合条件则说明c为小写字母,求它的大写字母
mov ds:[c1],bh
jmp s2 ;不执行另一分支,直接执行条件分支后面的语句
s0:cmp bh,'A' ;判断是否大于'A'
jz s ;等于'A'时跳转到s3
cmp bh,'A' ;继续判断是否小于'Z'
jnc s4 ;大于'Z'则跳转到s3判断是否小于
jmp s
s4:cmp bh,'Z' ;判断是否小于'Z'
jc s5 ;小于'Z'则跳转到s5处,求小写字母
jmp s
s5:add bh,32 ;求c的小写字母
mov ds:[c1],bh
s2:
mov bh,ds:[c]
mov ds:[leader],bh
mov ds:[followup],bh
sub byte ptr ds:[leader],1 ;求c的前导字母
add byte ptr ds:[followup],1 ;求c的后续字母
lea dx,out2
mov ah,09
int 21h
mov dl,ds:[c1] ;输出大写/小写字母
mov ah,02
int 21h
mov dl,0dh ;换行
mov ah,02
int 21h
mov dl,0ah
mov ah,02
int 21h
lea dx,out3
mov ah,09
int 21h
mov dl,ds:[leader] ;输出前导字母
mov ah,02
int 21h
mov dl,0dh ;换行
mov ah,02
int 21h
mov dl,0ah
mov ah,02
int 21h
lea dx,out4
mov ah,09
int 21h
mov dl,ds:[followup] ;输出后续字母
mov ah,02
int 21h
mov dl,0dh ;换行
mov ah,02
int 21h
mov dl,0ah
mov ah,02
int 21h
lea dx,out5
mov ah,09
int 21h
mov dl,0dh ;换行
mov ah,02
int 21h
mov dl,0ah
mov ah,02
int 21h
mov dl,0dh ;换行
mov ah,02
int 21h
mov dl,0ah
mov ah,02
int 21h
jmp s
e:mov ax,4c00h
int 21h
code ends
end start