Skip to content

Categories:

Lab 3

Lab Description:

In this lab we needed to create a program that displays a menu asking the user to perform the following operations like the sum of a number, the product of a number and the exponent of the number. We needed to define these numbers using factorial integer. Finding the sum definition and the product definition. We needed to program it using labels and jumps for decisions and repetition statements. The program should result a display and the value the program computes it should return to the original menu until it exit.

If the user choices to pick the first operation, the program is suppose to ask the user to enter one number into the system and the output results suppose to be the number we picked that got added. Same rules apply for the second operation, if we pick the second operation, the program will as us users to pick one value to enter into the program and the output results will be the value we picked that got multiplied. If we were to have picked the third operation, the program would of only asked us to pick only one value to represent n and then it will multiply 2 times depending on the amount of what n is  like for example, if the user picked n = 6 then the output will be 64 and it will look like 2^6 or 2*2*2*2*2*2. The disappointment part of this lab experiment is that we only had the addition part of the code working but not the multiplication and the exponential because  we had a lot of trouble shooting issues with our codes giving us a lot of unknown errors and we couldn’t figure out what the errors were.

Partner: Cesar Manon

program lab3;
#include("stdlib.hhf");
static
f:int32;
final:int32;
choices:int32;

begin lab3;

stdout.put("This is my calculator factorial",nl);
stdout.put("Enter the value following choices",nl);
stdout.put("For the following choices insert the given values, (1)the sum of a number,(2)the product of a number,(3)2^n,(4)Exit",nl);

stdin.get (choices);

cmp(choices,1);
 je Sum;
cmp(choices,2);
 je Prod;
cmp(choices,3);
 je Exp;

Sum:
 stdout.put("Enter the number",nl);
 stdin.get(f);
 mov(0,eax);
 jmp Sum1;

Sum1:
 add(f,eax);
 sub(1,f);
 cmp(f,0);
 jge Sum1;
 jnge BResult;
 BResult:
 mov(eax,final);
 stdout.put("The result is ", final, nl);
 mov(0,eax);
 mov(0,ebx);
 mov(0,ecx);
 mov(0,edx);

jmp Prod;

Prod:
stdout.put("Enter the number" ,nl);
stdin.get(f);

jmp Exp;

Exp:
 stdout.put("Enter the number",nl);
 stdin.get(f);
 mov(1,eax);
 shl(f,eax);//shl(2,1)
 mov(eax,final);
 stdout.put("The result is ", final, nl);

end lab3;

Screenshots:

PcYM6TcD7melNOu9-93g6GltlplWWZjv_RpsIKfwDYk

9CK8gpAXPevJlerGXbHJtsANIQj3dC-CvCXb0LVOLtw


0 Responses

Stay in touch with the conversation, subscribe to the RSS feed for comments on this post.



Some HTML is OK

or, reply to this post via trackback.