專注電子技術(shù)學(xué)習(xí)與研究
當(dāng)前位置:單片機(jī)教程網(wǎng) >> MCU設(shè)計(jì)實(shí)例 >> 瀏覽文章

匯編:統(tǒng)計(jì)字符串內(nèi)各種字符的數(shù)目

作者:佚名   來源:本站原創(chuàng)   點(diǎn)擊數(shù):  更新時(shí)間:2013年12月01日   【字體:

;對這個(gè)題目進(jìn)一步改造:
;3_7 用戶輸入一個(gè)由數(shù)字‘0’~‘9’英文大寫字母‘A’~‘Z’;以及英文小寫字母‘a’~‘z’組成的ASCII 字符串,
;字符串的結(jié)束符為 CR(即回車符,其ASCII 碼為0DH),字符串總長度不超過256 個(gè)。
;要求統(tǒng)計(jì)傳送的字符總數(shù)以及其中各種字符的數(shù)目

DATA SEGMENT
  SUM     DB 00H  ;總數(shù)          計(jì)數(shù)器
  CAPITAL DB 00h  ;大寫字母個(gè)數(shù)  計(jì)數(shù)器
  small   db 00h  ;小寫字母個(gè)數(shù)  計(jì)數(shù)器
  num     db 00h  ;數(shù)字個(gè)數(shù)      計(jì)數(shù)器
  result  db 'The amout all of the zifu in this string is  ','$'
  result1 db 'The amout of the number in the string is ','$'
  result2 db 'The amout of the big capital is ','$'
  result3 db 'The amout of the small capital is ','$'
  string  db  256 dup (?)   ;保存輸入的字符
     kongzi  DB 0DH,0AH,'$'      ;換行使用
  buffer  DB 256 DUP(0)       ;目標(biāo)內(nèi)存
  results DB 256 DUP(?)        
  tital   db 'Please input the string you want to be done : ',0dh,0ah,'$'
  tip     db 'Do you want to have a try again (if yes: "y" ,else "n"): ','$'
  tip1    db 'welcome to use the program again ,the original is WQ ','$'
DATA ENDS
CODE SEGMENT
 ASSUME CS:CODE,DS:DATA
START: MOV AX,DATA
       MOV DS,AX 
    lea dx,tital
       mov ah,09h
       int 21h    
       mov di,0
again:
       mov  ah,01h
       int  21h
       mov string[di],al
       inc di
       cmp al,0dh
       jnz again
       cld         ;將方向標(biāo)志位置零   串操作遞增
main: lods string  ;字符串裝入指令 把字符串一個(gè)個(gè)裝入al
      INC SUM     
   CMP AL,0DH
   JE DONE
      CMP AL,30H
      Jb main
      cmp al,41h
      jb k1 
   CMP AL,61H
   Jb k2 
   JMP main
DONE:
      lea dx,result    ;輸出SUM
      mov ah,09h
      int 21h
      DEC SUM         
   MOV AX,0
   MOV AL,SUM 
      MOV BL,10
   DIV BL
      MOV DX,AX
   ADD DX,3020H    ;為什么要加20呢?
   cmp dl,30h
   jnz wuling
   mov dl,20h
wuling:
      MOV AH,02h
      INT 21H
   MOV DL,DH       ;這是在干什么?
      MOV AH,2h       ;2號(hào)調(diào)用每次只輸出一個(gè)字符,即dl
   INT 21H   
   LEA DX,kongzi  ;換行
      MOV AH,09H
      INT 21H
              
           
 
     ;輸出num
    mov ax,0
    mov al,num
    mov bl,10
    div bl
    mov dx,ax
    add dx,3030h
    cmp dl,30h
    jne   wuling3
    mov dl,32
    wuling3:
    push dx
    lea dx,result1
    mov ah,09h
    int 21h
    pop dx
    mov ah,02h
    int 21h
    mov dl,dh
    mov ah,02h
    int 21h
    LEA DX,kongzi
       MOV AH,09H
       INT 21H
                            ;輸出CAPITAL
    MOV AX,0
    MOV AL,CAPITAL
    sub al,04h
    MOV BL,10
    DIV BL
    MOV DX,AX
    ADD DX,3030H
    CMP Dl,30H
    JNE WULING2
       MOV Dl,32
WULING2:push dx
        lea dx,result2
        mov ah,09h
        int 21h
        pop dx
        MOV AH,02h
     INT 21H
     MOV DL,DH
     MOV AH,2
     INT 21H
    
      mov al,sum
         sub al,capital
         add al,04h
         sub al,num
         mov small,al
                     
                    ;輸出small capital
    MOV AX,0
    MOV AL,small
    MOV BL,10
    DIV BL
    MOV DX,AX
    ADD DX,3020H
    CMP Dl,30H
    JNE WULING4
       MOV Dl,32    ;空格
 
WULING4: push dx
         LEA DX,kongzi
         MOV AH,09H
         INT 21H
         lea dx,result3
         mov ah,09h
         int 21h
         pop dx     
      
       
         MOV AH,02h
      INT 21H
      MOV DL,DH
      MOV AH,2
      INT 21H
    
     lea dx,kongzi
     mov ah,09h
     int 21h
     lea dx,tip
     mov ah,09h
     int 21h
     mov ah,01h
     int 21h
     cmp al,'y'
     je lop  
  
 lea dx,kongzi
 mov ah,09h
 int 21h  
        lea dx,tip1
     mov ah,09h
     int 21h   
over:
     MOV AH,4CH
     INT 21H
 k2:inc capital                              
    jmp main     
    k1: inc num
    jmp main
    lop:
    lea dx,kongzi
  mov ah,09h
  int 21h 
  jmp start
 
CODE ENDS
END START
 

關(guān)閉窗口

相關(guān)文章