You are on page 1of 10

Register No.

: 20BCE1477 Name: RAMINEDI SANTHOSH

Date: 02/02/2022 Exp: 4 Factorial, permutation and combination

Aim:

To find factorial, permutation and combination of a number using MASM


assembler

Tool Used:

Assembler - MASM 611

Algorithm for Factorial:


1. Initialize a counter of the number.
2. Looping until counter becomes for equal to number.
3. Multiplying BX value with AX register and incrementing BX value till it reaches
value of CX register.
4. Factorial of a number is stored in AX register.

Program for Factorial of a number:


Register No.: 20BCE1477 Name: RAMINEDI SANTHOSH

Sample Input:

Input: 5

Sample Output:

Output: 120 (78 in Hexa-decimal)

Register/ Memory Contents for I/O:

Snapshot of the Output:


Register No.: 20BCE1477 Name: RAMINEDI SANTHOSH

Algorithm for Permutation:


1. Let c and n are input for permutation.
2. Finding factorial of the c using factorial algorithm.
3. Finding factorial of the (c-n) using factorial algorithm.
4. Dividing c! / (c-n)! and storing result in AX register.

Program for Permutation:


Register No.: 20BCE1477 Name: RAMINEDI SANTHOSH

Sample Input:

Input: c=5 and n=2

Sample Output:

Output: 20 (14 in Hexa-decimal)


Register No.: 20BCE1477 Name: RAMINEDI SANTHOSH

Register/ Memory Contents for I/O:


Register No.: 20BCE1477 Name: RAMINEDI SANTHOSH

Snapshot of the Output:


Register No.: 20BCE1477 Name: RAMINEDI SANTHOSH

Algorithm for Factorial:


1. Let c and n are input for permutation.
2. Finding factorial of the c using factorial algorithm.
3. Finding factorial of the (c-n) using factorial algorithm.
4. Finding factorial of the n using factorial algorithm.
5. Dividing c! / (n!) (c-n)! and storing result in AX register.

Program for Combination:


Register No.: 20BCE1477 Name: RAMINEDI SANTHOSH

Sample Input:

Input: c=5 and n=2

Sample Output:

Output: 10 (A in Hexa-decimal)
Register No.: 20BCE1477 Name: RAMINEDI SANTHOSH

Register/ Memory Contents for I/O:


Register No.: 20BCE1477 Name: RAMINEDI SANTHOSH

Snapshot of the Output:

Result:

Factorial, permutation and combination is performed using MASM


Assembler.

You might also like