2012-04-29 55 views
-1

我正在嘗試創建一個密碼文件,輸入密碼並顯示所有密碼。我當前的代碼是這樣的,但它有一個錯誤:x86彙編-masm32:無效的指令操作數

.386 
.model flat,stdcall 
option casemap:none 

include  \masm32\include\windows.inc 
include  \masm32\include\kernel32.inc 
include  \masm32\include\masm32.inc 
includelib \masm32\lib\kernel32.lib 
includelib \masm32\lib\masm32.lib 

.data 
     input db 'Enter the password:',13,10,0 
     string db 'The passwords are:',0 
     space db '  ',0 
     pass1 db 'example password 1',0 
     pass2 db 'example password 2',0 
     pass3 db 'example password 3',0 
     pass4 db 'example password 4',0 
     ermsg db 'Incorrect Password. Exiting....',0 
     count dd 0 
      comp dd 13243546 

.data? 
     buffer db 100 dup(?) 
.code 
start: 
_top: 
     invoke StdOut,ADDR input 
     invoke StdIn,ADDR buffer,100 ; receive text input 
     cmp buffer, comp ;sorry for not pointing this out - this is line 32 
     jz _next 
     jmp _error 
_next: 
     invoke StdOut, ADDR string 
     invoke StdOut, ADDR space 
     invoke StdOut, ADDR pass1 
     invoke StdOut, ADDR pass2 
     invoke StdOut, ADDR pass3 
     invoke StdOut, ADDR pass4 
     invoke ExitProcess,0 
_error: 
     invoke StdOut, ADDR ermsg 
     mov eax, 1 
      mov count, eax 
      cmp count, 3 
      jz _exit 
      jmp _top: 
_exit: 
      invoke ExitProcess, 0 

這是錯誤:

test.asm(32) : error a2070: invalid instruction operands 

爲什麼這種情況發生。我明白錯誤在第32行,但我不明白錯誤是什麼。

+0

'cmp buffer,comp' - 你想在這裏做什麼? – DCoder 2012-04-29 07:40:50

+0

@Soohjun - 我編輯帖子以顯示第32行 – Progrmr 2012-04-29 08:14:34

+0

@DCoder - 我試圖比較緩衝區與comp,換句話說,比較緩衝區到13243546(這將是查看存儲在程序中的其他密碼所需的密碼) – Progrmr 2012-04-29 08:15:38

回答

3

cmp用於compare two bytes/words/dwords, not strings。所以你基本上要求它將buffer的前四個字節與comp的四個字節進行比較,使用無效的語法來完成此操作。

要比較字符串,您需要使用cmps或手動循環。

此外,comp應宣佈爲comp db '13243546', 0。你現在宣佈它的方式使它成爲一個dword 00CA149A,這相當於C字符串"\x9A\x14\xCA" - 類型相當複雜:)

+0

啊,我明白了....所以當我從'緩衝區'獲得輸入時,它是以字符串格式。所以我需要聲明'comp'作爲一個字符串來匹配。謝謝。 – Progrmr 2012-04-29 09:44:58