汇编语言(七)之字符串转大写
输入一串字符,将字符串的小写字母转成大写字母
程序运行:
代码:
datas segment
originalCaseMaxLength db 0ffh,0
originalCase db 100h dup(?)
uppercase db 100h dup(?)
inputPrompt db 'input a line of character:$'
outputoriginalCasePrompt db 0dh,0ah,'show noriginal characters:$'
outputUppercasePrompt db 0dh,0ah,'turn uppercase characters:$'
datas ends
stacks segment
db 100h dup(?)
stacks ends
codes segment
assume cs:codes,ds:datas,ss:stacks
main proc far
start:
push ds
mov ax,0h
push ax
mov ax,datas ;初始化ds
mov ds,ax
lea dx,inputPrompt ;输出输入提示
mov ah,9
int 21h
lea dx,originalCaseMaxLength
mov ah,10
int 21h
;输入并且转换小写字母成大写字
mov cl,originalCaseMaxLength+1 ;记录输入的字符个
mov ch,0
mov bx,0
s:
mov al,originalCase[bx]
cmp al,'a'
jae s1 ;如果al>='a',则跳转s1,判断是否al<='z'
jmp s3 ;否则跳s3,直接保存al于uppercase
s1:
cmp al,'z'
jbe s2 ;如果al<='z',则al转大写字
jmp s3 ;否则跳s3,直接保存al于uppercase
s2:
sub al,20h ;转大写字母
s3:
mov uppercase[bx],al ;保存al于uppercase
inc bx
loop s
break:
mov uppercase[bx+1],'$' ;设置输出字符
mov originalCase[bx+1],'$'
lea dx,outputoriginalCasePrompt ;输出原始字符提示
mov ah,9
int 21h
lea dx,originalCase ;输出原始字符
mov ah,9
int 21h
lea dx,outputUppercasePrompt ;输出转换字符串提示
mov ah,9
int 21h
lea dx,uppercase ;输出转换字符
mov ah,9
int 21h
ret
main endp
codes ends
end main