Lab 3

Lab Description:

This lab consist of creating a simple 32-bit calculator that perform the fallowing operations: addition, subtraction, and multiplication. A menu should display asking the user which operation would they like to perform. After choice selection a menu display would ask the user to enter the value and then perform the operation selected. This program is set to run until the user select 0 to exit. I implemented the lab using mov instructions,  jump and labels.

Code:

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

static
    choice: int32;
    n1:int32;
    n2:int32;
    x:int32;
    a:int32;
    b:int32;

begin lab3calculator;

RepeatLabel:						
    stdout.put(nl);
    stdout.put("This calculator perform the operation chosen by the user.",nl,"The program will run until the user presses 0 to exit.",nl);
    stdout.put(nl);
        stdout.put("What operation would you like to perform?",nl"Please:",nl);
        stdout.put(nl);
        stdout.put("Press 1 for Addition");
        stdout.put(nl);
        stdout.put("Press 2 for Subtraction");
        stdout.put(nl);
        stdout.put("Press 3 for Multiplication");
        stdout.put(nl);
    	stdout.put("Press 0 to excit",nl);
    	stdout.put(nl);
        stdout.put("Please enter you choice here:");
    stdin.get(choice);
        mov(choice, ecx);
	mov(1,ebx);
	cmp(ecx,ebx);
	jne SkipStmts1;
            stdout.put(nl);
            stdout.put("You chose ADDITION, how cool.",nl);
            stdout.put(nl);            
            stdout.put("Please enter the first value: ");    
            stdin.get(n1);
            mov(n1, eax);
            stdout.put(nl);
            stdout.put("Please enter the second value: ");
            stdin.get(n2);
            mov(n2, ebx);
            add(eax, ebx);
            mov(ebx, x);
            stdout.put(nl);
            stdout.put("The sum of ",n1," and ",n2," is: ", x, nl);
	SkipStmts1:
       		 mov(2,ebx);
		 cmp(ecx,ebx);
	jne SkipStmts2;
            stdout.put(nl);
            stdout.put("You chose SUBTRACTION, how cool.",nl);
            stdout.put(nl);            
            stdout.put("Please enter the first value: ");    
            stdin.get(n1);
            mov(n1, ebx);
            stdout.put("Please enter the second value: ");
            stdin.get(n2);
            mov(n2,eax);      
            sub(eax,ebx);
            mov(ebx,a);
            stdout.put(nl);
            stdout.put("The difference between ",n1," and ",n2," is: ",a, nl);
 	SkipStmts2:
		mov(3,ebx);
		cmp(ecx,ebx);
	jne SkipStmts3;
            stdout.put(nl);
            stdout.put("You chose MULTIPLICATION, how cool.",nl);
            stdout.put(nl);                             
            stdout.put("Please enter the first value:");
	    stdin.get(a); 
	    mov(a,eax);
	    stdout.put("Please enter the second value:");
            stdin.get(b);
                mov(b,ebx);
		mov(1,b);
			WhileLabel:	
				cmp(b,ebx);
				jnl WhileDone;
				add(a,eax);
			        inc(b);
				jmp WhileLabel;		
			WhileDone:
		mov(eax,x);
	    stdout.put("the product is:",x, nl);
    	SkipStmts3:
mov(0,edx);
cmp(edx,ecx);
jne RepeatLabel;
end lab3calculator;

Screen-Shots:

Addition:

Screenshot from 2013-10-29 01:45:57

Subtraction:

Screenshot from 2013-10-29 01:46:56

Multiplication:

Screenshot from 2013-10-29 01:47:36

Exit:

Screenshot from 2013-10-29 01:48:00

Leave a Reply

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