x86 assembly-masm32:无效的指令操作数

时间:2012-04-29 07:36:21

标签: assembly x86 masm

我正在尝试创建一个输入密码的密码文件,它会显示您的所有密码。我目前的代码是这样,但它有一个错误:

.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行,但我不明白错误是什么。

1 个答案:

答案 0 :(得分:3)

cmp用于compare two bytes/words/dwords, not strings。因此,您基本上要求它使用无效语法将buffer的前四个字节与comp 的四个字节进行比较。

要比较字符串,您需要使用cmps或手动循环。

此外,comp应声明为comp db '13243546', 0。现在你声明它的方式使它成为一个双字00CA149A,相当于C字符串"\x9A\x14\xCA" - 输入相当复杂:)

相关问题