⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 统计字符串出现次数.asm

📁 汇编语言实现的实现在字符串中查找指定的字母出现的次数,
💻 ASM
字号:
DSEG SEGMENT
A  DB  100,?,100 DUP(?)
B  DB  100,?,100 DUP(?)
CRLF   DB  13,10,'$'
DSEG   ENDS


CSEG SEGMENT
 MAIN  PROC   FAR	
    ASSUME CS:CSEG,DS:DSEG,ES:DSEG
START:
      PUSH     DS                ;save old data segment
      SUB      AX,AX             ;put zero in AX
      PUSH     AX    
    MOV AX,DSEG
    MOV DS,AX
    MOV ES,AX
    
    LEA DX,A
    MOV AH,0AH
    INT 21H 
    LEA DX,CRLF
    MOV AH,09H
    INT 21H
    
    LEA DX,B
    MOV AH,0AH
    INT 21H 
    LEA DX,CRLF
    MOV AH,09H
    INT 21H
    
          MOV  DL,0                        ;use DL to count,clean it
          MOV  CL,B[1]                  ;get length of string2
          CMP  CL,A[1]                  ;compare length of string1 and string2
          JA   EXIT                         ;if str1 is shorter,exit
          
          LEA  BX,A+2                   ;get addr of string1
AGAIN:    MOV  AL,[BX]                     ;move the char in BX to AL
          CMP  AL,0DH                      ;compare it to 0D,
          JZ   EXIT                         ;if equal,exit
          MOV  CL,B[1]                  ;get length of string2
          MOV SI,BX                         ;move addr of string1 to SI
          LEA  DI,B+2                    ;get addr of string2
          CLD
          REPZ CMPSB                       ;compare string1 and string2
          JNZ  NOTMATCH                  ;if not equal,notmatch
          INC  DL                           ;else,increase DL by 1
          
NOTMATCH: INC  BX                         ;get the next char of string1
          JMP  AGAIN                     ;loop again
EXIT:     ADD  DL,30H                      ;output the count
          MOV  AH,2
          INT  21H
          RET

MAIN ENDP   
CSEG  ENDS 
END   START 
     

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -