In this lab we had to create a calculator that will display a menu asking the user what operation to perform. The operations supported are addition, subtraction, multiplication, exponentiation and convert to roman numerals . When the user selects an operation the program will ask the user for the values and perform the operation.
program Calc1; #include("stdlib.hhf") static x:int32; y:int32; r:int32; i:int32; j:int32; Operation:int32; begin Calc1; repeat 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 4 to convert to roman numbers: ",nl); stdout.put("Enter 5 to do exponents:",nl); stdout.put("Enter 0 to exit: ",nl); stdin.get(Operation); mov(Operation,edx); switch(edx) case(1) mov(0,r); stdout.put("enter number 1: "); stdin.get(x); if(x>65536) then stdout.put(nl,"number is larger than 65536!" , nl); endif; stdout.put(nl); stdout.put("enter number 2: "); stdin.get(y); if(y>65536) then stdout.put(nl,"number is larger than 65536!" , nl); endif; stdout.put(nl); mov(x,eax); mov(y,ebx); add(ebx,eax); mov(eax,r); stdout.put("The answer is: ",r,nl); if(r>65536) then stdout.put(nl,"number is larger than 65536!" , nl); endif; stdout.put(nl); case(2) mov(0,r); stdout.put("enter number 1: "); stdin.get(x); if(x>65536) then stdout.put(nl,"number is larger than 65536!" , nl); endif; stdout.put(nl); stdout.put("enter number 2: "); stdin.get(y); if(y>65536) then stdout.put(nl,"number is larger than 65536!" , nl); endif; stdout.put(nl); mov(x,eax); mov(y,ebx); sub(ebx,eax); mov(eax,r); stdout.put("The answer is: ",r,nl); if(r>65536) then stdout.put(nl,"number is larger than 65536!" , nl); endif; stdout.put(nl); case(3) mov(0,r); stdout.put("enter number 1: "); stdin.get(x); if(x>65536) then stdout.put(nl,"number is larger than 65536!" , nl); endif; stdout.put(nl); stdout.put("enter number 2: "); stdin.get(y); if(y>65536) then stdout.put(nl,"number is larger than 65536!" , nl); endif; stdout.put(nl); mov(x,eax); mov(y,ebx); while(ebx > 0) do add(eax,r); sub(1,ebx); endwhile; stdout.put("the answer is: ",r,nl); if(r>65536) then stdout.put(nl,"number is larger than 65536!" , nl); endif; stdout.put(nl); case(4) mov(0,r); stdout.put("enter a number: "); stdin.get(x); if(x>65536) then stdout.put(nl,"number is larger than 65536!" , nl); endif; stdout.put(nl); mov(x,eax); while(eax > 0) do if(eax >= 1000 ) then stdout.put("M"); sub(1000,eax); elseif(eax >= 900 ) then stdout.put("CM"); sub(900,eax); elseif(eax >= 500 ) then stdout.put("D"); sub(500,eax); elseif(eax >= 400 ) then stdout.put("CD"); sub(400,eax); elseif(eax >= 100 ) then stdout.put("C"); sub(100,eax); elseif(eax >= 90 ) then stdout.put("XC"); sub(90,eax); elseif(eax >= 50 ) then stdout.put("L"); sub(50,eax); elseif(eax >= 40 ) then stdout.put("XL"); sub(40,eax); elseif(eax >= 10 ) then stdout.put("X"); sub(10,eax); elseif(eax >= 9 ) then stdout.put("IX"); sub(9,eax); elseif(eax >= 5 ) then stdout.put("V"); sub(5,eax); elseif(eax >= 4 ) then stdout.put("IV"); sub(4,eax); elseif(eax >= 1 ) then stdout.put("I"); sub(1,eax); endif; endwhile; stdout.put(nl); case(5) mov(0,r); stdout.put("enter number 1: "); stdin.get(x); if(x>65536) then stdout.put(nl,"number is larger then 65536!" , nl); endif; stdout.put(nl); stdout.put("enter number 2: "); stdin.get(y); if(y>65536) then stdout.put(nl,"number is larger then 65536!" , nl); endif; stdout.put(nl); mov(x,eax); mov(y,ebx); mov(1,r); for(mov(0,i); i<ebx; inc(i)) do mov(0,ecx); for(mov(0,j); j65536) then stdout.put(nl,"number is larger then 65536!" , nl); endif; stdout.put(nl); endswitch; until(edx = 0); stdout.put("end program"); end Calc1;