Lab 2

Lab Description:

To understand and demonstrate how to code in HLA (Higher Language Assembly) by updating the previous calculator assignment with a new function. The new function should convert any decimal integer into an roman numeral. The new function should take into consideration of the special cases such as the number 4, the roman numeral conversion for it would be IV and so forth. The special cases of roman numerals takes a number such as 1 or 5 before the bigger and substracts it. IV is 5 – 1 because of the 1 in front. The same applies to numbers such as 10 or 90. 90 is represented as XC, where c is squivalent to 100 and X is equivalent to 10. the X in front of C means 100 – 10 which equates to 90.

Code:

program calc;
#include("stdlib.hhf");
static //declaration of variables
	num1: int32;
	num2: int32;
	num3: int32;
	ans: int32;
	choice: int32;
	i: int32;
	ii: int32;
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) Dec to Roman   |-----", nl);
		stdout.put("-----| 6) 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, eax);	
			stdout.put("Enter in second number: ");
			stdin.get(num2);
			mov(num2, ebx);
			add(eax, ebx); //addition
			mov(ebx, ans);
			stdout.put("Answer: ", ans, nl);
		elseif (choice = 2) then
			stdout.put("Enter in first number: ");
			stdin.get(num1);
			mov(num1, eax);	
			stdout.put("Enter in second number: ");
			stdin.get(num2);
			mov(num2, ebx);
			sub(ebx, eax); //subtraction
			mov(eax, ans);
			stdout.put("Answer: ", ans, nl);
		elseif (choice = 3) then
			stdout.put("Enter in first number: ");
			stdin.get(num1);
			mov(num1, eax);	
			stdout.put("Enter in second number: ");
			stdin.get(num2);
			mov(num2, ebx);
			//for statement that multiplies with addition
			for(mov(0,i); i < ebx; add(1, i)) do
				add(eax,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, eax
			mov(num1, eax);	
			stdout.put("Enter exponent: ");
			stdin.get(num2); //exponent, ebx
			mov(num2, ebx); 
			//for statement that does exponentials with addition
			for(mov(0,i); i < eax; add(1, i)) do
				add(eax,ans);
				for(mov(1,ii); ii 0)do
				if(eax >= 1000)then
					stdout.put("M");
					sub(1000,eax);
				elseif(eax >= 999)then
					stdout.put("IM");
					sub(999,eax);
				elseif(eax >= 995)then
					stdout.put("VM");
					sub(995,eax);
				elseif(eax >= 990)then
					stdout.put("XM");
					sub(990,eax);
				elseif(eax >= 950)then
					stdout.put("LM");
					sub(950,eax);
				elseif(eax >= 900)then
					stdout.put("CM");
					sub(900,eax);
				elseif(eax >= 500)then
					stdout.put("D");
					sub(500,eax);
				elseif(eax >= 499)then
					stdout.put("ID");
					sub(499,eax);
				elseif(eax >= 495)then
					stdout.put("VD");
					sub(495,eax);
				elseif(eax >= 490)then
					stdout.put("XD");
					sub(490,eax);
				elseif(eax >= 450)then
					stdout.put("LD");
					sub(450,eax);
				elseif(eax >= 400)then
					stdout.put("CD");
					sub(400,eax);
				elseif(eax >= 100)then
					stdout.put("C");
					sub(100,eax);
				elseif(eax >= 99)then
					stdout.put("IC");
					sub(99,eax);
				elseif(eax >= 95)then
					stdout.put("VC");
					sub(95,eax);
				elseif(eax >= 90)then
					stdout.put("XC");
					sub(90,eax);
				elseif(eax >= 50)then
					stdout.put("L");
					sub(50,eax);
				elseif(eax >= 49)then
					stdout.put("IL");
					sub(49,eax);
				elseif(eax >= 45)then
					stdout.put("VL");
					sub(45,eax);
				elseif(eax >= 40)then
					stdout.put("XL");
					sub(40,eax);
				elseif(eax >= 10)then
					stdout.put("X");
					sub(10,eax);
				elseif(eax >= 9)then
					stdout.put("IX");
					sub(9,eax);
				elseif(eax >= 5)then
					stdout.put("V");
					sub(5,eax);
				elseif(eax >= 4)then
					stdout.put("IV");
					sub(4,eax);
				else
					stdout.put("I");
					sub(1,eax);	
				endif;
			endwhile;
			stdout.put(nl);
		elseif (choice = 6) 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-03-12 22:54:11