x86 汇编中的递归 Ackermann-Peter 函数 (NASM)
我正在尝试在 x86 NASM-Assembly 中实现递归 Ackermann-Peter-Function。该函数定义如下:
*a(0;m) = m + 1
*a(n + 1; 0) = a(n; 1)
*a(n + 1;m + 1)) = a(n ; a(n + 1;m))
我的问题是我什至无法想象如何正确开始。到目前为止,我只在汇编中递归地实现了“x 的幂”函数。
这是我到目前为止所拥有的: http://pastebin.com/rsWALyCq (德语提示只要求 n 和 m)
我感谢每一位我可以通过这个获得帮助。
--
所以我现在将推送/弹出语句设为对称,但仍然出现分段错误。我尝试调试整个事情并在第一个案例中放置了一条调试消息。我编译了该程序并使用 n=0 和 m=0 进行了尝试,但他没有打印调试消息,因此他甚至没有输入第一种情况。我似乎无法找出他为什么不这样做。
这是我目前的尝试: http://pastebin.com/D4jg7JGV
im trying to implement the recursive Ackermann-Peter-Function in x86 NASM-Assembly. The Function is defined as follows:
*a(0;m) = m + 1
*a(n + 1; 0) = a(n; 1)
*a(n + 1;m + 1)) = a(n; a(n + 1;m))
My Problem is i can't even imagine how to start properly. By now i only implemented an "power of x" Function recursively in Assembly.
Here is what i have so far:
http://pastebin.com/rsWALyCq (The german prompts just ask for n and m)
Im thankfull for every bit of help i can get with this one.
--
SO i made the push/pop Statements Symetric now, but still get an Segmentation fault. I tried to debug the whole thing and placed a Debug-Message inside the firstcase. I compiled the Program and tried it with n=0 and m=0 and hes not printing the Debug-Message, so he isnt even entering the firstcase. I can't seem to manage to find out why hes not doing it.
Heres my current try:
http://pastebin.com/D4jg7JGV
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
解决方案:
好吧,我发现了问题:
我没有正确管理 ebp 和 esp。因此,我现在在每个函数调用中都使用了 ENTER 和 LEAVE 宏,现在整个事情都可以正常工作了。
这是解决方案。感谢您的宝贵时间:
完整代码:
http://pastebin.com/ZpPucpcs
SOLUTION:
Ok I found the problem:
I didn't manage the ebp and esp right. So, I now used the ENTER and LEAVE Macros in every function call and now the whole thing works properly.
Here is the Solution. Thank you for your time:
Full Code:
http://pastebin.com/ZpPucpcs
如果您可以递归地执行此操作(伴随所有随之而来的堆栈帧增长),那么这相当简单。基本思想,在子程序的代码中:
If you're ok with doing this recursively (with all the attendant stack frame growth), then this is fairly straightforward. The basic idea, in the code of the subroutine: