匯編程序:比較2個字符串是否相同(初級版)
source1 db 50 dup(?) ; 存放第一個串
source2 db 50 dup(?) ; 存放第二個串
title1 db Please input the first string:,0dh,0ah,$
title2 db Please input the second string:,0dh,0ah,$
ans db match,0dh,0ah,$
ans1 db no match,0dh,0ah,$
DATAS ENDS
STACKS SEGMENT
STACKS ENDS
CODES SEGMENT
ASSUME CS:CODES,DS:DATAS,SS:STACKS
START:
MOV AX,DATAS
MOV DS,AX
mov dx,offset title1;輸出抬頭
mov ah,09h ;輸出字符串用09
int 21h
mov cl,50
mov si,0
again:
mov ah,01h
int 21h
cmp al,0dh
jz two
mov source1[si],al
inc si
dec cl
jnz again ;將第一個串搞定
two:
mov dx,offset title2;輸出第二個抬頭
mov ah,09h
int 21h
mov cl,50
mov si,0
again1:
mov ah,01h
int 21h
cmp al,0dh
jz main
mov source2[si],al
inc si
dec cl
jnz again1;這里以上部分是給兩個字符串賦值,一下部分是比較。
main:
mov si,0
mov cx,6
again2:mov al,source2[si]
cmp source1[si],al
jnz nomatch
incsi
dec cx
jnz again2
cmpcx,0
jz match
nomatch:mov dx,offset ans1
mov ah,09h
int 21h
jmp over
match: mov dx,offset ans
mov ah,09h
int 21h
over: MOV AH,4CH
INT 21H
CODES ENDS
END START
; MADE BY WQ
這里是完善版的程序:http://www.51hei.com/mcu/2469.html
評論