Lab 3- Calc32 bit with the use of Jumps

 

Lab Description:

This is a recreation of the second lab with the use of jumps and no loops. This creates challenge of recreating for , if-else, repeat loops using jumps. With the use of jumps, variety of labels are made that contain each arithmetic operation, 1-addition, 2-subtraction, 3-multiplication, then one label for the option to exit the program. Using jumps in the program, it relies on comparison statements which determines what arithmetic label the program  will jump to.

Code:

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

static
	numone: int32;
	numtwo: int32;
	x: int32;
	y: int32;
	z: int32;
	u: int32;
	v: int32;
	n: int32;
	Decision: int32;

begin jmpcalc32;

	menu0:
		stdout.put("What math operation would you like to do? For Add-1 , Subtract-2 , Multiply-3, To exit press '9'", nl);
		stdin.get(Decision);
		//If you press '1', start addition.
		cmp(Decision, 1);
		je add1;
		jne menu1;
			add1:
				stdout.put("What's the first number", nl);
				stdin.get(x);
				mov(x, eax);
				stdout.put("What's the second number", nl);
				stdin.get(y);
				mov(y, ebx);
				//Add both numbers together.
				add(eax, ebx);
				mov(ebx, z);
				stdout.put("Your answer is:", z, nl);
					jmp menu0;
		menu1:
			//If you press '2', start subtraction.
			cmp(Decision, 2);
			je sub1;
			jne menu2;

				sub1:
					stdout.put("What's the first number", nl);
					stdin.get(x);
					mov(x, eax);
					stdout.put("What's the second number", nl);
					stdin.get(y);
					mov(y, ebx);
					//Subtract both numbers together.
					sub(ebx, eax);
					mov(eax, u);
					stdout.put("Your answer is:", u, nl);
						jmp menu0;
		menu2:
			//If you press '3', start multiplication.
			cmp(Decision, 3);
			je multi1;
			jne menu3;
				multi1:
					stdout.put("What's the first number", nl);
					stdin.get(x);
					mov(x, eax);
					stdout.put("What's the second number", nl);
					stdin.get(y);
					mov(y, ebx);
					mov(1, n);
					mov(n, edx);
					mov(0, ecx);
						//Start the repetition of addition until n is greater 3
						jmp multi2;
							multi2:
								cmp(edx, ebx);
								jg Done;
								add(eax, ecx);
								inc(edx);
								jmp multi2;
					Done:
						mov(ecx, v);						
						stdout.put("Your product is:", v, nl);
						jmp menu0;
		menu3:
			//If you press '9', you will exit out of the program.		
			cmp(Decision, 9);
			je exit1;
				exit1:
end jmpcalc32;

 

Screenshots:

jmpcalc32

 

 

 

Leave a Reply

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