我有這樣的宏:字符串比較失敗的兩個字符
compare macro string1, string2
local equal, notequal
mov eax, 1
mov ecx, 4
lea esi, offset string1
lea edi, offset string2
cld
repz cmpsb
je equal
jmp notequal
equal: mov eax, 0
notequal:
endm;
如果string1爲「A + B」 1和字符串爲「A + B」所有的偉大工程和EAX是0 也工作了「 AB「或」AxB「..
爲什麼這不適用於比較」AB「和」AB「?
PS。我使用MASM,我寧願不使用C/C++函數
以後編輯:
string1 db "AB"
operation db 6 dup(0)
其中操作字符串2,我用這個宏從鍵盤 閱讀:
read macro var, typee
push offset var
push offset typee
call scanf
add esp, 8
mov esi, eax
endm
其中var實際上是操作,typee是=>字符串db「%s」,0
我認爲你在比較四個字節。當你有三個字符加上終止''\ 0''時,所有四個字節都是相同的。當你有兩個字符加上''\ 0''時,你可能會發現自己的第四個字節沒有初始化,這通常會有所不同......你能確認「硬編碼」AB \ 0 \ 0工作嗎? – Floris
兩個'\ 0'的硬編碼絕對可行。 – Devolus
我剛剛添加了「稍後編輯」,如果string1將string1 db「AB \ 0 \ 0」和我a_file也將(從鍵盤)「AB \ 0 \ 0」它的工作..但我需要它使它只與AB – smotru