Lab Description
A basic 32 bit calculator that has a menu that asks the user for which operation they want to do. The calculator supports
adding, subtracting, and multiplication. The calculator does not use any loops or mul function; it uses labels and jumps to do most operations. The calculator will not exit until the user presses 0.
Code
program lab3; #include("stdlib.hhf") static x:int32; y:int32; r:int32; choice:int32; begin lab3; loop_menu: stdout.put("Enter 1 to add numbers: ",nl); stdout.put("Enter 2 to subtract numbers: ",nl); stdout.put("Enter 3 to multiply numbers: ",nl); stdout.put("Enter 0 to exit: ",nl); stdin.get(choice); mov(choice,edx); cmp(edx,1); jne a; mov(0,r); stdout.put("enter number 1: "); stdin.get(x); stdout.put("enter number 2: "); stdin.get(y); mov(x,eax); mov(y,ebx); add(ebx,eax); mov(eax,r); stdout.put("The answer is: ",r,nl); jmp loop_menu; a: cmp(edx,2); jne s; mov(0,r); stdout.put("enter number 1: "); stdin.get(x); stdout.put("enter number 2: "); stdin.get(y); mov(x,eax); mov(y,ebx); sub(ebx,eax); mov(eax,r); stdout.put("The answer is: ",r,nl); jmp loop_menu; s: cmp(edx,3); jne m; mov(0,r); stdout.put("enter number 1: "); stdin.get(x); stdout.put("enter number 2: "); stdin.get(y); mov(x,eax); mov(y,ebx); mul_loop: cmp(ebx,0); jle mul_end; add(eax,r); sub(1,ebx); jmp mul_loop; mul_end: stdout.put("the answer is: ",r,nl); stdout.put(nl); jmp loop_menu; m: cmp(edx,0); jne loop_menu; stdout.put("End Of Program"); end lab3;