Wesam E.

asked • 11/01/22

Please change this c++ code into pep9

Take the following program and translate it into PEP/9 assembly language:

 

#include <iostream>

 

using namespace std;

 

int fib(int n)

{

int temp;

if (n <= 0)

  return 0;

else if (n <= 2)

  return 1;

else {

  temp = fib(n – 1);

  return temp + fib(n-2);

}

}

 

int main()

{

  int num;

  cout << "Which fibonacci number? ";

  cin >> num;

  cout << fib(num) << endl;

  return 0;

}

 

You must use equates to access the stack and follow the call to the function as discussed in the book (pass the parameter, return address, return a value and so on). There are NO global variables in the resulting code (except a global message of "Range num? "). It must be able to do a range greater than 2.

1 Expert Answer

By:

Darshan P. answered • 11/13/24

Tutor
New to Wyzant

A highly motivated and computer science engineer with a strong fo

Still looking for help? Get the right answer, fast.

Ask a question for free

Get a free answer to a quick problem.
Most questions answered within 4 hours.

OR

Find an Online Tutor Now

Choose an expert and meet online. No packages or subscriptions, pay only for the time you need.