所以我有一个程序,应该识别一个单词(s1)是否是另一个单词(s2)的变位词。但我一直得到错误A2070:第15行、第34行和第36行的指令操作数无效。我已经查找了错误,但似乎无法找到解决方案或理解它。
我所尝试的就是将指定行的movzx改为mov,但这会导致程序抛出异常。如果程序正常运行,它应该将eax中的值从0改为1。
.386
.model flat,stdcall
.stack 4096
ExitProcess proto,dwExitCode:dword
.data
s1 byte "GARDEN"
s2 byte "DANGER"
c1 byte 26 dup(0) ;counter for each letter in s1
c2 byte 26 dup(0) ;counter for each letter in s2
.code
main proc
mov eax, 0 ;we will assume that we do not have an anagram
movzx ebx, lengthof s1 ;(1) iterate lengthof s1 times
mov esi, 0 ;start at the first byte of s1 and s2
CounterLoop: ;this will increment the proper 'elements' of c1 and c2
movzx edi, s1[esi] ;move the value from s1 into edi
inc c1[edi - 65] ;(2) increment the counter at the value - 65.
;subtract 65 because the ASCII value of A is 65, B is 66, C is 67...
;when you subtract 65 then the sum of all the As will be stored in 'index' 0
;Bs in 'index' 1, Cs in 'index' 2...
movzx edi, s2[esi] ;(3) Do the same procedure for s2
inc c2[edi - 65] ;(4) increment the second counter at the value - 65.
inc esi ;increment esi
loop CounterLoop ;after this loop terminates our couter arrays will have the proper values
movzx esi, 0 ;(5) start checking the counter arrays at 'index' 0
movzx ebx, lengthof c1 ;(6)iterate lengthof c1 times
VerifyLoop:
mov bl, c1 ;(7) move value of c1 into bl
cmp bl, c2 ;(8) check bl vs the value of c2
jmp NoAna ;(9) if they are not equal then we do not have an anagram. jump to NoAna
inc esi ;increment esi
loop VerifyLoop
mov eax, 1 ;if the loop terminates and we have not jumped then we know we have an anagram
NoAna:
invoke ExitProcess, 0
main endp
end main
1条答案
按热度按时间nwnhqdif1#
loop
指令依赖于ECX,而不是您设置的EBX。请改为写入mov ecx, LENGTHOF s1
。更好的是,不要使用慢速的
loop
指令,并将其写成:你的第二个循环可以使用相同的技巧来替换
loop VerifyLoop
。这个循环有一些额外的问题:jmp NoAna
必须成为条件跳转jne NoAna
。inc esi
当前没有任何用途,因为您不用它来寻址 c1 和 c2 数组中的连续字节。