LAB 2

Lab 2 Description:
The Second lab that I had to do was to write a program in HLA that calculates two input in additional, subtraction, multiplication, and exponential. The program also converts the output that is decimal into roman numerial. The additional and subtraction part was simple but the multiplication and exponential was a little difficult because you cannot use the mul and exp statements. I did the multiplication and exponential by first planning how i would do it mathmatically with out the multiply or exponent. I used the add for the multiplication and than used that for loop with increment to repeat until ecx is not lesser than ebx anymore. I did the same thing for the exponential except, i added new input and i did a for loop under a for loop. The purpose of the 1st for loop is to be a counter until a variable which is 0 is not less than ebx. After that it will move 0 to ecx for each count. During that time before the first for loop conter goes from 0 to 1, the second for loop is adding r to ecx, and repeating until a variable that is 0 is equal to eax. After that it will move the ecx to x variable and repeat until the first for loop is satisfied. The conversion to roman was not difficult since i did that last lab and all i had to do was change some code, and test it. This lab was a good learning experience to know how the add, sub, mul, and exponential in assembly work. It was also a good problem solving experience since i had to solve the problem using math and than translate that into code.

 CODE
program calculator;
	#include("stdlib.hhf");

static
	input1: int32;
	input2: int32;
	output: int32;
	calc: int32;
	x: int32;
	i:int32;
	j:int32;
	input:int32;

begin calculator;

	stdout.put("Enter your first input!", nl);
	stdin.get(input1);
	stdout.put("Enter your second input!", nl);
	stdin.get(input2);
	stdout.put("Your first input are=",input1,nl);
	stdout.put("Your second input are=",input2,nl);
	stdout.put("Enter 1 for add", nl,"Enter 2 for subtract", nl,"Enter 3 for multiplication", nl, 		"Enter 4 for exponent",nl);
	stdin.get(calc);
//ADD
if(calc=1) then
	mov(input1, eax);
	mov(input2, ebx);
	add(eax, ebx);
	mov(ebx, output);
	stdout.put("Your add output is=", output, nl);
	stdout.put("Enter 1 to convert to roman?",nl);
	stdin.get(input);
//Roman conversion
if(input=1) then

    mov(output, ESI);
    if(ESI0) then
            stdout.put("The number ",output," is equivalent to : ");
            if(ESI>=1000 && ESI<4000) then                       while(ESI>=1000) do
                  sub(1000, ESI);
                  stdout.put("M");
                  endwhile;
            endif;
            if(ESI>=900) then
                      sub(900, ESI);
                      stdout.put("CM");
            endif;
    if(ESI>=500) then
        sub(500, ESI);
        stdout.put("D");
    endif;
    if(ESI>=400) then
        sub(400,ESI);
        stdout.put("CD");
    endif;
    if(ESI>=100 && ESI<400) then         while(ESI>=100) do

        sub(100, ESI);
            stdout.put("C");
        endwhile;
    endif;
    if(ESI>=90) then
        sub(90, ESI);
        stdout.put("XC");
    endif;
    if(ESI>=50) then
        sub(50, ESI);
        stdout.put("L");
    endif;
    if(ESI>=40) then
        sub(40,ESI);
        stdout.put("XL");
    endif;
        if(ESI>=10 && ESI<40) then         while(ESI>=10) do
            sub(10, ESI);
            stdout.put("X");
        endwhile;
    endif;
    if(ESI>=9) then
        sub(9, ESI);
        stdout.put("IX");
    endif;
    if(ESI>=5) then
        sub(5, ESI);
        stdout.put("V");
    endif;
    if(ESI>=4) then
        sub(4,ESI);
        stdout.put("IV");
    endif;
    if(ESI>=1 && ESI<4) then         while(ESI>=1) do
            sub(1, ESI);
            stdout.put("I");
        endwhile;
    endif;
    stdout.put(" in Roman numeral"nl);
    endif;
endif;
endif;

//subtract
if(calc=2) then 
	mov(input1, eax);
	mov(input2, ebx);
	sub(ebx, eax);
	mov(eax, output);
	stdout.put("Your subtract output is=", output, nl);
	stdout.put("Enter 1 to convert to roman?",nl);
	stdin.get(input);
//Roman conversion
if(input=1) then

    mov(output, ESI);
    if(ESI0) then
            stdout.put("The number ",output," is equivalent to : ");
            if(ESI>=1000 && ESI<4000) then                       while(ESI>=1000) do
                  sub(1000, ESI);
                  stdout.put("M");
                  endwhile;
            endif;
            if(ESI>=900) then
                      sub(900, ESI);
                      stdout.put("CM");
            endif;
    if(ESI>=500) then
        sub(500, ESI);
        stdout.put("D");
    endif;
    if(ESI>=400) then
        sub(400,ESI);
        stdout.put("CD");
    endif;
    if(ESI>=100 && ESI<400) then         while(ESI>=100) do

        sub(100, ESI);
            stdout.put("C");
        endwhile;
    endif;
    if(ESI>=90) then
        sub(90, ESI);
        stdout.put("XC");
    endif;
    if(ESI>=50) then
        sub(50, ESI);
        stdout.put("L");
    endif;
    if(ESI>=40) then
        sub(40,ESI);
        stdout.put("XL");
    endif;
        if(ESI>=10 && ESI<40) then         while(ESI>=10) do
            sub(10, ESI);
            stdout.put("X");
        endwhile;
    endif;
    if(ESI>=9) then
        sub(9, ESI);
        stdout.put("IX");
    endif;
    if(ESI>=5) then
        sub(5, ESI);
        stdout.put("V");
    endif;
    if(ESI>=4) then
        sub(4,ESI);
        stdout.put("IV");
    endif;
    if(ESI>=1 && ESI<4) then         while(ESI>=1) do
            sub(1, ESI);
            stdout.put("I");
        endwhile;
    endif;
    stdout.put(" in Roman numeral"nl);
    endif;
