27 lines
333 B
NASM
27 lines
333 B
NASM
|
|
||
|
BITS 32
|
||
|
|
||
|
GLOBAL fact
|
||
|
|
||
|
SECTION .text
|
||
|
|
||
|
fact:
|
||
|
|
||
|
mov eax, [esp+4] ; n в eax
|
||
|
cmp eax, 1
|
||
|
je ret1 ; 1 ! = 1
|
||
|
|
||
|
push ecx ; save used ecx
|
||
|
|
||
|
dec eax ; eax = n-1
|
||
|
push eax
|
||
|
call fact ; в eax (n-1)!
|
||
|
pop ecx ; ecx = n
|
||
|
inc ecx
|
||
|
mul ecx ; eax *= ecx
|
||
|
|
||
|
pop ecx ; restore used ecx
|
||
|
|
||
|
ret1:
|
||
|
ret
|