# Calculate the factorial of a number | 8086 Microprocessor

Here, we are going to learn how calculate the factorial of a given number using assembly program in 8086 Microprocessor?
Submitted by Ayush Sharma, on October 31, 2018

Problem statement:

Write an assembly language program for calculating the factorial of a number using 8086 microprocessor.

Assumptions:

• Starting address of program: 0400
• Input memory location: 0500
• Output memory location: 0600 and 0601

Point to be noted:

If the Given Number is a 16-bit number, the AX register is automatically used as the second parameter and the product is stored in the DX:AX register pair. This means that the DX register holds the high part and the AX register holds the low part of a 32-bit number.

Algorithm:

1. Input the Number whose factorial is to be find and Store that Number in CX Register (Condition for LOOP Instruction)
2. Insert 0001 in AX(Condition for MUL Instruction) and 0000 in DX
3. Multiply CX with AX until CX become Zero(0) using LOOP Instruction
4. Copy the content of AX to memory location 0600
5. Copy the content of DX to memory location 0601
6. Stop Execution

Program:

0400MOV CX, [0500]CX ← [0500]
0404MOV AX, 0001AX ← 0001
0407MOV DX, 0000DX ← 0000
040AMUL CXDX:AX ← AX * CX
040CLOOP 040AGo To [040A] till CX->00
0410MOV [0600], AX[0600]←AX
0414MOV [0601], DX[0601]←DX
0418HLTStop Execution

Explanation:

1. MOV CX, [0500] loads 0500 Memory location content to CX Register
2. MOV AX, 0001 loads AX register with 0001
3. MOV DX, 0000 loads DX register with 0000
4. MUL CX multiply AX with CX and store result in DX:AX pair
5. LOOP 040A runs loop till CX not equal to Zero
6. MOV [0600], AX store AX register content to memory location 0600
7. MOV [0601], DX store DX register content to memory location 0601
8. HLT stops the execution of program

What's New

Top Interview Coding Problems/Challenges!

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates