回 帖 发 新 帖 刷新版面

主题:求助:从键盘输入一系以$结束符的字符串,然后对其中的非数字字符计数,并显示结果.

从键盘输入一系$结束符的字符串,然后对其中的非数字字符计数,并显示结果. 

请高手给个完整的答案,能在机器上运行通过的,我是新手,初学者! 谢谢!

回复列表 (共1个回复)

沙发


DATA SEGMENT
   msg db 'plese input some letters and numbers.',0ah,0dh 
       db '$'
   msg1 db 'the number of letters is:'
      l db ?,0ah,0dh,'$'
   msg2 db 'the number of numbers is:'
      d db ?,0ah,0dh,'$'
   buf  db 80
    db ?
        db 80 dup(?)
DATA ENDS
;;
;
;;
CODE SEGMENT
    ASSUME CS:CODE,DS:DATA
START:  MOV AX,DATA
    MOV DS,AX  
        lea dx,msg      ;输出提示信息
        mov ah,09h
        int 21h
           lea dx,buf
        mov ah,0ah      ;输入字符,且最后一个为$
        int 21h
        mov dl,0ah
        mov ah,02h
        int 21h
        mov bx,0
        mov cx,0
        lea si,buf+2

 comper:cmp byte ptr[si],30h       ;<1跳转
        jb error
        cmp byte ptr[si],39h
        ja ndt1                    ;>9跳转
        inc cx    
        jmp error
   ndt1:cmp byte ptr[si],'A'
        jb error
        cmp byte ptr[si],'Z'
        ja ndt2
        inc bx
        jmp error
   ndt2:cmp byte ptr[si],'a'
        jb error
        cmp byte ptr[si],'z'
        ja error
        inc bx
  error:inc si
        cmp byte ptr[si],'$'      ;为'$'结束
        jne comper               
        add bl,30h
        mov l ,bl
        mov dx,offset msg1       ;输出
        mov ah,09h
        int 21h
        add cl,30h
        mov d ,cl
        mov dx,offset msg2
        mov ah,09h
        int 21h
         
        mov ah,4ch
        int 21h
   code ends
         end start
    
    
很好的答案 啊
不过比你要求的 多点功能啊

我来回复

您尚未登录,请登录后再回复。点此登录或注册