任意长度字符串小写字母转大写

assume cs:codesg

datasg segment
	db 'Beginnner`s All-purpose Symbolic Instruction Code.',0
datasg ends

codesg segment
	begin: 	mov ax,datasg
			mov ds,ax
			mov si,0
			;转换前回显字符串
			call showstr
			
			;执行转换函数
			call letterc
			
			 ;换行
     		mov dl, 10
    		MOV  AH,6
     		INT  21H
     		mov dl, 13
     		MOV  AH,6
    		INT  21H

			;转换后回显字符串
			call showstr
			
			mov ax,4c00h
			int 21h
			
;把小写字母转换为大小字母的函数
letterc:
			;保存现场	
			push ax
			push cx
			push si
	
	start:	;判断读取到的字符是否为0
			;若为0就跳转到返回功能块
			mov ch,0
			mov cl,[si]
			jcxz endfunc
			
			;若不是0就继续
			;判断读取到的字符是否为小写字符
			mov al,61h
			cmp cl,al
			jb continue	;如果ASCII码小于97(a)跳过转换步骤继续遍历字符串 
			mov al,7ah
			cmp cl,al
			ja continue ;如果ASCII码大于122(z)跳过转换步骤继续遍历字符串
			
			;如果经历这么多困难还执行到这一步,那么呵呵,你就肯定要变大咯!!
			and cl,11011111b
			mov [si],cl
			
	continue:	
			inc si
			jmp short start
	
	endfunc:
			;函数结束恢复现场
			pop si
			pop cx
			pop ax
			ret
			
;回显ds:[si]中的字符串,以0作为结束标志
showstr:   
			;保存现场
			push ax
			push cx
			push si
			;判断读取到的字符是否为0
			;若为0就跳转到返回功能块
strbegin:	mov ch,0
			mov cl,[si]
			jcxz strend
     		mov dl, [si]
    	 	MOV  AH,02
     		INT  21H
     		INC si
     		loop strbegin
strend:    	
			;恢复现场
			pop si
			pop cx
			pop ax
			ret
			
			
	
codesg ends
end begin

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值