Lab 3

Lab Description:

This lab consist of creating a 32bit calculator, which function is to add, subtract and multiply two entries. We should use labels and jumps to implemented. We should not use the following functions: if, while, mul…

Lab Code:

program lab3;
#include( "stdlib.hhf");
static
	n:int32;
	n1:int32;
	n2:int32;
	x:int32;
begin lab3;
RepeatLabel:
		stdout.put("Press [1]:Addition [2]:subtraction [3]:multiplication [0]: exit",nl);
		stdout.put("Operation:");
		stdin.get(n);
			mov(n,edx);
				mov(1,ebx);
				cmp(edx,ebx);
			jne Skip;
				stdout.put("enter n1: ");
				stdin.get(n1);
				mov(n1, eax);
				stdout.put(" enter n2: ");
				stdin.get(n2);
				mov(n2, ebx);
				add(ebx,eax);
				mov(eax,n);
				stdout.put("the sum is: ",n, nl);
			Skip:
				mov(2,ebx);
				cmp(edx,ebx);
			jne Skip1;
				stdout.put("enter n1: ");
				stdin.get(n1);
				mov(n1,eax);
				stdout.put("enter n2: ");
				stdin.get(n2);
				mov(n2,ebx);
				sub(ebx,eax);
				mov(eax,n);
				stdout.put("the difference is: ",n, nl);
			Skip1:
				mov(3,ebx);
				cmp(edx,ebx);
			jne Skip2;
				stdout.put("enter n1:");
				stdin.get(n1);
				mov(n1,eax);
				stdout.put("enter n2:");
				stdin.get(n2);
				mov(n2,ebx);
				mov(1,n2);
					WhileLabel:
						cmp(n2,ebx);
						jnl WhileDone;
						add(n1,eax);
						inc(n2);
						jmp WhileLabel;
					WhileDone:
				mov(eax,n);
				stdout.put("the product is:",n, nl);
			Skip2:
mov(0,ecx);
cmp(ecx,edx);
jne RepeatLabel;
end lab3;

 

Screenshots:

Screenshot Screenshot-1 Screenshot-2

Leave a Reply

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