global _start
_start :

section .text

%macro disp_macro 2
mov rax,1
mov rdi,1
mov rsi,%1
mov rdx,%2
syscall
%endm

%macro accept 2
mov rax,0
mov rdi,0
mov rsi,%1
mov rdx,%2
syscall
%endm

disp_macro msg1,len1
accept num,3
call convert
cmp al,01h
ja c1
disp_macro msg2,len2
jmp exit

c1:push rax
disp_macro msg3,len3
pop rax
mov rcx,rax
dec rcx

c2:push rax
dec rax
cmp rax,01
ja c2

c3:pop rbx
mul rbx
dec rcx
jnz c3
call display

exit:
%macro exitm 0
mov rax,60
mov rdi,0
syscall
%endm

exitm

display:
mov rsi,disparr+3
mov rcx,4

a2:mov rdx,0
mov rbx,10H
div rbx
cmp dl,09H
jbe a1
add dl,07h

a1:add dl,30H
mov[rsi],dl
dec rsi
dec rcx
jnz a2

mov rax,1
mov rdi,1
mov rsi,disparr
mov rdx,4
syscall

ret


convert:
mov rsi,num
mov al,[rsi]
cmp al,39h
jle l1
sub al,07h
l1:sub al,30h
rol al,04
mov bl,al
inc rsi
mov al,[rsi]
cmp al,39h
jle l2
sub al,07h
l2:sub al,30h
add al,bl

ret


section .data
msg1 db "Enter the Number:",0Ah
len1 equ $-msg1

msg2 db "  The factorial is 1:",0Ah
len2 equ $-msg2

msg3 db "The factorial is: ",0Ah
len3 equ $-msg3


section .bss
num resb 10
no resb 10
disparr resb 20

Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: