LAB -2

  32-bit Calculator Lab #2

LAB DESCRIPTION: Revisit of lab#1 with addition of Lab#2

For this laboratory you can use the vi editor to create a code-file. Be sure to end the documents name with “.hla” so that it can be compiled. The code must contain a addition function, subtraction function, multiplication function, exponentiation function, and an exit function. Also, the code must adapt for any value of 65536 (2^[16]) or above as it may overload the system. In addition, the multiplication function must be a loop function that adds numbers repetitively. Also, the coding must include a exponentiation calculator, and the exponentiation must work for any number raised to another. In addition you may not be able to use any hla function that computes the values using mul, div, or pow for the multiplication or exponentiation.

For LAB#2 we will add the Roman numeral converter, it is to use only what we have learned so far in terms of hla commands. For this lab the same conditions apply as above–we may not use mul, imul, pow, or any associated commands/keywords.

The required Roman numerals that we need to convert should be within these parameters

I = 1                 Special cases below
V = 5                   IV = 4
X = 10                 IX = 9
L = 50                  XL = 40
C = 100               XC = 90
D = 500               IC = 99
M = 1000            CD = 400
…                        XD = 490
…                        ID = 499
…                        CM = 900
…                        XM = 990
…                        IM = 999

CODE:

 

program a32BitCalculator;
#include ("stdlib.hhf");

static
 Value1: int32;
 Value2: int32;
 Value3: int32;
 Total1: int32;
 Total2: int32;
 Applications: int32;
 Applications1: int32;
 counter: int32; 
 i: int32;
 j: int32;

