LAB-1

                                                         32-bit Calculator Lab #1

LAB DESCRIPTION:

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.

One major problem I had was that i could not get the program to run indefinitely until the user decided to exit the calculator. In addition, another problem I ran across was that i created a logical error that ended the code prematurely so that when a application is selected it did not check the statements below.

CODE:

 

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

static
 Value1: int32;
 Value2: int32;
 Total1: int32;
 Total2: int32;
 Applications: 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);

	mov(0, Value1);
	mov(0, Value2);
	stdout.put("Please remember that if a number inputed is greater than 65000[2 raised to 16]");
	stdout.put("Please input the values for Value1, and Value2", nl);

	  stdout.put("Value1",nl);
	  stdin.get(Value1);
	while(Value1 >= 65000) do
	   stdout.put("This number is out of range of the calculator please reinput the value.", nl);
	  stdout.put("Value1",nl);
          stdin.get(Value1);
	endwhile;
	stdout.put("Value2",nl);
	stdin.get(Value2);
	while(Value2 >= 65000) do
           stdout.put("This number is out of range of the calculator please reinput the value.", nl);
          stdout.put("Value2",nl);
          stdin.get(Value2);
        endwhile;

	mov(0,Applications);
	stdout.put("Application ", nl);
	stdin.get(Applications);
	 if(Applications>6) then  //while (Applications>6) do
	  	stdout.put("Enter Application again");
		stdin.get(Applications);
	   elseif(Applications=0)then  //while (Applications=0)do
		stdout.put("Enter Application again");
           stdin.get(Applications);
			//endwhile; 
	   endif;	//endwhile;	//ending the program prematurely, 
		//	Addition
	if(Applications = 1) then
		 mov(0, Total2);
		 mov(Value1,eax);
	 	 add(Value2,eax);
		 mov(eax, Total2);
		 stdout.put("The value for the Sum is = ", Total2, nl);
		//endif;
		//	Subtraction	
		elseif(Applications = 2) then
		 mov(Value1,eax);
		 sub(eax,Value2);
		 stdout.put("The value for the Difference is = ", Value2, nl);
		//endif;
		//	Multiplication
		elseif(Applications = 3) then
		 	mov(Value2, edx);
			mov(Total1,eax);			
			mov(counter,ebx);
		 for(mov(0, counter); counter < edx; inc(counter)) do
		        mov(Value1,ecx);
		  	add(ecx, eax);
			mov(eax, Total1);
		 endfor;
		 	stdout.put("This program will use arithmatic addition");	
		  	stdout.put("The value for the product is = ", Total1, nl);

		//	Exponentiation
		elseif(Applications = 4) then
			mov(1,Total1);
			mov(Value2,eax);
			mov(Value1,ebx);
			for(mov(0,i);i<eax; add(1,i))do
			mov(0,ecx);
				for(mov(0,j);j<ebx; add(1,j))do
					add(Total1,ecx);
					//mov(ecx,Total1);
				endfor;
				mov(ecx,Total1);
			endfor;
			stdout.put("The Eponent Value is = ", Total1, nl);

		//	Roman Numerals
		elseif(Applications = 5) then
		  stdout.put("Please Choose another Applications, Under Construction, Have a nice day");
		endif;
		//End Choices
		//breakif(Applications = 6)then  

		end a32BitCalculator;		
//Final ------------------------------------------------------------------------------
Rodriguez_Cyn_Calculator_Addition

Rodriguez_Cyn_Calculator_Subtraction

Rodriguez_Cyn_Calculator_Multiplication1

Rodriguez_Cyn_Calculator_Exponentiation1

Leave a Reply

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