32-bit Calculator

32-bit Calculator

Introduction:

The objective of this experiment is to create a simple 32-bit calculator.  The calculator will display a menu asking the user what operation they would like to perform.  The operations supported should be: Addition, Subtraction, Multiplication, and Exponentiation.  Once the user selects an operation, the program will ask the user for the values and perform the operation.  The multiplication and exponentiation operation must be implemented as a loop that adds numbers repeatedly. You are not to use the mul, imul, or pow functions to perform multiplication and exponentiation.  Once the program computes the value and displays the result, it should return to the original menu until the user chooses to exit.

I have many problem with coding nearly 129 errors, but I have reduce all the errors.

My partner name is Fredrick Jah.

Lab Code

program calc1;
#include("stdlib.hhf");
static
n1:int32; // n1
n2:int32; // n2
n3:int32; // n3
n4:int32; //
n5:int32; // n5
n6:int32; // n6
cot:int32; // cot
vop:int32;// value out put vop
otbp:int32;// operation to be performed //app
begin calc1;

stdout.put("Please select operation to be performed on the 2 numbers from following lists, (1)Addition,(2)Subtractoin,(3)Multiplicatoin,(4)Exponentation,(5) To end the program", nl);
stdin.get(otbp);

while(otbp>4)do
stdout.put(nl,"invalid selection", nl);
stdin.get(otbp);
endwhile;
while(otbp<1)do
stdout.put(nl,"invalid selection", nl);
stdin.get(otbp);
endwhile;

stdout.put(nl,"Please input 1st number: ");
stdin.get(n1);
stdout.put(nl,"Please input 2nd number: ");
stdin.get(n2);

// addition
if(otbp=1)then

mov(n1,eax);
mov(n2,ebx);
add(eax,ebx);
mov(ebx, vop);
stdout.put("The answer is", vop, nl);

//subtraction
elseif(otbp=2)then

mov(n1, eax);
mov(n2, ebx);
sub(eax,ebx);
mov(ebx, vop);
stdout.put("The answer is",vop, nl);

//multiplication
elseif(otbp=3)then

mov(n2,edx);
mov(vop,eax);
mov(cot,ebx);
for(mov(0,cot);cot<edx;inc(cot))do
mov(n1,ecx);
add(ecx,eax);
mov(eax,vop);

stdout.put(nl,"The answer is: ", vop, nl);

//exponentiation

//elseif(otbp=4)then

mov(1,vop);
mov(n2,eax);
mov(n1,ebx);
for(mov(0,n5);n5<eax;add(1,n5))do
mov(0,ecx);
for(mov(0,n6);n6<ebx;add(1,n6))do
add(vop,ecx);
endfor;
mov(ecx,vop);
endfor;
stdout.put(nl,"The answer is: ", vop, nl);

endif;
end calc1;

Leave a Reply

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