; PROGRAM: FACTORIAL OF A NUMBER
read macro num
mov ah, 01h
int 21h
sub al, 30h
mov num, al
endm
print macro s
mov ah, 09h
mov dx, offset s
int 21h
endm
data segment
msg db 'Enter Number: $'
num db ?
factis db 'Factorial is: $'
nl db 0dh,0ah,'$'
pfact db 11 dup('$')
data ends
code segment
assume cs:code, ds:data
start:
mov ax, data
mov ds, ax
print msg
read num
mov bl, num
mov bh, 00h
mov ax, 0001h
mov cx, ax
FACTORIAL:
mul cx
cmp cx, bx
jge STOPF
inc cx
jmp FACTORIAL
STOPF:
mov si, offset pfact
call hex2ascii ;converts hex in ax
print nl ;to ascii into si loc
print factis
print pfact
mov ah, 4ch
int 21h
hex2ascii proc near
mov cx, 0000h
REPDIV:
mov dx, 0000h
mov bx, 000ah
div bx
add dl, 30h
push dx
inc cx
cmp ax, 000ah
JGE REPDIV
add al, 30h
mov [si], al
inc si
SAVEASCI:
pop dx
mov [si], dl
inc si
loop SAVEASCI
STOP1:
mov [si], '$'
ret
hex2ascii endp
code ends
end start
**************************
OUTPUT
Z:\S5IT\masm>factorial
Enter Number: 4
Factorial is: 24
Z:\S5IT\masm>factorial
Enter Number: 0
Factorial is: 01
**************************
0 comments:
Post a Comment