Assembly collatz猜想程序中的堆芯转储
我想在汇编中实现Collatz猜想。它的算法应该计算在EAX值变为1之前需要多少步。但我有一个问题,当我试图执行时,控制台显示“内核转储”或冻结。我在EBX中存储了步数。我通过Assembly collatz猜想程序中的堆芯转储,assembly,Assembly,我想在汇编中实现Collatz猜想。它的算法应该计算在EAX值变为1之前需要多少步。但我有一个问题,当我试图执行时,控制台显示“内核转储”或冻结。我在EBX中存储了步数。我通过push eaxcallfpop eax在程序的主要部分调用此函数 f: mov eax, [esp+4] cmp eax,1 je end AND eax, 0x01 jz parity inc ebx imul eax,3 inc eax parity: inc ebx shr
push eax
callf
pop eax
在程序的主要部分调用此函数
f:
mov eax, [esp+4]
cmp eax,1
je end
AND eax, 0x01
jz parity
inc ebx
imul eax,3
inc eax
parity:
inc ebx
shr eax,1
jmp f
end:
mov eax,ebx
ret
请帮忙
更新
解决了
f:
mov eax, [esp+4]
mov ebx, 1 ;In case EAX=1 !!!
jjump:
cmp eax,1
je end
test eax, 0x01
jz parity
inc ebx
imul eax,3
inc eax
jmp jjump
parity:
inc ebx
shr eax,1
jmp jjump
end:
mov eax,ebx
ret
你写了一个无休止的循环。如果[esp+4]处的值不是1,则始终跳回标签f并重新读取相同的值 把标签贴在这里:
f:
mov eax, [esp+4]
f_:
您可能应该测试eax,1
而不是和
,因为后者会破坏您想要继续使用的值
这两种可能性都必须跳转到额外的标签jjump
整个代码变成:
f:
mov eax, [esp+4]
mov ebx, 1 ;In case EAX=1 !!!
jjump:
cmp eax,1
je end
test eax, 0x01
jz parity
inc ebx
imul eax,3
inc eax
jmp jjump
parity:
inc ebx
shr eax,1
jmp jjump
end:
mov eax,ebx
ret
谢谢你的回复,我改了。在moveax之后,[esp+4]我添加了跳跃:现在它在那里跳跃。但该计划仍然冻结。我想我不能移动标签f:因为它是我的函数,我在主程序中通过调用f来调用它
f:
mov eax, [esp+4]
mov ebx, 1 ;In case EAX=1 !!!
jjump:
cmp eax,1
je end
test eax, 0x01
jz parity
inc ebx
imul eax,3
inc eax
jmp jjump
parity:
inc ebx
shr eax,1
jmp jjump
end:
mov eax,ebx
ret