model small
.data
x db "enter a no. $"
y db "factorial $"
.code
.startup

mov ah,09h
lea dx,x
int 21h

mov ah,01h
int 21h
sub al,30h
mov bl,0ah
mul bl
mov bl,al
mov ah,01h
int 21h
sub al,30h
add al,bl

mov ah,09h
lea dx,y
int 21h

mov bl,al

l:
dec bl
mul bl
cmp bl,01h
jne l

mov ah,09h
lea dx,y
int 21h
cmp al,64h
jl l2

mov ch,al
mov bh,0ah
div bh
mov dh,ah
div bh
mov dl,al
add dl,30h
mov ah,02h
int 21h
mov dl,ah
add dl,30h
mov ah,02h
int 21h
mov dl,dh
add dl,30h
mov ah,02h
int 21h
jmp e

l2:

mov bh,0ah
div bh
mov dl,al
add dl,30h
mov ah,02h
int 21h
mov dl,ah
add dl,30h
mov ah,02h
int 21h

e:
.exit
end

Hello, as to your question:

add al,bl  ; AL now contains value user entered in DECimal
mov ah,09h
lea dx,y
int 21h
; but AL is destroyed after here
; after this MS-DOS call AL is overwritten with dollar-sign char of
; printed string, DOS uses fast putchar to write to console
mov bl,al

; if AL was not destroyed the following routine you entered would 
; calculate correctly the factorial of the number
l: 
dec bl
mul bl
cmp bl,01h
jne l

mov ah,09h
lea dx,y
int 21h
cmp al,64h
jl l2

; DIV instruction divides 8-bit divisor by 16-bit divisor in AX
; by here in the code AH is uninitialized, and contains 24h, 24xx / 10 ?
; hence you need to initialize AH before the division
; *multiplier is explicit operand of DIVide

; control never reaches here you only allowed user to enter a two
; digit decimal value between 00-99 which is less than 64h

mov ch,al 
mov bh,0ah 
div bh    
mov dh,ah 
div bh    
mov dl,al
add dl,30h
mov ah,02h
int 21h
mov dl,ah ; ? AH still contains number of function call
add dl,30h
mov ah,02h
int 21h
mov dl,dh
add dl,30h
mov ah,02h
int 21h
jmp e

l2: ; this code looks fine, control should have reached here, except
    ; the accumulator is not preserved before MS-DOS call

mov bh,0ah
div bh
mov dl,al
add dl,30h
mov ah,02h
int 21h
mov dl,ah ; ? AH still contains number of function call 
add dl,30h
mov ah,02h
int 21h

Add this, made it work in my assembler...
When I assembled this I made it into a .COM

mov ah,01h
int 21h
sub al,30h
mov bl,0ah
mul bl
mov bl,al
mov ah,01h
int 21h
sub al,30h
add al,bl

push ax ; here
mov ah,09h
lea dx,  y
int 21h
pop ax ; here

mov bl,al

l:
dec bl
mul bl
cmp bl,01h
jne l

push ax ; here
mov ah,09h
lea dx,  y
int 21h
pop ax ; here
xor ah, ah ; here
cmp al,64h
jl l2

mov ch,al
mov bh,0ah
div bh     
mov dh,ah
div bh
mov dl,al
add dl,30h
mov ah,02h
int 21h
mov dl,ah
add dl,30h
mov ah,02h
int 21h
mov dl,dh
add dl,30h
mov ah,02h
int 21h
jmp e

l2:

mov bh,0ah
div bh
mov dl,al
add dl,30h
push ax ; here
mov ah,02h
int 21h
pop ax ; here
mov dl,ah
add dl,30h
mov ah,02h
int 21h

Have a good day...

This article has been dead for over six months. Start a new discussion instead.