, . .

. Y = N!,

Y = 1, N = 0,

Y = 1 * 2 ... * N, N > 1

N < 0 -1, .

:

unsigned fact(int n){

if(n < 0) return -1;

if(n == 0)return 1

return (n * fact(n - 1));

}

;

ideal

p586

model flat

extrn ExitProcess:proc

dataseg

n dd 4

x dd ?

codeseg

proc fact

push ebp

mov ebp,esp; [ebp+8]-n

push ebx ecx edx

mov ebx, [ebp+8]

test ebx,ebx

js m1; <0

jz m2; ==0

mov ecx, ebx

dec ebx

push ebx

call fact

mul ecx

jmp short m3

m1: mov eax,0

jmp short m3

m2: mov eax,1

m3: pop edx ecx ebx

pop ebp

ret 4

endp fact

begin:

push [n]

call fact

call ExitProcess

end begin

"" , , . , , K * N, K- , , N -