begin a32BitCalculator;

	stdout.put("Hello, this is Rafael And Cythia's 32BitCalculator coding", nl);

	stdout.put("Hello, The partners names are Cynthia and Rafael", nl);

	stdout.put("Hello, user to help you decide your application please select from the following list, (1)Addition, (2)Subtraction, (3)Multiplication, (4)Exponential, (5)Conversion to Roman Numerals, (6) to Exit the program.", nl, nl);

	mov(0,Applications);// Applications =0 unnesessary
	stdout.put("Application ", nl);
	stdin.get(Applications);
	 while (Applications>6 || Applications6
	  	stdout.put("Enter Application again");
		stdin.get(Applications);	//infinite loop untill correct number is inputed
		endwhile;	// first check ends
	  /* while (Applications<1)do// Second checks if Applications = 65000) do//Checks the first number for valid input
	   stdout.put("This number is out of range of the calculator please reinput the value.", nl);
	  stdout.put("Value1",nl);
          stdin.get(Value1);
	endwhile;		// ends first check

	stdout.put("Value2",nl);
	stdin.get(Value2);	//user inputs value2

	while(Value2 >= 65000) do//Checks the second number for valid input
           stdout.put("This number is out of range of the calculator please reinput the value.", nl);
          stdout.put("Value2",nl);
          stdin.get(Value2);
        endwhile;		//ends second check

		 mov(0, Total2);
		 mov(Value1,eax);//move "Value1" data to register eax
	 	 add(Value2,eax);//adds "Value2" data to register eax
		 mov(eax, Total2);//moves data in register eax to variable space "Total2"
		 stdout.put("The value for the Sum is = ", Total2, nl);//outputs Decimal data in Total2
		mov(0,eax);
		mov(0,ebx);
		mov(0,ecx);// Resets the registers after the Applications
		mov(0,edx);
		mov(0,Total1);
		mov(0,Total2);

//	Subtraction	
		elseif(Applications = 2) then

mov(0, Value1);//Value1=0 unnesessary
	mov(0, Value2);//Value2=0 unnesessary

	stdout.put("Please remember that if a number inputed is greater than 65000[2 raised to 16] the program may crash", nl);

	stdout.put("Please input the values for Value1, and Value2", nl);

	stdout.put("Value1",nl);
	stdin.get(Value1);	//user inputs value1

	while(Value1 >= 65000) do//Checks the first number for valid input
	   stdout.put("This number is out of range of the calculator please reinput the value.", nl);
	  stdout.put("Value1",nl);
          stdin.get(Value1);
	endwhile;		// ends first check

	stdout.put("Value2",nl);
	stdin.get(Value2);	//user inputs value2

	while(Value2 >= 65000) do//Checks the second number for valid input
           stdout.put("This number is out of range of the calculator please reinput the value.", nl);
          stdout.put("Value2",nl);
          stdin.get(Value2);
        endwhile;		//ends second check

		 mov(Value1,eax);//move "Value1" data to register eax
		 mov(Value2,ebx);//move "Value2" data to register ebx
		 sub(eax,ebx);//subtracts the data in register eax from ebx
		 mov(ebx,Total1);//move difference data in register ebx to "Total1"
		stdout.put("Please note that Value1 is subtracted from Value2",nl);
		 stdout.put("The value for the Difference is = ", Total1, nl);
		//outputs Decimal data in Total1
		mov(0,eax);
		mov(0,ebx);
		mov(0,ecx);// Resets the registers after the Applications
		mov(0,edx);
		mov(0,Total1);
		mov(0,Total2);

//	Multiplication
		elseif(Applications = 3) then

mov(0, Value1);//Value1=0 unnesessary
	mov(0, Value2);//Value2=0 unnesessary

	stdout.put("Please remember that if a number inputed is greater than 65000[2 raised to 16] the program may crash", nl);

	stdout.put("Please input the values for Value1, and Value2", nl);

	stdout.put("Value1",nl);
	stdin.get(Value1);	//user inputs value1

	while(Value1 >= 65000) do//Checks the first number for valid input
	   stdout.put("This number is out of range of the calculator please reinput the value.", nl);
	  stdout.put("Value1",nl);
          stdin.get(Value1);
	endwhile;		// ends first check

	stdout.put("Value2",nl);
	stdin.get(Value2);	//user inputs value2

	while(Value2 >= 65000) do//Checks the second number for valid input
           stdout.put("This number is out of range of the calculator please reinput the value.", nl);
          stdout.put("Value2",nl);
          stdin.get(Value2);
        endwhile;		//ends second check

		 	mov(Value2, edx);//move "Value2" data to register edx
			mov(Total1,eax);//move "Total1" data to register eax
		 for(mov(0, counter); counter = 65000) do//Checks the first number for valid input
	   stdout.put("This number is out of range of the calculator please reinput the value.", nl);
	  stdout.put("Value1",nl);
          stdin.get(Value1);
	endwhile;		// ends first check

	stdout.put("Value2",nl);
	stdin.get(Value2);	//user inputs value2

	while(Value2 >= 65000) do//Checks the second number for valid input
           stdout.put("This number is out of range of the calculator please reinput the value.", nl);
          stdout.put("Value2",nl);
          stdin.get(Value2);
        endwhile;		//ends second check

			mov(1,Total1);//move the data value decimal 1 to variable space "Total1"
			mov(Value2,eax);//move "Value2" data to register eax
			mov(Value1,ebx);//move "Value1" data to register ebx
			for(mov(0,i);i<eax; add(1,i))do//does the below statements until i is equal to Value2
			mov(0,ecx);//move the data value decimal 0 to register ecx, used as a place holder for the added values
				for(mov(0,j);j0) do//Starts the Roman numeral converter
					 if(eax=4)then
					   stdout.put("IV",nl);//Prints what is inside the quotes
						sub(4,eax);//subtracts 4 from inputed value
					 elseif(eax=9)then
					   stdout.put("IX",nl);//Prints what is inside the quotes
						sub(9,eax);//subtracts 9 from inputed value
					 elseif(eax=40)then
					   stdout.put("IL",nl);//Prints what is inside the quotes
						sub(40,eax);//subtracts 40 from inputed value
					 elseif(eax=90)then
					   stdout.put("XC",nl);//Prints what is inside the quotes
						sub(90,eax);//subtracts 90 from inputed value
					 elseif(eax=99)then
					   stdout.put("IC",nl);//Prints what is inside the quotes
						sub(99,eax);//subtracts 99 from inputed value
					 elseif(eax=400)then
					   stdout.put("CD",nl);//Prints what is inside the quotes
						sub(400,eax);//subtracts 400 from inputed value
					 elseif(eax=490)then
					   stdout.put("XD",nl);//Prints what is inside the quotes
						sub(490,eax);//subtracts 490 from inputed value
					 elseif(eax=499)then
					   stdout.put("ID",nl);//Prints what is inside the quotes
						sub(499,eax);//subtracts 499 from inputed value
					 elseif(eax=900)then
					   stdout.put("CX",nl);//Prints what is inside the quotes
						sub(900,eax);//subtracts 900 from inputed value
					 elseif(eax=990)then
					   stdout.put("XM",nl);//Prints what is inside the quotes
						sub(990,eax);//subtracts 990 from inputed value
					 elseif(eax=999)then
					   stdout.put("IM",nl);//Prints what is inside the quotes
						sub(999,eax);//subtracts 999 from inputed value
					 endif;		// ends the special check list
					 while(eax>=1000) do
					   stdout.put("M");//Prints what is inside the quotes
						sub(1000,eax);//subtracts 1000 from inputed value
					 endwhile;
					 while(eax>=500) do
					   stdout.put("D");//Prints what is inside the quotes
						sub(500,eax);//subtracts 500 from inputed value
					 endwhile;
					 while(eax>=100) do
					   stdout.put("C");//Prints what is inside the quotes
						sub(100,eax);//subtracts 100 from inputed value
					 endwhile;
					 while(eax>=50) do
					   stdout.put("L");//Prints what is inside the quotes
						sub(50,eax);//subtracts 50 from inputed value
					 endwhile;
					 while(eax>=10) do
					   stdout.put("X");//Prints what is inside the quotes
						sub(10,eax);//subtracts 10 from inputed value
					 endwhile;
					 while(eax>=5) do
					   stdout.put("V");//Prints what is inside the quotes
						sub(5,eax);//subtracts 5 from inputed value
					 endwhile;
					 while(eax>=1) do
					   stdout.put("I");//Prints what is inside the quotes
						sub(1,eax);//subtracts 1 from inputed value
					 endwhile;
					endwhile;//ends the Roman numeral loop

		mov(0,eax);
		mov(0,ebx);
		mov(0,ecx);// Resets the registers after the Applications
		mov(0,edx);
		mov(0,Total1);
		mov(0,Total2);

		endif;// ends the larger if statement for selection
		//End Choices
		//breakif(Applications = 6)then  
			stdout.put(nl);
			stdout.put("Enter Application again to continue", nl);
			stdout.put("(1)Addition",nl,"(2)Subtration",nl,"(3)Multiplication",nl,"(4)Exponentiation",nl,"(5)Roman Numeral Converter",nl,"(6)Exit the program",nl);
			stdin.get(Applications);		
		endwhile;
		end a32BitCalculator;		
//Final ------------------------------------------------------------------------------ 

Rodriguez_Cyn_Calculator_Addition_Lab2

Rodriguez_Cyn_Calculator_Subtraction_Lab2

Rodriguez_Cyn_Calculator_Multiplication_Lab2

Rodriguez_Cyn_Calculator_Exponentiation_Lab2

Rodriguez_Cyn_Calculator_Roman_Numerals_Lab2

Leave a Reply

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