assemblyrecursionx86nasmackermann

Recursive Ackermann-Peter Function in x86 Assembly (NASM)


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


Solution

  • 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:

    asm_main:
        ENTER 0,0               ;setup Routine
        PUSHA
        MOV eax, prompt1        ;ask for n
    

    Full Code: http://pastebin.com/ZpPucpcs