32-bit Calculator Converter

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

Its a same 32bit calculator from LAB1 but we have new addition in menu for operation called “Roman Numerals”. when selecting this operation the number you entered will be converted to Roman Numerals. EX “25 will be converted into XXV”.

My partner name is Fredrick Jah.

Lab Code

program calc1;
    #include("stdlib.hhf");
static 
n1:int32; // n1  
n2:int32; // n2
n3:int32; // n3
rom: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) Roman numeral,(6)To end the program", nl);
      stdin.get(otbp);

while(otbp>5)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; // addition if(otbp=1)then stdout.put(nl,"Please input 1st number: "); stdin.get(n1); while(n1>=65535)do
stdout.put(nl,"Please input 1st number: ");
 stdin.get(n1);
endwhile;
     stdout.put(nl,"Please input 2nd number: ");
stdin.get(n2);
while(n2>=65535)do
stdout.put(nl,"Please input 2nd number: ");
stdin.get(n2);
endwhile;

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

//subtraction
elseif(otbp=2)then

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

while(n1>=65535)do
stdout.put(nl,"Please input 1st number: ");
stdin.get(n1);
endwhile;
     stdout.put(nl,"Please input 2nd number: ");
stdin.get(n2);
while(n2>=65535)do
 stdout.put(nl,"Please input 2nd number: ");
stdin.get(n2);
endwhile;

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

//multiplication

elseif(otbp=3)then 

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

while(n1>=65535)do
stdout.put(nl,"Please input 1st number: ");
stdin.get(n1);
endwhile;
      stdout.put(nl,"Please input 2nd number: ");
stdin.get(n2);
while(n2>=65535)do
stdout.put(nl,"Please input 2nd number: ");
stdin.get(n2);
endwhile;

mov(n2,edx);
mov(vop,eax);
 mov(cot,ebx);
for(mov(0,cot);cot<edx;inc(cot))do mov(n1,ecx); add(ecx,eax); endfor; mov(eax,vop);      stdout.put(nl,"The answer is: ", vop, nl); //exponentiation elseif(otbp=4)then stdout.put(nl,"Please input 1st number: "); stdin.get(n1); while(n1>=65535)do
stdout.put(nl,"Please input 1st number: ");
stdin.get(n1);
endwhile;
     stdout.put(nl,"Please input 2nd number: ");
 stdin.get(n2);
while(n2>=65535)do
stdout.put(nl,"Please input 2nd number: ");
stdin.get(n2);
endwhile;

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); elseif(otbp=5)then      stdout.put(" Please enter a Number between 1 and 7000",nl);       stdout.put(" The number you enter is going to be converted into Roman numeral ",nl ); stdin.get(rom); mov(rom,eax); while(eax>0)do
// M=1000
// D=500
// C=100
// L=50
// X=10
// V=5
 // I=1
if(eax>=1000)then
stdout.put("M");
sub(1000,eax);

elseif(eax>=999)then
stdout.put("IM");
sub(999,eax);

elseif(eax>=990)then
stdout.put("XM");
 sub(990,eax);

elseif(eax>=900)then
stdout.put("CM");
sub(900,eax);

elseif(eax>=500)then
stdout.put("D");
sub(500,eax);

elseif(eax>=499)then
stdout.put("ID");
 sub(499,eax);

elseif(eax>=490)then
stdout.put("XD");
sub(490,eax);

elseif(eax>=400)then
stdout.put("CD");
sub(400,eax);

elseif(eax>=100)then
stdout.put("C");
 sub(100,eax);

elseif(eax>=99)then
stdout.put("IC");
sub(99,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);

endif;
end calc1;

 

 

 

Leave a Reply

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