本文主要是介绍小写转大写输出,并统计数字、大写字母、小写字母的个数,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
键盘输入数字、大写字母、小写字母的混合串(以回车结束,100个以内),
将其中的小写字母转换为大写字母后显示到CRT上
data segmentmess db "please input", 0dh,0ah,'$'buf db 101 db ?db 101 dup (0)
data endscode segmentassume cs:code,ds:data,es:data
start:mov ax, datamov ds, axmov dx, offset messmov ah, 9int 21hmov dx, offset bufmov ah, 10int 21hmov dl,0ahmov ah,2int 21hmov dl,0dhmov ah,2int 21hmov bx, offset buf+2mov cl, buf+1s:cmp cl, 0jz printdec clmov al, [bx]cmp al, 30hjb okcmp al, 3Ahjb numcmp al, 41hjb okcmp al, 5Bhjb capcmp al, 61hjb okcmp al, 7Bhjb low_ok:inc bxjmp snum:jmp okcap:jmp oklow_:sub byte ptr [bx], 20hjmp okprint:mov byte ptr [bx], '$'mov dx, offset buf+2mov ah, 9int 21hmov ah, 4chint 21hcode ends
end start
扩展:并统计其中其中数字、大写字母、小写字母的的个数,显示出来
data segmentmess db "pelease input a string: ", 0dh, 0ah, '$'Num db 0dh, 0ah,"THE NNMBER OF NUM IS :$"Cap db 0dh, 0ah,"THE NNMBER OF CAP IS :$"Lower db 0dh, 0ah,"THE NNMBER OF LOWER IS :$"x1 db 0 ;统计数字个数x2 db 0 ;统计大写祖母个数x3 db 0 ;统计小写字母个数buf db 100db ?db 100 dup(0)data ends
code segmentassume cs:code, ds:data, es:data
start:mov ax, datamov ds, axmov dx, offset messmov ah, 9int 21hmov dx, offset bufmov ah, 10int 21hmov dl,0ahmov ah,2int 21hmov dl,0dhmov ah,2int 21hmov bx, offset buf+2mov cl,buf+1lop:mov al, [bx]cmp al, 61h jb next1;如果不是小写字母跳转到next1cmp al, 7ahja next1sub al, 20h ;小写字母Ascii码减20得到大写字母mov dl, almov ah,2 ;调用2功能输出int 21hinc x3 ;小写字母个数加1jmp l
next1:cmp al, 41h ;41h-Ajb next2 ;al < 41h;如果不是大写字母就跳转到next2cmp al, 5ah ;5ah-Zja next2 ;al > 5ahinc x2 ;大写字母个数加1jmp l
next2:inc x1 ;数字个数加1
l:inc bxdec cljnz lop;不等于0继续mov dx, offset Nummov ah, 9int 21h;输出统计个数mov al,x1call B_TO_D16 ;调用子程序输出数字串mov dx, offset Capmov ah, 9int 21hmov al,x2call B_TO_D16 ;调用子程序输出大写字母串mov dx, offset Lowermov ah, 9int 21hmov al,x3call B_TO_D16jmp exit;16位二进制转十进制子程序
B_TO_D16 PROC NEAR;AL中要转换的二进制数AND AH,0 ;ah存放余数,初始化为0MOV BL,100DIV BL ;ax/100得到百位数,存放al中MOV CL,AH ;余数暂存于cl中ADD AL,30H ;输出百位数MOV DL,ALMOV AH,02HINT 21HMOV AL,CL MOV BL,10AND AH,0DIV BL ;ax/10得到十位数ADD AL,30H ;输出十位数MOV DL,ALMOV CL,AHMOV AH,02HINT 21HMOV AL,CL ;输出个位数ADD AL,30HMOV DL,ALMOV AH,02HINT 21HRET
B_TO_D16 ENDPexit:mov ah, 4chint 21h
code endsend start
这篇关于小写转大写输出,并统计数字、大写字母、小写字母的个数的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!