include 'emu8086.inc' lf equ 0ah cr equ 0dh data segment N dw 0 data ends stack segment dw 200h dup(0) stack ends code segment start: ; set segment registers: mov ax, data mov ds, ax CALL CLEAR_SCREEN PRINT cr PRINT lf PRINT 'Enter a Number : ' CALL SCAN_NUM ;cx = entered number CALL Fact1 ; parameter is in cx result is in ax PRINT cr PRINT lf PRINT 'Nonrecursive Factorial : ' CALL PRINT_NUM_UNS CALL Fact2 ; parameter is in cx result is in ax PRINT cr PRINT lf PRINT 'Recursive Factorial : ' CALL PRINT_NUM_UNS ; wait for any key.... mov ah, 1 int 21h mov ax, 4c00h ; exit to operating system. int 21h code ends DEFINE_CLEAR_SCREEN DEFINE_SCAN_NUM DEFINE_PRINT_STRING DEFINE_PRINT_NUM DEFINE_PRINT_NUM_UNS ; required for print_num. DEFINE_PTHIS Fact1 PROC ; cl is parameter1 and equal to N mov ch , 0 mov si , 2 mov ax , 1 For1: cmp si , cx ja endFor1 ; jump if (si>cx) mul si ; dx:ax = ax * si inc si ; si++ jmp For1 endFor1: ret Fact1 ENDP Fact2 PROC ; cl is parameter1 and equal to N mov ch , 0 if: cmp cl , 1 ja else mov ax , 1 ret else: push cx dec cx call Fact2 ; parameter is in cx result is in ax pop cx mul cx ret Fact2 ENDP PushALL MACRO push ax push bx push cx push dx push si push di push bp push sp PushALL ENDM PopALL MACRO pop sp pop bp pop di pop si pop dx pop cx pop bx pop ax PopALL ENDM end start ; set entry point and stop the assembler.