[匯編] 比較2個字符串是否相等


 

 1 ; multi-segment executable file template.
 2 
 3 data segment
 4     STRING DB 'SPACE EXPLORERS INC'
 5     PRLINE DB 'SPACE EXPLORERS INCE'
 6     LAST   DB ' '  
 7     same   DB 'MATCH$'
 8     nsame  DB 'NO MATCH$'
 9 ends
10 
11 stack segment
12     dw   128  dup(0)
13 ends
14 
15 code segment
16 start:
17 ; set segment registers:
18     mov ax, data
19     mov ds, ax
20     mov es, ax
21 
22     ; add your code here 
23     mov cx,PRLINE-STRING        ;先判斷長度,長度不相等直接不匹配
24     cmp cx,LAST-PRLINE
25     jnz NEQUAL
26      
27     lea si,STRING               ;長度相等則逐個匹配
28     mov di,offset PRLINE
29     cld
30     rep cmpsb
31     jz  EQUAL
32     jnz NEQUAL
33     
34     EQUAL:                      ;輸出結果
35     lea dx,same 
36     jmp NEXT 
37     NEQUAL:
38     lea dx,nsame
39     NEXT:
40     mov ah, 9
41     int 21h        ; output string at ds:dx
42     
43     ; wait for any key....    
44     mov ah, 1
45     int 21h
46     
47     mov ax, 4c00h ; exit to operating system.
48     int 21h    
49 ends
50 
51 end start ; set entry point and stop the assembler.

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM