Lab 1

Lab Description:

To understand and demonstrate how to code in HLA (Higher Language Assembly) by producing a very simple calculator that can perform addition, subtraction, multiplication and exponential functions. HLA is a language that is both higher and lower level. It provides more of a control over the hardware by a means of memory allocation when performing computations. Compiling the program is simple with the command “hla [filename.hla]” and execution of the file name uses the command “./filename”  The addition and subtraction is fairly simple and is done by a function call of add() and sub() perspectively. The multiplication and exponents are a bit more complex and will utilize for-loop’s that will loop the addition to perform both the multiplication and exponential tasks.

Code:

program calc;
#include("stdlib.hhf");
static //declaration of variables
	num1: int16;
	num2: int16;
	num3: int16;
	ans: int16;
	choice: int16;
	i: int16;
	ii: int16;
begin calc;
	//loop that will run forever unless option 5 is selected
	forever
		stdout.put("-----|-------------------|-----", nl);
		stdout.put("-----|     Calc Menu     |-----", nl);
		stdout.put("-----|-------------------|-----", nl);
		stdout.put("-----| 1) Addition       |-----", nl);
		stdout.put("-----| 2) Subtraction    |-----", nl);
		stdout.put("-----| 3) Multiplication |-----", nl);
		stdout.put("-----| 4) Exponent       |-----", nl);
		stdout.put("-----| 5) Exit           |-----", nl);
		stdout.put("-----|-------------------|-----", nl);
		stdout.put("Enter in choice: ");
		stdin.get(choice);

		//if then statement for choice input
		if (choice = 1) then
			stdout.put("Enter in first number: ");
			stdin.get(num1);
			mov(num1, ax);	
			stdout.put("Enter in second number: ");
			stdin.get(num2);
			mov(num2, bx);
			add(ax, bx); //addition
			mov(bx, ans);
			stdout.put("Answer: ", ans, nl);
		elseif (choice = 2) then
			stdout.put("Enter in first number: ");
			stdin.get(num1);
			mov(num1, ax);	
			stdout.put("Enter in second number: ");
			stdin.get(num2);
			mov(num2, bx);
			sub(bx, ax); //subtraction
			mov(ax, ans);
			stdout.put("Answer: ", ans, nl);
		elseif (choice = 3) then
			stdout.put("Enter in first number: ");
			stdin.get(num1);
			mov(num1, ax);	
			stdout.put("Enter in second number: ");
			stdin.get(num2);
			mov(num2, bx);
			//for statement that multiplies with addition
			for(mov(0,i); i < bx; add(1, i)) do
				add(ax,num3);
			endfor;
			mov(num3,ans);
			stdout.put("Answer: ", ans, nl);
			mov(0,num3);
		elseif (choice = 4) then
			stdout.put("Enter base: ");
			stdin.get(num1); //base, ax
			mov(num1, ax);	
			stdout.put("Enter exponent: ");
			stdin.get(num2); //exponent, bx
			mov(num2, bx); 
			//for statement that does exponentials with addition
			for(mov(0,i); i < ax; add(1, i)) do
				add(ax,ans);
				for(mov(1,ii); ii <= bx; add(1,ii)) do
					mov(ans,cx);
					add(ans,cx);
					mov(cx,ans);	
				endfor;			
			endfor;
			stdout.put("Answer: ", ans, nl);
			mov(0,ans);
		elseif (choice = 5) then //display message and exit after option 5
			stdout.put("Thanks for using my 16-bit Calc v1.0 :)", nl);
			break;
		else //for anything else the user inputs is invalid
			stdout.put("Error: Invalid Menu Selection...", nl);
		endif;
	endfor;
end calc;

 

Screenshot:

Screenshot from 2014-02-27 05:42:43 Screenshot from 2014-02-27 05:43:15