lab 4

Lab Description:

Lab 4 was also challenging because i had to go pull out all the C++ notes to be able to do this lab. we had to convert all the previous programs that we wrote in HLA into a C++ or C program. Also find our assembly program. i was able to write and run the program. When i Look at the program in both languages, it really hard to see the similarities at first because it looks really packed and kinda messy. The assembly program looks very very long. it is about 500 lines.But when i looked closely at the commands used, i can see certain commands that i became familiar with such as “jmp”, “call”. i can also observe that a lot of different labels have been created. The command “string” is seen to be used many times. But many others commands and lines that i really have no real ideas what they mean or there for such as “uleb128”, “movl”, “testb”, “setne” and many others.

Code:

#include 
using namespace std;

int main()
{
	int x, y, z, i;

cout<<"Enter 1 to add: \n";
cout<<"Enter 2 to subtract: \n";
cout<<"Enter 3 to multiply: \n";
cout<<"Enter 4 to exponentiate: \n";
cout<<"Enter 5 to convert to roman numerals: \n"; cin>>x;

switch(x)
{
	case 1:

			cout<<"Enter number 1: "; 			cin>>x;
			if(x>65536)
			{	
				cout<<"This number is too large.\n";
				break;
			}
				else
				cout<<"Enter number 2: \n"; 			cin>>y;
			z=x+y;
			cout<<"The answer is "<<z<<endl;
			break;

	case 2:

			cout<<"Enter number 1: "; 			cin>>x;
			if(x>65536)
			{	
				cout<<"This number is too large.\n";
				break;
			}
				else
				cout<<"Enter number 2: \n"; 			cin>>y;
			z=x-y;
			cout<<"The answer is "<<z<<endl;
			break;

	case 3:

			cout<<"Enter number 1: "; 			cin>>x;
			if(x>65536)
			{	
				cout<<"This number is too large.\n";
				break;
			}
				else
				cout<<"Enter number 2: \n"; 			cin>>y;
			z=x*y;
			cout<<"The answer is "<<z<<endl;
			break;

	case 4:
			cout<<"Enter number 1: "; 			cin>>x;
			if(x>65536)
			{	
				cout<<"This number is too large.\n";
				break;
			}
				else
				cout<<"Enter number 2: \n"; 			cin>>y;
			for(i=y;i>0;y--)
			{
				z=x*x;
			}

			cout<<"The answer is "<<z<<endl;
			break;

	case 5:

			cout<<"Enter a decimal number or Enter 0 to exit.\n";   			cin>>x;

 			 while(x!=0)
			{
        			while(x!=0)
				{
  					if(x>=1000) 
     					{
						cout<<"M";       						x=x-1000; 					} 					else if(x>=900) 
     					{
						cout<<"CM";       						x=x-900; 					} 					else if(x>=500) 
     					{
						cout<<"D";       						x=x-500; 					} 					else if(x>=400) 
     					{
						cout<<"CD";       						x=x-400; 					} 					else if(x>=100) 
     					{
						cout<<"C";       						x=x-100; 					} 					else if(x>=90) 
     					{
						cout<<"XC";       						x=x-90; 					} 					else if(x>=50) 
     					{
						cout<<"L";       						x=x-50; 					} 					else if(x>=40) 
     					{
						cout<<"XL";       						x=x-40; 					} 					else if(x>=10) 
     					{
						cout<<"X";       						x=x-10; 					} 					else if(x>=9) 
     					{
						cout<<"IX";       						x=x-9; 					} 					else if(x>=5) 
     					{
						cout<<"V";       						x=x-5; 					} 					else if(x>=4) 
     					{
						cout<<"IV";       						x=x-4; 					} 					else if(x>=1) 
     					{
						cout<<"I";
      						x=x-1;
					}
			}

				}
		}
}

Leave a Reply

Your email address will not be published. Required fields are marked *