LAB 2

LAB DESCRIPTION:

This second lab, we were asked to write a program this different operations, such as addition, subtraction, multiplication and exponential. For this program, I used the ” if….then”, and “else if….then” conditions to be able set up this cases. this is lab, the idea to how to set the program was there. but the set up of the writing was a littleĀ tough. I might say.Ā Also I had a program that I couldn’t figure outĀ because the compiler was running the program.Ā TheĀ problem wasĀ I was missing theĀ doubleĀ equal signĀ in the set up of the condition: (if (ecx”==”1) then:). The professor saw it and everything ran perfectly.

Code:

Program Operation;
#include("stdlib.hhf");
Static
a: int32;
x: int32;
y: int32;
z: int32;
i: int32;
j: int32;
begin Operation;

stdout.put( " choose operation ",nl);
stdout.put( "1 = addition",nl);
stdout.put( "2 = substraction",nl);
stdout.put( "3 = multiplication",nl);
stdout.put("4 = exponantial",nl);
stdout.put( "enter option ",nl);
stdin.get(a);
mov(a,ecx);

if (ecx==1) then;

	  stdout.put( "enter x ",nl);
	  stdin.get(x);
	  stdout.put( "enter y ",nl);
	  stdin.get(y);
	  mov(x,eax);
	  mov(y,ebx);
	  add(eax,ebx);
	  mov(ebx,z);
	  stdout.put(z);

elseif(ecx==2) then
	  stdout.put( "enter x ",nl);
	  stdin.get(x);
	  stdout.put( "enter y ",nl);
	  stdin.get(y);
	  mov(x,eax);
	  mov(y,ebx);
	  sub(ebx,eax);
	  mov(eax,z);
	  stdout.put(z);

elseif (ecx==3) then
	  stdout.put( "enter x ",nl);
	  stdin.get(x);
	  stdout.put( "enter y ",nl);
	  stdin.get(y);
	  mov(x,eax);
	  mov(y,ebx);
	  mul(ebx);
	  mov(eax,z);
	  stdout.put(z);

elseif (ecx==4) then 
stdout.put(nl);
stdout.put( "enter x ",nl);
	  stdin.get(x);
	  stdout.put( "enter y ",nl);
	  stdin.get(y);
	mov(x,eax);
		mov(y,ebx);
		mov(1,z);
			for(mov(0,i); i<ebx; inc(i)) do
 				mov(0,ecx);
			for(mov(0,j); j<eax; inc(j)) do   			
				add(z,ecx);             		
		endfor; 		  
 			mov(ecx,z); 			
		endfor; 		

                stdout.put("the answer is: ",z,nl); 
		endif;
		stdout.put(nl);

 end Operation;

CODE:

pic1

 

Leave a Reply

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