刚学汇编~~问个小问题
刚学汇编 都还不怎么会~~~下面是我写的 就是判断字符串是否匹配 是则输出“match”否则就是“nomatch”但是结果总是“no match”啊
data segment
string1 db 'abc '
string2 db 'abc '
match db 'match$ '
nomatch db 'no match$ '
data ends
code segment
assume cs:code,ds:data
start:
mov ax,data
mov ds,ax
mov bx,offset string1
mov si,offset string2
mov cx,string2-string1
begin:
mov al,[bx]
cmp al,[si]
inc bx
inc si
jnz next
loop begin
;-----------输出match-----------------
mov ah,9
mov dx,seg match
mov ds,dx
mov dx,offset match
int 21h
;-----------输出no match------------
next:
mov ah,9
mov dx,seg nomatch
mov ds,dx
mov dx,offset nomatch
int 21h
mov ax, 4c00h
int 21h
code ends
end start
[解决办法]
data segment
string1 db 'abc '
string2 db 'abc '
match db 'match$ '
nomatch db 'no match$ '
data ends
code segment
assume cs:code,ds:data
start:
mov ax,data
mov ds,ax
mov bx,offset string1
mov si,offset string2
mov cx,string2-string1
begin:
mov al,[bx]
cmp al,[si]
jnz next ;条件转移应该紧接于cmp指令之后
inc bx
inc si
;jnz next
loop begin
;-----------输出match-----------------
mov ah,9
mov dx,seg match
mov ds,dx
mov dx,offset match
int 21h
jmp short exit ;缺少此条指令,则程序还会顺序向下执行
;-----------输出no match------------
next:
mov ah,9
mov dx,seg nomatch
mov ds,dx
mov dx,offset nomatch
int 21h
exit: mov ax, 4c00h ;添加个标号exit
int 21h
code ends
end start
[解决办法]
帮你该了一下,把他复制一下就可运行
data segment
string1 db 'abc '
string2 db 'abc '
match db 'match$ '
nomatch db 'no match$ '
data ends
code segment
assume cs:code,ds:data,es:data ;用字符串指令,须用到附加数据段
start:
mov ax,data
mov ds,ax
mov es,ax
lea si,string1
lea di,string2
mov cx,3
repe cmpsb
jnz next
;-----------输出match-----------------
mov ah,9
mov dx,offset match
int 21h
jmp exit
;-----------输出no match------------
next:
mov ah,9
mov dx,offset nomatch
int 21h
exit:
mov ax, 4c00h
int 21h
code ends
end start