本文主要是介绍统计并输出数字、大写字母、小写字母,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
内存自source开始有20个数字、大写字母、小写字母的混合串(比如:1234567890abceFGHIJ)
编程将其中的数字符号挑选出来存储到dst开始的内存中,并将结果显示到CRT上。
data segmentsource db "1234567890abceFGHIJ"dst db 20 dup(?)
data ends code segmentassume cs:code,ds:data,es:data
start:mov ax, datamov ds, axnum:mov si, offset sourcemov di, offset dsts1:mov al, [si]cmp al, 30hjb next1cmp al, 39hja next1mov [di], alinc dinext1:inc sicmp si, offset dstjb s1mov byte ptr[di], '$'mov dx, offset dstmov ah, 9int 21hexit:mov ah, 4chint 21hcode endsend start
扩展A:做一个菜单,选1,2,3,4分别输出数字、大写、小写及退出
扩展B:同时输出数字、大写、小写的个数
data segmentmenu db "1 print num", 0dh, 0ah ;定义打印菜单db "2 print upper case", 0dh, 0ahdb "3 print lower case", 0dh, 0ahdb "4 exit", 0dh, 0ah, '$' ;0dh回车,0ah换行choice db "please choice 1 2 3 4: ", 0dh,0ah,'$'NumOut db 0dh, 0ah,"The number of Num is :$"UpperOut db 0dh, 0ah,"The number of Upper is :$"LowerOut db 0dh, 0ah,"The number of Lower is :$"source db "1234567890abcdeFGHIJ"count equ $-source ;count为混合串长度dst db 20 dup(?) ;dst内存开始存放结果Nonum db 0 ;统计数字的个数Noupper db 0 ;统计大写字母的个数Nolower db 0 ;统计小写字母的个数
data endscode segmentassume cs:code, ds:data, es:data
start:mov ax, data ;将数据段地址装入段寄存器mov ds, axmov Nonum,0mov Noupper,0mov Nolower,0mov dx, offset menu ;调用9功能打印字符串mov ah, 9int 21hmov dx, offset choicemov ah, 9int 21hmov ah, 8 ;调用8功能,输入int 21hcmp al, '1'jz numcmp al, '2'jz upcmp al, '3'jz low1jmp exit
;选出数字符号并显示
num:mov bx, offset sourcemov si, offset dst ;si存放结果,从dst开始存放mov cl, count
next1:mov al, [bx]cmp al, 30h ;大于39h小于30h不是数字跳转到l1jb l1cmp al, 39hja l1mov [si], aladd Nonum, 1inc si
l1:inc bxdec cljnz next1mov dx,offset NumOutmov ah,9int 21hmov al,NonumCALL B_TO_D16 ;调用子程序打印统计个数jmp dsp
;选出大写字母符号并显示
up:mov bx, offset sourcemov si, offset dstmov cl, count
next2:mov al, [bx]cmp al, 41hjb l2cmp al, 5ahja l2mov [si], aladd Noupper, 1inc si
l2:inc bxdec cljnz next2mov dx,offset UpperOutmov ah,9int 21hmov al,NoupperCALL B_TO_D16 jmp dsp
;选出小写字母符号并显示
low1:mov bx, offset sourcemov si, offset dstmov cl, count
next3:mov al, [bx]cmp al, 61hjb l3cmp al, 7ahja l3mov [si], aladd Nolower, 1inc si
l3:inc bxdec cljnz next3mov dx,offset LowerOutmov ah,9int 21hmov al, NolowerCALL B_TO_D16
dsp: mov byte ptr[si],'$' ;输出si的内容mov dl,0ahmov ah,2int 21hmov dl,0dhmov ah,2int 21hmov dx,offset dstmov ah,9int 21hjmp start
B_TO_D16 PROC NEAR;16位二进制转十进制子程序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 ENDP
exit:mov ah, 4cHint 21Hcode endsend start
这篇关于统计并输出数字、大写字母、小写字母的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!