Reputation: 225
The problem is that it does not jump at doi
even if dl
and bl
are equal. Anyone knows why?
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
Upvotes: 0
Views: 1116
Reputation: 4693
This compares implicit-length 0-terminated strings. (Unlike the strings in the question that are either explicit length (with l1 equ $-sir1
but no special byte marking the end) or have a $
terminator.)
It also assumes ES = DS, or that the 2nd string is pointed to by ES:BP. (The question is using [BP]
for one of them, which is probably a mistake unless you're using a "tiny" code model where 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
Upvotes: 3