很多錯誤,沒有改,給了註釋。;輸入一個字串 與已知字串比較,相等match 不等dismatchdata segmentstr_s db "apple"str_d db 30,?,30 dup(?)len_s dw $-str_s ;想儲存字串長度,不是這麼寫的len_d dw $-str_d ;使用EQUmess1 db "match$"mess2 db "mismatch$" ;dismatch寫成mismatch;資料段沒有結束符號;一個數據段即可,這個段用來幹嘛?extra segmentx db 100 dup(?)extra endscode segmentassume cs:code,ds:data,es:extramain proc farstart:mov ax,datamov ds,axmov ax,extramov es,axlea dx,str_dmov ah,0ahint 21hlea si,str_slea di,str_dcldmov cx,len_srepe cmpsbjz l1lea dx,mess2jmp l2L1:lea dx,mess1L2:mov ah,09hint 21hmov ax,4c00hint 21hmain endpcode endsend start修改後如下:;輸入一個字串 與已知字串比較,相等match 不等dismatchdata segmentstr_s db "apple"len_s equ $-str_sstr_d db 30,?,30 dup(?)mess1 db "match$"mess2 db "dismatch$"data endsCODE SEGMENTASSUME CS:CODE,DS:DATASTART:MOV AX,dataMOV DS,AXMOV ES,AX;輸入字串lea dx,str_dmov ah,0ahint 21h;比較字串長度是否一致XOR CX,CXMOV CL,str_d+1CMP CX,len_sJNE MS;比較字串中各元素是否一致LEA SI,str_sLEA DI,str_d+2MAD:MOV AL,DS:[SI]MOV BL,ES:[DI]CMP AL,BLJNE MSINC SIINC DILOOP MADLEA DX,mess1JMP SHORT SHOWMS:LEA DX,mess2SHOW:;輸出匹配結果資訊MOV AH,09HINT 21HMOV AH,4CHINT 21HCODE ENDSEND START
很多錯誤,沒有改,給了註釋。;輸入一個字串 與已知字串比較,相等match 不等dismatchdata segmentstr_s db "apple"str_d db 30,?,30 dup(?)len_s dw $-str_s ;想儲存字串長度,不是這麼寫的len_d dw $-str_d ;使用EQUmess1 db "match$"mess2 db "mismatch$" ;dismatch寫成mismatch;資料段沒有結束符號;一個數據段即可,這個段用來幹嘛?extra segmentx db 100 dup(?)extra endscode segmentassume cs:code,ds:data,es:extramain proc farstart:mov ax,datamov ds,axmov ax,extramov es,axlea dx,str_dmov ah,0ahint 21hlea si,str_slea di,str_dcldmov cx,len_srepe cmpsbjz l1lea dx,mess2jmp l2L1:lea dx,mess1L2:mov ah,09hint 21hmov ax,4c00hint 21hmain endpcode endsend start修改後如下:;輸入一個字串 與已知字串比較,相等match 不等dismatchdata segmentstr_s db "apple"len_s equ $-str_sstr_d db 30,?,30 dup(?)mess1 db "match$"mess2 db "dismatch$"data endsCODE SEGMENTASSUME CS:CODE,DS:DATASTART:MOV AX,dataMOV DS,AXMOV ES,AX;輸入字串lea dx,str_dmov ah,0ahint 21h;比較字串長度是否一致XOR CX,CXMOV CL,str_d+1CMP CX,len_sJNE MS;比較字串中各元素是否一致LEA SI,str_sLEA DI,str_d+2MAD:MOV AL,DS:[SI]MOV BL,ES:[DI]CMP AL,BLJNE MSINC SIINC DILOOP MADLEA DX,mess1JMP SHORT SHOWMS:LEA DX,mess2SHOW:;輸出匹配結果資訊MOV AH,09HINT 21HMOV AH,4CHINT 21HCODE ENDSEND START