DATAS SEGMENT
BUFFERA DB 32
The DB 0
The DB 32 DUP (0)
BUFFERB DB 32
The DB 0
The DB 32 DUP (0)
PROMPTSTRINGA DB 'input A string:' ah, 0 0 dh, '$'
PROMPTSTRINGB DB 'input string B:' ah, 0 0 dh, '$'
PROMPTSTRINGENTER DB ah 0, 0 dh, '$'
FOUNDSTRING DB 'FOUND IT, 0 ah, 0 dh,' $'
NOTFOUNDSTRING DB 'NOT FOUND IT, ah, 0 0 dh,' $'
Flag the db?
DATAS ends
CODES SEGMENT
ASSUME CS: CODES, DS: DATAS
START:
Mov AX, DATAS
Mov DS, AX
MOV DX, OFFSET PROMPTSTRINGA; Print the input prompt
MOV AH, 09 h
INT 21 h
MOV DX, SEG BUFFERA; The input string 1
MOV DS, DX
MOV DX, OFFSET BUFFERA; Output to the input string
MOV AH, AH 0
INT 21 h
MOV DX, OFFSET PROMPTSTRINGENTER; Carriage returns
MOV AH, 09 h
INT 21 h
MOV DX, OFFSET PROMPTSTRINGB; Print the input prompt
MOV AH, 09 h
INT 21 h
MOV DX, SEG BUFFERB; The input string 2
MOV ES, DX
MOV DX, OFFSET BUFFERB; Print string 2
MOV AH, AH 0
INT 21 h
MOV DX, OFFSET PROMPTSTRINGENTER; Carriage returns
MOV AH, 09 h
INT 21 h
Mov BX, offset PROMPTSTRINGA
Mov AX, offset PROMPTSTRINGB
Dec AX
While1:; While1 judgment string 2 initials equals the which initials string 1
Mov si, AX; Si store target string 1 offset
Mov di, BX. Di deposit with judge string 2 offset
Inc si
Inc AX
Cx, xor cx
Mov ch, [si]; Ch store strings one character at a time of 1
Mov cl (di); Cl store 2 a character in the string
CMP ch, 0
Jz flag0; Determine whether they have been for the last one character at a time, if is the jump
CMP ch, cl
JNZ while1
While2:; While2 judgment string 2 letters with the rest of the string of 1 the rest of the letters are equal
Inc di
Inc si
Inc dx; Si di on the judge the rest of the characters
Cx, xor cx
Mov ch, [si]; Ch store strings one character at a time of 1
Mov cl (di); Cl store 2 a character in the string
CMP cl, 0
Jz flag1; String has been equal to the last character shows 2
CMP ch, 0; 1 is the last a string
Jz flag0
CMP ch, cl
Jz while2; If two character equality continues to cycle a character
JNZ while1; Cycle range is 1
Flag0:
MOV DX, OFFSET NOTFOUNDSTRING
MOV AH, 09 h
INT 21 h
JMP ENDPRO; End program
Flag1:
MOV DX, OFFSET FOUNDSTRING; Output found
MOV AH, 09 h
INT 21 h
JMP ENDPRO; End program
ENDPRO: MOV AX, 4 c00h
INT 21 h
CODES ends
The end START
Why can't this always show not found, display the found? Comparison of the code is from https://www.cnblogs.com/roseAT/p/10250320.html,
CodePudding user response:
While1: front face ax and the setting of bx, set on the prompt string, it should be there in the input string BUERRA/B; Secondly, comparative method, whether can you first look at the two string length, if not the same, need not better than, as continued but end of the string rather than 00 0 dh (input) caused by the function,CodePudding user response:
I'm sorry, the back of the above is part of the idea is wrong, want to set up a string is the same, compared the requirements of the question is the comparison of the substring,CodePudding user response: