输入以$结尾的字符串,统计并输出非数字字符的个数
程序运行:
代码:
datas segmentstring db 100h dup(?)nonNumberCount dw 0inputPrompt db 'input string and end by $:'inputPromptLen dw $-inputPromptoutputNonnumberCount db 0dh,0ah,'output nonnumber 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,axlea si,inputPrompt ;输出输入提示mov ah,2mov cx,inputPromptLen ;输出输入提示的字符串长度 s2: mov dl,[si]int 21h ;输出提示字符inc siloop s2mov ah,1 ;输入设置mov bx,0 ;记录输入有效的字符个数s:int 21hcmp al,'$' ;以'$'结束输入je breakcmp al,'0' ;判断字符是否大于'0'jb nonNumber ;若小于'0',则计数器加1cmp al,'9' ;判断字符是否大于'9'ja nonNumber ;若大于'9',则计数器加1jmp s1nonNumber: ;非数字字符,计数器加1inc bxs1:jmp sbreak: mov nonNumberCount,bx ;保存计数器lea dx,outputNonnumberCount ;输出计数器提示mov ah,9int 21hmov ax,nonNumberCount call print ;输出计数器retmain endpprint proc nearmov cx,0mov bx,10sprint:mov dx,0div bxpush dxinc cxcmp ax,0 jne sprintsprint1:pop dxadd dl,30h ;加30h,转成数字字符mov ah,2int 21hloop sprint1retprint endp
codes endsend main