cmpstr.asm

来自「一个汇编编译器很好用的」· 汇编 代码 · 共 87 行

ASM
87
字号
;演示程序
;此程序比较数据段和附加段的两串字符串string1和string2是否相等
;若相等,显示“string1 match string2”,否则显示“the two strings are nomatch”

; -----------定义数据段

DSEG    SEGMENT 'DATA'

      string1 db "I am a student."                               ;字符串一

      match db " string1 match string2",13,10,'$'
      nomatch db "the two strings are nomatch",13,10,'$'
      quit db "press any key to exit......",13,10,'$'
DSEG    ENDS


; -----------附加段

eseg   segment
       string2 db "I am a student."                              ;字符串二
eseg ends

;-----------定义代码段
CSEG    SEGMENT 'CODE'

;*******************************************

START   PROC    FAR
     assume cs:cseg,ds:dseg,es:eseg

;--------------保存返回DOS的地址
    PUSH    DS
    MOV     AX, 0
    PUSH    AX

;------------设置段寄存器
    MOV     AX, DSEG
    MOV     DS, AX
    mov     ax,eseg
    MOV     ES, AX
 

    lea si,string1
    lea di,string2
    mov cx,15
    cld
    repe cmpsb

    cmp cx,0
    jz mat
;-----------两字符串不等
    mov ah,9
    lea dx,nomatch
    int 21h
    jmp waitforexit

;-----------两字符串相等
mat:
    mov ah,9
    lea dx,match
    int 21h

;-----------按任意键退出
waitforexit: 
    mov ah,9
    lea dx,quit
    int 21h

     mov ah,1
     int 21h
   

    



;----------- 返回DOS

  exit:  RET
START   ENDP

;*******************************************

CSEG    ENDS

        END    START    ; set entry point.

⌨️ 快捷键说明

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