AIM: Write a Program to generate Factorial of a number


To understand the concept of multiplication using direct MUL instruction in 8086. To understand how to use 16-bit results

To analyze the process and the result

System Requirement : 

8086 Trainer Kit with Key Board

Setting up the Trainer Kit:

  1. Ensure that standard IBM PC/AT system keyboard is connected
  2. System is Powered ON
  3. Student has a handy opcode table for programming
  4. Use data Address as :
    1. For Program Code

segment address : 1000       Offset address : 0200

  1. For Data

segment address  : 0000      Offset address : 1300

Result               : from offset 130A



Figure 4.1 Factorial of a number

Algorithm to find the factorial of a number–

  1. Input the Number whose factorial is to be find and Store that Number in CL Register (Condition for LOOP Instruction)
  2. Initialize AL=01, AH=00
  3. Multiply CL with AL until CL become Zero(0) using LOOP Instruction
  4. Copy the content of AL to Destination Address
  5. Copy the content of AH to Destination Address + 01
  6. Stop Execution

Explanation of the code for factorial of a number

Code Segment Op-Code Mnemonic Explanation
1300: 0200 BE 0013 MOV SI, 1300h ; set source index
1300: 0203 BF 0A 13 MOV DI, 130Ah ; set destination index
1300: 0206 8A 0C MOV CL, [SI] ; CL loaded with 8-bit FROM 1300
1300: 0208 B0 01 MOV AL, 01 ; AL is initialized to 01h
1300: 020A B4 00 MOV AH, 00 ; AH register initialized to 0000
1300: 020C F6 E1 Back: MUL CL ; Multiply  AX <- AL * CL
1300: 020E FE C9 DEC CL ; Decrement multiplier by 1
1300: 0210 75 FA JNZ Back ; Go To back label
1300: 0212 88 05 MOV [DI], AL ; store low part of result
1300: 0214 47 INC DI ; increment destination index
1300: 0215 88 25 MOV [DI], AH ; Store high byte of result
1300: 0217 F4 HLT ; stops executing  program

Execution of the Program

Address Map for DATA and RESULT

Data Segment Address DATA
Number whose factorial is needed Segment  : Offset:

0000 : 1300



Result Segment  : Offset:

0000 : 130A and

0000 : 130B





(0078)hex = decimal (120)

Executing The Program

Key Pressed/Action Display on LCD
Press G  from Keyboard BURST
Press Enter Segm_Adr
0000 Press Enter Ofst
0200 Press Enter Wait


Do not press the Reset Key; Check the result by using Sub_Mir Command

Verification of Result

TRY   Address High Byte Low Byte
1st Number 0000:1300      xx
Factorial Value->
Address-> 0000:130B 0000:130A
2nd Number 0000:1300      xx
Factorial Value->
Address-> 0000:130B 0000:130A
3rd Number 0000:1300      xx
Factorial Value->
Address-> 0000:130B 0000:130A

Viva Question

Q.1: How do you use MUL instruction for 8-bit multiplication?


Syntax ;           MUL CL for 8-bit;           Result in AX

When we multiply two 8-bit number, result will be a 16-bit value. For example if we multiply two 8-bit numbers available in AL and CL the execution of MUL CL will result in AX <- AL*CL

We store content of AL at low address and AH at high address

Q.2: How do you use MUL instruction for 16-bit multiplication?


Syntax :           MUL CX for 16-bit value Result in DX:AX

When we multiply two 16-bit number, result will be a 32-bit value. Execution of MUL CX will result in DX : AX  <- AX*CX

We store result at four memory locations


Updated: April 27, 2019 — 2:29 pm

Leave a Reply

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

care4you © 2020 Connect On Facebook DMCA.com Protection Status