Assembly Language Design and Write a FACTORIAL program FYI
Assembly Language:
Design and Write a FACTORIAL program – (FYI / DEFINITION: Its most basic occurrence is the fact that there are n! ways to arrange n distinct objects into a sequence.)
Create a program that will calculate the FACTORIAL of ANY number that is assigned.
Example: 5! (This means FIVE – FACTORIAL.) To calculate this, you start at the original number…in this case, 5.
Calculation: 5 * 4 * 3 * 2 * 1 equals the Result / that is, FIVE FACTORIAL
Solution
INCLUDE io.h
Cr EQU 0ah
 Lf EQU 0dh
 data SEGMENT
 p_n DB cr, lf, \'Enter value n: \',0
 p_res DB cr, lf, \'The factorial of given number is: \',0
 tmpstr DW 40 DUP (?)
 data ENDS
code SEGMENT
 ASSUME cs:code, ds:data
 start: mov ax, data
 mov ds, ax
 ;input number
 output p_n
 inputs tmpstr, 10
 atoi tmpstr
 ;initialize
 mov bx, ax
 mov ax, 01h
 ; find factorial
 Fact_loop: imul bx
 dec bx
 jnz Fact_loop
 ;Display factorial
 output p_res
 itoa tmpstr, ax
 output tmpstr
EndQ: mov al, 00h
 mov ah, 4ch
 int 21h
 code ENDS
 END start
===================================================================
Outptut:
Enter value n:
 5
 The factorial of given number is 120

