统计字符串

题目:计算字符串中字母、数字、其他字符的个数。

 

代码:

 

DATAS SEGMENT
    BUF DB 80
    LEN DB ?
    STRING DB 80 DUP(32)
    crlf db 13,10,'$'   
    displ DB 'The amount of letters is:',13,10,'$'
    dispd db 'The amount of digits is:',13,10,'$'
    dispo db 'The amount of others is:',13,10,'$'
    LETTER DB 0
    DIGIT DB 0
    OTHER DB 0
DATAS ENDS


STACKS SEGMENT
    DB 200 DUP (?)
STACKS ENDS


CODES SEGMENT
    ASSUME CS:CODES,DS:DATAS,SS:STACKS
START:
    MOV AX,DATAS
    MOV DS,AX
    call input
    call dispcrlf
    mov dx,offset string
    mov ah,09
    int 21h
    CALL TONGJI
    CALL RESULT
    MOV AH,4CH
    INT 21H
   
    input proc near;输入
        mov dx,offset buf
     mov ah,10
     int 21h
     ret
    input endp
   
    TONGJI PROC NEAR;统计
    LEA BX,STRING
    MOV CL,LEN
    LOOP1:
       MOV AL,[BX]
       CALL ISLETTER
       JNC NEXT
       INC LETTER
       JMP THE_END
       NEXT:
       CALL ISDIGIT
       JNC THE_END
       INC DIGIT
       THE_END:
       INC BX
       LOOP LOOP1
    ret
    TONGJI ENDP
   
    ISLETTER PROC NEAR
    CMP AL,'A'
    JB EXIT1
    CMP AL,'Z'
    JBE EXIT2
    CMP AL,'a'
    JB EXIT1
    CMP AL,'z'
    JBE EXIT2
    EXIT1:
     CLC
     RET
    EXIT2:
    STC
    RET
   ISLETTER ENDP
  
   ISDIGIT PROC NEAR
      CMP AL,'0'
      JB NOTD
      CMP AL,'9'
      JA NOTD
      STD
      RET
      NOTD:
      CLC
      RET
   ISDIGIT ENDP
  
   RESULT PROC NEAR
      mov dx,offset crlf
      mov ah,09h
      int 21h
      mov dx,offset displ;输出字母个数 
      mov ah,09
      int 21h
      mov bl,letter
      call out_amount
      call dispcrlf
      mov dx,offset dispd;输出数字个数
      mov ah,09
      int 21h
      mov bl,digit
      call out_amount
      call dispcrlf
      mov dx,offset dispo;输出其他字符个数
      mov ah,09
      int 21h
      mov bl,len
      sub bl,letter
      sub bl,digit
      call out_amount
      call dispcrlf
      ret
   RESULT ENDP
  
   dispcrlf proc near
      mov dx,offset crlf
      mov ah,09
      int 21h
      ret
   dispcrlf endp
  
   out_amount proc near
      ;要输出的数存储在bl中
      push ax
      push dx
      push cx
      mov cl,4
      mov al,bl
      shr al,cl
      mov dl,al
      and dl,0fh
      add dl,30h
      mov ah,02h
      int 21h
      mov dl,bl
      and dl,0fh
      add dl,30h
      mov ah,02h
      int 21h
      pop cx
      pop dx
      pop ax
      ret
   out_amount endp
  
CODES ENDS
    END START

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值