Click here to Skip to main content
15,879,844 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
windows32 assembly language recursive procedure.

accept, from the user, an integer greater than 0. Guard against invalid values being entered using a loop.
call the recurse sub-procedure using the cdecl protocol,
receive the results of the sub-procedure,
and display the results.
The recurse sub-procedure should (following the cdecl protocol):
recurse(0) = 3,
and recurse(n) = 5 * recurse(n-1) + 9, for n > 0.
return the value back to the calling procedure.

I did this task in C++ programming language but I am not familiar with assembly language I wanted to know how it can be done in assembly language.

What I have tried:

C++
#include <iostream>
using namespace std;

int recursion(int n);
int main()
{
    int n,result;
    cout<<"Enter the integer: ";
    cin>>n;
	
    result = recursion(n);
    cout<<result;
    return 0;
}

int recursion(int n){
    if(n>0){
        return 5 * recursion(n-1)+9;
    }
    else{
    	return 3;	
	}
}
Posted
Updated 20-Oct-21 11:06am
v2

Recursion is recursion: it doesn't matter what language you write it in, it's the same process.
All you need to do is write a subroutine (a label that you can CALL and which will hits a RETURN instruction at some point, and have it call itself just the same as in the C code.
The difference being that you have to preserve your stack and registers yourself.

Read your course notes, and it should all be pretty obvious.
 
Share this answer
 
v2
You can set compiler flags and get an assembly output.
If you also set the debug info flag, comments are also displayed.

The code would be greatly simplified if you use C instead of C ++ as the basis.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900