Lab 3

In this lab we were able to create a simple 32-bit calculator. This calculator will be able to preform addition, subtraction and multiplication by using labels and jump commands.


program bitcalc32;
#include( "stdlib.hhf");

static
	a: int32;
	b: int32;
	c: int32;
	d: int32;
	e: int32;
	n: int32;
	choice: int32;

begin bitcalc32;

	menu:
		stdout.put("For Addition press 1, Subtraction press 2, Multiplication press 3, to exit press 0", nl);
		stdin.get(choice);
		mov(choice,edx);
		cmp(edx,1);
                je addition;
                cmp(edx,2);
                je subtraction;
                cmp(edx,3);
                je multiplication;
                cmp(edx,0);
                je exit1;
		
				addition:
					stdout.put("Enter first number", nl);
					stdin.get(a);
					mov(a, eax);
					stdout.put("Enter second number", nl);
					stdin.get(b);
					mov(b, ebx);
					add(eax, ebx);
					mov(ebx, c);
					stdout.put("Answer equals:", c, nl);
					jmp menu;

				subtraction:
					stdout.put("Enter first number", nl);
					stdin.get(a);
					mov(a, eax);
					stdout.put("Enter second number", nl);
					stdin.get(b);
					mov(b, ebx);
					sub(ebx, eax);
					mov(eax, d);
					stdout.put("Answer equals:", d, nl);
						jmp menu;

				multiplication:
					stdout.put("Enter first number", nl);
					stdin.get(a);
					mov(a, eax);
					stdout.put("Enter second number", nl);
					stdin.get(b);
					mov(b, ebx);
					mov(1, n);
					mov(n, edx);
					mov(0, ecx);
						jmp multiplication2;
							multiplication2:
								cmp(edx, ebx);
								jg Done;
								add(eax, ecx);
								inc(edx);
								jmp multiplication2;
					Done:
						mov(ecx, e);						
						stdout.put("Answer equals:", e, nl);
						jmp menu;
		
				exit1:
end bitcalc32;
 

bitcalc32

Leave a Reply

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