Lab Description:
In this lab we were creating a simple 32 bit calculator using HLA Program. This 32 bit calculator we needed to display the user perform like addition, subtraction, multiplication ,exponentiation and convert to roman to perform the operation. Once you program is selected by an operation the program will ask to input the integer values and perform the operation. The system has to display a warning message if the user is value is greater than 2^16(65536) the operation will overflow. In the multiplication it needs to add a loop so the number can add repeatedly while the exponentiation must have a loop that multiplies numbers repeatedly. Once the program is done run it to see if it works properly or not.
Lab Partner: Cesar Manon.
Code:
Program lab2; #include("stdlib.hhf"); static number:int32; number2:int32; final:int32; operations:int32; k:int32; j:int32; r:int32; i:int32; x:int32; begin lab2; stdout.put("This is my calculator",nl); stdout.put("For the following operations insert the given values, (1)Addition,(2)Subtraction,(3)Multiplication,(4)Exponentiation,(5)Convert to Roman,(6)Exit",nl); stdin.get (operations); if (operations>6) then stdin.get(operations); endif; if (operations=0) then stdin.get (operations); endif; stdout.put("Please input the values for number,number2",nl); stdin.get(number); stdin.get(number2); while(number>65000) do stdout.put("This number is out of range please enter it again") stdin.get(number); endwhile; while(number2>65000) do stdout.put("This number is out of range please enter it again") stdin.get(number2); endwhile; //Addition if(operations=1) then mov(number,eax); add(eax,number2); stdout.put(number2, nl); //Subtraction elseif(operations=2) then mov(number,eax); sub(eax,number2); stdout.put(number2, nl); //Multiplication elseif(operations=3) then mov(number2,eax); mov(0, ebx); for(mov(0,k); k<eax;add(1,k))do add(number,ebx); endfor; mov(ebx, r); stdout.put(r, nl); //Exponentiation elseif(operations=4) then mov(1,final); mov(number,eax); mov(number2,ebx); for(mov(0,i); i<ebx; add(1,i))do mov(0,ecx); for(mov(0,j); j0) do //Convert to Roman elseif(operations=5) then stdout.put("Enter Number to convert to roman", nl); stdin.get(x); mov(x,eax); while(eax>0) do 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=499) then stdout.put("XD"); sub(499,eax); elseif(eax=400) then stdout.put("CD"); sub(400,eax); elseif(eax=99) then stdout.put("IC"); sub(99,eax); elseif(eax=90) then stdout.put("XC"); sub(90,eax); elseif(eax=40) then stdout.put("XL"); sub(40,eax); elseif(eax=9) then stdout.put("IX"); sub(9,eax); elseif(eax=4) then stdout.put("IV"); sub(4,eax); elseif(eax>=500) then stdout.put("D"); sub(500,eax); elseif(eax>=100) then stdout.put("C"); sub(100,eax); elseif(eax>=50) then stdout.put("L"); sub(50,eax); elseif(eax>=10) then stdout.put("X"); sub(10,eax); elseif(eax>=5) then stdout.put("V"); sub(5,eax); elseif(eax>=1) then stdout.put("I"); sub(1,eax); endif; endwhile; endif; stdout.put(nl); end lab2;
Screenshots:
0 Responses
Stay in touch with the conversation, subscribe to the RSS feed for comments on this post.