endif;
endif;

//multiplication
if(calc=3) then
	mov(input1,eax);
	mov(input2,ebx);
	for(mov(0,ecx); ecx<ebx; inc(ecx)) do
		add(eax,output);
	endfor;
	stdout.put("multiplication=",output,nl);

	stdout.put("Enter 1 to convert to roman?",nl);
	stdin.get(input);
if(input=1) then

    mov(output, ESI);
    if(ESI0) then
            stdout.put("The number ",output," is equivalent to : ");
            if(ESI>=1000 && ESI<4000) then                       while(ESI>=1000) do
                  sub(1000, ESI);
                  stdout.put("M");
                  endwhile;
            endif;
            if(ESI>=900) then
                      sub(900, ESI);
                      stdout.put("CM");
            endif;
    if(ESI>=500) then
        sub(500, ESI);
        stdout.put("D");
    endif;
    if(ESI>=400) then
        sub(400,ESI);
        stdout.put("CD");
    endif;
    if(ESI>=100 && ESI<400) then         while(ESI>=100) do

        sub(100, ESI);
            stdout.put("C");
        endwhile;
    endif;
    if(ESI>=90) then
        sub(90, ESI);
        stdout.put("XC");
    endif;
    if(ESI>=50) then
        sub(50, ESI);
        stdout.put("L");
    endif;
    if(ESI>=40) then
        sub(40,ESI);
        stdout.put("XL");
    endif;
        if(ESI>=10 && ESI<40) then         while(ESI>=10) do
            sub(10, ESI);
            stdout.put("X");
        endwhile;
    endif;
    if(ESI>=9) then
        sub(9, ESI);
        stdout.put("IX");
    endif;
    if(ESI>=5) then
        sub(5, ESI);
        stdout.put("V");
    endif;
    if(ESI>=4) then
        sub(4,ESI);
        stdout.put("IV");
    endif;
    if(ESI>=1 && ESI<4) then         while(ESI>=1) do
            sub(1, ESI);
            stdout.put("I");
        endwhile;
    endif;
    stdout.put(" in Roman numeral"nl);
    endif;
endif;
endif;

//exponential
if(calc=4) then
	mov(1,x);
	mov(input1, eax);
	mov(input2, ebx);
	for(mov(0,i); i<ebx; inc(i)) do
		mov(0,ecx);
	for(mov(0,j); j<eax; inc(j)) do
		add(x,ecx);
	endfor;
	mov(ecx,x);
	mov(x,output);
	endfor;
	stdout.put("exponent=",x,nl);
	stdout.put("Enter 1 to convert to roman?",nl);
	stdin.get(input);
if(input=1) then

    mov(output, ESI);
    if(ESI0) then
            stdout.put("The number ",output," is equivalent to : ");
            if(ESI>=1000 && ESI<4000) then                       while(ESI>=1000) do
                  sub(1000, ESI);
                  stdout.put("M");
                  endwhile;
            endif;
            if(ESI>=900) then
                      sub(900, ESI);
                      stdout.put("CM");
            endif;
    if(ESI>=500) then
        sub(500, ESI);
        stdout.put("D");
    endif;
    if(ESI>=400) then
        sub(400,ESI);
        stdout.put("CD");
    endif;
    if(ESI>=100 && ESI<400) then         while(ESI>=100) do

        sub(100, ESI);
            stdout.put("C");
        endwhile;
    endif;
    if(ESI>=90) then
        sub(90, ESI);
        stdout.put("XC");
    endif;
    if(ESI>=50) then
        sub(50, ESI);
        stdout.put("L");
    endif;
    if(ESI>=40) then
        sub(40,ESI);
        stdout.put("XL");
    endif;
        if(ESI>=10 && ESI<40) then         while(ESI>=10) do
            sub(10, ESI);
            stdout.put("X");
        endwhile;
    endif;
    if(ESI>=9) then
        sub(9, ESI);
        stdout.put("IX");
    endif;
    if(ESI>=5) then
        sub(5, ESI);
        stdout.put("V");
    endif;
    if(ESI>=4) then
        sub(4,ESI);
        stdout.put("IV");
    endif;
    if(ESI>=1 && ESI<4) then         while(ESI>=1) do
            sub(1, ESI);
            stdout.put("I");
        endwhile;
    endif;
    stdout.put(" in Roman numeral"nl);
    endif;

endif;
endif;

end calculator;

Lab Report Screenshot:
Exponential
Screenshot from 2013-10-12 01:44:14

Multiplication:
Screenshot from 2013-10-12 02:00:03

Addition:
Screenshot from 2013-10-12 02:02:07

Subtraction:
Screenshot from 2013-10-12 02:03:57

Leave a Reply