【发布时间】:2015-05-02 11:51:30
【问题描述】:
我需要将下一个伪代码翻译成汇编。只需读取数组中的 5 个数字并与最后一个值进行比较。参数很好。
伪代码:
tmp= not L0
tmp = not ( not tmp and not L1)
tmp= tmp or L2
tmp = not (not tmp or not L3)
tmp= tmp and L4
if(tmp == L5 )
valido
sino
invalido
这是我的“解决方案”:
EsLicenciaValida PROC licencia: dword
mov ebx, licencia
mov edx,[ebx]
mov ecx, edx
neg ecx
add ebx, 4
mov edx,[ebx]
not edx
not ecx
and ecx, edx
not ecx
add ebx, 4
mov edx,[ebx]
or ecx, edx
add ebx, 4
mov edx,[ebx]
not edx
not ecx
or ecx,edx
not ecx
add ebx, 4
mov edx,[ebx]
and ecx, edx
add ebx, 4
mov edx,[ebx]
cmp edx, ecx
jne invalido
valido:
mov eax, ecx
jmp salir
invalido:
mov eax, 0000h
salir:
ret
EsLicenciaValida ENDP
ECX 寄存器有伪代码的 tmp 值。 EBX 数组实际位置的值。
有人知道怎么了?谢谢大家=)
【问题讨论】:
-
您的问题是什么?你的代码没有达到你的预期吗?如果不是,有什么不同?
-
哦,对不起。在 cmp 值中,拒绝应该接受的值。例如,如果您插入一个具有十六进制值的数组:A-A-A-A-A-32 (50) 所有其他值的总和应该为 50,但不起作用,则使用无效值。
-
neg ecx是错误。五个“0Ah”(0x0A)的结果是 10d。这看起来像一个谜题。您应该找到总和为 50 的五个数字和“算法”为 32h。我没有测试这是否可以解决。
标签: visual-studio assembly x86 pseudocode