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 and exponentiation 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 lab1; #include("stdlib.hhf"); static number:int32; number2:int32; final:int32; operations:int32; k:int32; j:int32; r:int32; i:int32; begin lab1; 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)Exit",nl); stdin.get (operations); if (operations>6) then stdin.get(operations); elseif (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); j<eax; add(1,j))do add(final,ecx); endfor; mov(ecx,final); endfor; stdout.put(final, nl); endif; end lab1;
Screenshots:
0 Responses
Stay in touch with the conversation, subscribe to the RSS feed for comments on this post.