输入一串字符串,分别统计英文字符,数字字符和其他字符的个数
程序运行:
代码:
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 ;对输入的一行字符进行统计mov cl,linexor ch,chmov si,1cmp cx,0 ;判断字符串的长度是否为0jz break ;若为0,跳转s:mov al,line[si]cmp al,'0' ;判断字符是否小于'0'jb other ;若小于'0',则字符为其他字符cmp al,'9' ;判断字符是否大于'9'ja letter_or_other ;若大于'9',则字符为字母或其他字符inc digit_count ;否则,字符为数字字符,数字记录器加1jmp next ;跳转letter_or_other:and al,11011111b ;将字符转为大写字符cmp al,'A' ;判断字符是否大于'A'jb other ;若小于,则字符是其他字符,跳转cmp al,'Z' ;判断字符是否大于'Z'ja other ;若大于,则字符为其他字符,跳转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