Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7652569
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T11:48:17+00:00 2026-05-31T11:48:17+00:00

I need to program the Ackermann function. This is what I have so far:

  • 0

I need to program the Ackermann function. This is what I have so far:

    .model small
;
    extrn   putstrng:far
    extrn   newline:far
    extrn   getdec$:far
    extrn   putdec$:far
; 
;
    .stack 1024                  
;
    .const


    .data

    .code
    assume ds:dgroup
;
debut:  mov     ax, seg dgroup     
    mov     ds, ax
    mov     es, ax
;

    mov     ax,2   ; value of N
    mov     bx,ax
    mov     ax,2 ; Value of M
    mov     dx,ax
    mov     cx,0

    push    dx
    push    bx

    call ackermann

    pop     bx
    pop     dx

    MOV ax, 0
    MOV ax, cx
call    putdec$
call    newline


    mov     ax, 4c00h          
    int     21h

ackermann   proc far C uses cx

    mov dx, [bp+6] 
    mov bx, [bp+4]
    cmp bx, 0
    JE firstCase
    cmp dx, 0
    JE secondCase
    dec dx
    push dx
    push bx
    CALL ackermann
    pop bx
    pop dx
    dec bx
    push dx
    push bx
    CALL ackermann
    pop bx
    pop dx
    ret


firstCase:
    MOV cx, dx
    inc cx
    ret


secondCase:
    DEC bx
    push dx
    push bx
    call ackermann
    pop bx
    pop dx
    ret

ackermann endp

    end     debut

Whatever I put for the value of N or M, i always get the answer 0. I think I know why. This part :

MOV ax, 0
MOV ax, cx
call    putdec$
call    newline

is probably wrong, but I don’t know what to do with it.

Any help will be greatly appreciated.

Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T11:48:19+00:00Added an answer on May 31, 2026 at 11:48 am

    Assuming that your Ackermann function actually works and leaves its result in the cx register, and that putdec$ prints the value in the ax register, there’s absolutely nothing wrong with that code segment you’ve shown.

    It needlessly loads zero into ax first but then replaces it with cx.

    Hence your problem lies with one of:

    • putdec$ does not print ax.
    • your Ackermann function does not work as you expect.
    • your Ackermann function does not return its value in cx.

    Fist step is to fire up your debugger and set a breakpoint at the mov ax, 0 instruction – this will tell you what value is in cx (and other registers) to check whether the Ackermann function is working.

    Then you may need to go back and single-step through the function, comparing it to what you expect to happen at each stage with some paper and pencils.


    With a bit of static code analysis, and a quick investigation into what this Ackermann function actually is meant to do 🙂 , I can discern the following:

    One thing I’m not sure you have right (if you’re using the Wikipedia definition of the Ackermann function here) is the second case. It states that:

             /  n + 1             if m = 0
    A(m,n) = |  A(m-1,1)          if m > 0 and n = 0
             \  A(m-1,A(m,n-1))   if m > 0 and n > 0
    

    Your second case code decrements bx/m as expected but leaves dx/n alone, rather than setting it to one.

    In your third case (though I haven’t looked closely) you do call the function twice but nowehere can I see a transfer of cx, the result of the first, inner A() call, to either one of the registers pushed onto the stack for the outer call. This would be a vital step in calculating a nested function like A(x,A(y,z)).

    Instead, your outer call seems to use some variation of the original values.

    Those two helpful pointers should be a good start for you, to hone your debugging skills and become a better developer 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a program written for text simplification in python language, I need this
In my program I need to programmatically configure an ApplicationContext. Specifically, I have a
I have an WPF application. The problem: need program(daemon, service) that send signals by
for a third party application I need to program a Com Server. This is
I need launch program in remote desktop, this program open a window and need
I have a program and I am catching an error. I need the program
I have years of C++ programming experience in Windows. Now I need to program
I cannot get this to work properly, I need the program to list through
I need my program to create and edit a config file, which would contain
I need my program to see different colors. Pretty much all I need is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.