装配jmp没有跳跃

时间:2013-01-03 09:30:10

标签: assembly x86 dos x86-16

问题是即使doidl相等,它也不会跳到bl。谁知道为什么?

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

1 个答案:

答案 0 :(得分: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