0

doi问题是即使dlbl相等,它也不会跳跃。有谁知道为什么?

assume cs:code,ds:data
data segment
sir1 db "abc"
l1 equ $-sir1
sir2 db "a"
l2 equ $-sir2
bunbun db "Este!$"
nu db "NU este!$"
iesire db "Apasa Enter!$"

data ends

code segment
start:
    mov ax,data
    mov ds,ax

    mov bp,offset sir1
    mov si,offset sir2
    dec bp
    push bp
    push si
    mov ah,l1
    mov bh,l2

unu:
    pop si
    pop bp
    inc bp
    dec ah
    mov dl,sir1[bp]
    mov bl,sir2[si]
    push bp
    push si
    cmp dl,bl
    je doi
    cmp ah,0
    je nu_bun
    jmp unu

doi:
    inc si
    inc bp
    dec ah
    mov dl,sir1[bp]
    mov bl,sir2[si]
    cmp dl,bl
    jne unu
    cmp bh,0
    je bun
    jmp doi

bun:
    mov dx,offset bunbun
    mov ah,09h
    int 21h
    mov ah, 09h
    mov dx,offset iesire
    int 21h
    mov ah, 0ah
    int 21h
    mov ax,4c00h
    int 21h

nu_bun:
    mov dx,offset nu
    mov ah,09h
    int 21h
    mov ah, 09h
    mov dx,offset iesire
    int 21h
    mov ah, 0ah
    int 21h
    mov ax,4c00h
    int 21h

code ends
end start
4

1 回答 1

3

这比较隐式长度以 0 结尾的字符串。(与问题中的字符串不同,这些字符串要么是明确的长度(l1 equ $-sir1但没有特殊的字节标记结束),要么有一个$终止符。)

它还假设 ES = DS,或者第二个字符串由 ES:BP 指向。(问题是[BP]用于其中一个,除非您使用 DS = SS 的“微小”代码模型,否则这可能是一个错误。)

doi:
   ; cld             ; assume DF=0
    xchg di, bp
    mov cx, ax
    xor ax, ax

cmp_next:            ; do{
    lodsb              ; AL = [si]        ; si++
    scasb              ; cmp al, [es:di]  ; di++
    jnz not_equal
    test  al, al
    jnz   cmp_next   ; }while(al!=0);
   ; else fall through if we reached the end without finding a difference
do_equal:
    xchg di, bp
    mov ax, cx
    jmp somewhere_togo_when_equal

not_equal:
    xchg di, bp
    mov ax, cx
    jmp somewhere_togo_when_not_equal
于 2013-01-03T11:03:47.103 回答