2013-10-19 121 views
0

如何實現這樣的事情:.IF比較字符串MASM

abc db "abc",0 
def db "def",0 
textnotequal db "strings are not equal",0 
textequal db "strings are equal",0 

.if abc != def 
    invoke MessageBox, NULL, addr textnotequal, addr textnotequal, MB_OK 

.elseif abc == def 
    invoke MessageBox, NULL, addr textequal, addr textequal, MB_OK 
.endif 

我需要MOV ABC &高清弄成第一或者是這通常是不可能的?

+0

'abc'和'def'是指向字符串的指針,而不是字符串本身。通過比較它們,你可以比較不同的內存地址,除非它們指向的地方不同,即使它們指向的字符串是相同的。爲了比較字符串,您必須訪問這些地址,並在每個字節之間逐字節地進行更深的比較,以瞭解字符串是否相等。你可能需要爲此寫一個函數。 – Havenard

+0

的確,我在下面使用簡單的repempmpb行來編寫了一個這樣的函數的例子來進行更深入的比較。 –

回答

0

您可以在彙編中編寫cmpstr函數的版本。例如:

abc db "abc",0 
def db "def",0 
... 
mov ecx,3  #the length of the abc and def strings 
cld   #set the direction flag so that EDI and ESI will increase using repe 
mov esi, offset [abc] #moves address of abc string into esi 
mov edi, offset [def] #exact syntax may differ depending on assembler you use 
         #I am not exactly sure what MASM accepts but certainly something similar to this 
repe cmpsb  #repeat compare [esi] with [edi] until ecx!=0 and current chars in strings match 
       #edi and esi increase for each repetition, so pointing to the next char 
cmp ecx,0  #test if the above command passed until the end of strings 
je strings_are_equal #if yes then strings are equal 
# here print the message that strings are not equal (i.e. invoke MessageBox) 
jmp end 
strings_not_equal: 
# here print the message that strings are equal (i.e. invoke MessageBox) 
end: 
+0

最終使用'lstrcmpi'和'.if eax == FALSE',但是這絕對讓我朝着正確的方向前進,謝謝。 :) –