Experiment-4-Factorial of a number in 8086 8086 Programming by Ravinder Nath Rajotiya - April 19, 2019April 29, 20220 Share on Facebook Share Send email Mail Print Print Table of Contents Toggle AIM: Write a Program to generate Factorial of a numberSystem Requirement : Setting up the Trainer Kit:Flowchart:Algorithm to find the factorial of a number–Explanation of the code for factorial of a numberExecution of the ProgramAddress Map for DATA and RESULTExecuting The ProgramVerification of ResultViva Question AIM: Write a Program to generate Factorial of a number Objective: 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: Ensure that standard IBM PC/AT system keyboard is connected System is Powered ON Student has a handy opcode table for programming Use data Address as : For Program Code segment address : 1000 Offset address : 0200 For Data segment address : 0000 Offset address : 1300 Result : from offset 130A Flowchart: Figure 4.1 Factorial of a number Algorithm to find the factorial of a number– Input the Number whose factorial is to be find and Store that Number in CL Register (Condition for LOOP Instruction) Initialize AL=01, AH=00 Multiply CL with AL until CL become Zero(0) using LOOP Instruction Copy the content of AL to Destination Address Copy the content of AH to Destination Address + 01 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 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 05 Result Segment : Offset: 0000 : 130A and 0000 : 130B 78 00 (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 Cmd_Wrd= 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? Answer: 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? Answer: 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 Share on Facebook Share Send email Mail Print Print