Question

Exercise 1: For each of the following high-level language code snippets, write the SRO assembly code. Assume that the variabl

0 0
Add a comment Improve this question Transcribed image text
Answer #1

#include <iostream>

#include <stdio.h>

#include <string>

#include <stdlib.h>

#include <unistd.h> // From http://cs.dvc.edu/HowTo_CSleep.html

using namespace std;

class fibonnaci_series{

public:

fibonnaci_series(int x); // Construction

void push(int n); // Adds a new item to stack

unsigned int pop(); // remove the head guy (the most recently added item)

bool isEmpty(); // check if we have any item added.

void reverse(); // List all items of stack.

  

private:

unsigned*fib; // A pointer to show the head node

unsigned short size; // how many items stack has

};

fibonnaci_series:: fibonnaci_series(int x){

size = 0;

unsigned*fib = new unsigned int(x);

}

// add an item as the head one in the stack

void fibonnaci_series::push(int n)

{

if(n<=1){
  
fib[ size++ ] = n;
  
}
  
for(int i=2;i<=n;i++){
  
fib[i]= fib[i-1]+fib[i-2];
  
}
cout<<"size"<<size;

}

unsigned int fibonnaci_series::pop()

{

return fib[--size];

}

void fibonnaci_series::reverse()

{

while (size > 0)

cout << fib[--size] << ", ";

}

bool fibonnaci_series::isEmpty()

{

return size;

}

int main(int argc, const char * argv[]) {

fibonnaci_series S(30);

const int z[]={1,2,3};
int sizeOfArray=sizeof(z)/sizeof(z[0]);
cout << "Enter numbers:";

//cin >> z;

for (int j = 0; j < sizeOfArray; j++)

S.push(z[j]);
  
S.reverse();

}

Add a comment
Know the answer?
Add Answer to:
Exercise 1: For each of the following high-level language code snippets, write the SRO assembly code....
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT