汇编语言(二十)之分类统计字符个数
生活随笔
收集整理的這篇文章主要介紹了
汇编语言(二十)之分类统计字符个数
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
輸入一串字符串,分別統(tǒng)計(jì)英文字符,數(shù)字字符和其他字符的個數(shù)
程序運(yùn)行:
?
代碼:
datas segmentline_max_length db 0ffhline db 0, 100h dup(?)letter_count dw 0digit_count dw 0other_count dw 0input db 'input a line:$'output_letter_count db 0dh,0ah,'letter count:$'output_digit_count db 0dh,0ah,'digit count:$'output_other_count db 0dh,0ah,'other count:$'datas endsstacks segment stackdb 100h dup(?)stacks endscodes segmentassume cs:codes,ds:datas,ss:stacks main proc far start:push dsmov ax,0hpush axmov ax,datas ;初始化dsmov ds,ax;輸入一行字符提示lea dx,inputmov ah,9int 21h;輸入一行字符lea dx,line_max_lengthmov ah,10 int 21h ;對輸入的一行字符進(jìn)行統(tǒng)計(jì)mov cl,linexor ch,chmov si,1cmp cx,0 ;判斷字符串的長度是否為0jz break ;若為0,跳轉(zhuǎn)s:mov al,line[si]cmp al,'0' ;判斷字符是否小于'0'jb other ;若小于'0',則字符為其他字符cmp al,'9' ;判斷字符是否大于'9'ja letter_or_other ;若大于'9',則字符為字母或其他字符inc digit_count ;否則,字符為數(shù)字字符,數(shù)字記錄器加1jmp next ;跳轉(zhuǎn)letter_or_other:and al,11011111b ;將字符轉(zhuǎn)為大寫字符cmp al,'A' ;判斷字符是否大于'A'jb other ;若小于,則字符是其他字符,跳轉(zhuǎn)cmp al,'Z' ;判斷字符是否大于'Z'ja other ;若大于,則字符為其他字符,跳轉(zhuǎn)inc letter_count ;否則,字符為字母字符,字母記錄器加1jmp nextother:inc other_count ;字符為其他字符,其他記錄器加1 next:inc siloop sbreak: ;輸出記錄器的值lea dx,output_letter_countmov ah,9int 21h mov ax,letter_countcall decimallea dx,output_digit_countmov ah,9int 21hmov ax,digit_countcall decimallea dx,output_other_countmov ah,9int 21hmov ax,other_countcall decimalretmain endpdecimal proc near push axpush cx push dxpush bx cmp ax,0jge no_negative mov bx,ax mov dl,'-'mov ah,2 int 21h neg bx mov ax,bx no_negative:mov cx,0mov bx,10 de:xor dx,dx div bx push dx inc cxcmp ax,0 jnz de de1:pop dxadd dl,30hmov ah,2 int 21hloop de1 pop bx pop dx pop cx pop ax ret decimal endp codes endsend main?
總結(jié)
以上是生活随笔為你收集整理的汇编语言(二十)之分类统计字符个数的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 更新固态硬盘不想换系统怎样更换固态硬盘不
- 下一篇: 汇编语言(二十一)之数值交换与自增