section .data
num db 5
result db 0,0,0,0
section .text
global _start
_start:
mov ax,1
mov bh,0
mov bl,[num]
call fact
mov rsi,result ; convert to ascii and display
mov cl,4 ; iter1 ax=78 iter2
up:
rol ax,4 ; ax=87 ax = 78
mov dx,ax ; dx = 87 dx=78
and ax,0fh ; ax=07 ax=08
cmp al,09
jbe skip ;if given digit is greater than 9,cy=0 else cy=1(if cy=1 then jump)
add al,07
skip:
add al,30h
mov [rsi],al ; result[0]=37 result[1]=38
inc rsi ; result++
mov ax,dx ; ax = 87 ax = 78
dec cl ; cl= 3 cl = 2
jnz up
mov rax,1
mov rdi,1
mov rsi,result ; display string i.e. result= 78
mov rdx,4
syscall
mov rax,60
mov rdi,0
syscall
; procedure - recursive iteration 1 2 3 4
fact:
cmp bx,1
jne next
ret
next:
mul bx ; ax*bx ax =5 20 60 120
dec bx ; bx = 4 3 2 1
call fact
ret
To embed this project on your website, copy the following code and paste it into your website's HTML: