32-bit Calculator using Labels and Jumps.

32-bit Calculator using Labels and Jumps.

Introduction:

In this lab, I will created a simple 32-bit calculator similar to the one created in Lab 1 and 2.  The calculator will display a menu asking the user what operation to perform.  The operations supported are Addition, Multiplication and Exponent.  Once the user selects an operation, the program will ask the user for the values and perform the operation. we cannot use the mul or imul or related HLA functions to perform the multiplication.  Also I will solely rely on labels and jumps.  we cannot use if, while, for, or related commands.  Once the program computers the value and displays the result, it should return to the original menu until the user chooses to exit.

To create this lab, the same code was used from Lab 2.  I removed all loops from the code and instead created a series of Labels.  The program was segmented into multiple parts each with its own label.  After the declaration or variables and the program begins, the beginning Label of the program takes place.  The beginning label then shows the user the menu, and prompts for the operation that they wish to complete.  Once the number is chosen of the operation, the program will jump to a different label of the program whether it be Addition,  Multiplication or Exponent.  At the end of each label, there is a jump statement to bring the user back to the beginning label.  To exit the program, a jump statement is used to bring the user from pressing any other key or number from the beginning label to the final label of the program which exits the program.

My partners is Fredrick Jah.

Code:

program lab3full;
#include ("stdlib.hhf");

static;
    n1: int32;
    n2: int32;
    a: int32;
    b:int32;
    option: int32;

begin lab3full;
menu:
    stdout.put("Enter 1 for the sum of a number, Enter 2 for the product of a number, Enter 3         for expn, Enter 4 to exit program",nl);

    stdin.get(option);
    mov(option, eax);    
    cmp(eax,1);
    je addition;
    cmp(eax,2);
    je product;
    cmp(eax,3);
    je expn;
    cmp(eax,4);
    je exit1;

addition:

    stdout.put("Enter number the get addition",nl);
    stdin.get(n1);
    mov(0,ebx);
    mov(n1,ecx);
    jmp whilelabel;

    whilelabel:
        add(ecx,ebx);
        sub(1,ecx);
             cmp(ecx,0);
        jnge endwhilelabel;
        jge whilelabel;    

    endwhilelabel:
        mov(ebx, n1);
        stdout.put("The answer is ", n1,nl); 
        mov(0,eax);mov(0,ebx);mov(0,ecx);mov(0,edx);
         jmp menu;

product:
    stdout.put("Enter number the get factorial",nl);
    stdin.get(n1);
    mov(n1,eax);
    sub(1, n1);
    jmp labelmul;

labelmul:
    add(eax,eax);
     sub(1,n1);
    cmp(n1,0);

jne labelmul;

    mov(eax,n1);
    stdout.put("The answer is ", n1,nl);
    mov(0,eax);mov(0,ebx);mov(0,ecx);mov(0,edx);
    jmp menu;

 expn:
    stdout.put("Enter number the get 2expn",nl);
    stdin.get(n1);
    //mov(1,edx);
    shl(n1,edx);
    mov(edx,n1);
    stdout.put("The answer is ", n1,nl); 
    jmp menu;

exit1: 

end lab3full;

 

 

 

Leave a Reply

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