Factorial: Difference between revisions
Content added Content deleted
Line 6,175: | Line 6,175: | ||
end;</lang> |
end;</lang> |
||
=== Iterative FreePascal === |
=== Iterative FreePascal === |
||
{$mode objFPC}{R+} |
|||
<lang pascal> |
|||
FUNCTION Factorial ( n : qword ) : qword; |
|||
(* Update for version 3.2.0 *) |
|||
(* Factorial works until 20! , which is good enough for me for now *) |
(* Factorial works until 20! , which is good enough for me for now *) |
||
(* replace qword with dword and rax,rcx with eax, ecx for 32-bit *) |
(* replace qword with dword and rax,rcx with eax, ecx for 32-bit *) |
||
(* for Factorial until 12! *) |
(* for Factorial until 12! *) |
||
VAR |
|||
F: qword; |
|||
BEGIN |
BEGIN |
||
Line 6,186: | Line 6,193: | ||
asm |
asm |
||
mov $1, %rax |
mov $1, %rax |
||
mov n, %rcx |
mov n, %rcx |
||
.Lloop1: |
.Lloop1: |
||
Line 6,193: | Line 6,200: | ||
loopnz .Lloop1 |
loopnz .Lloop1 |
||
mov %rax, |
mov %rax, F |
||
end; |
end; |
||
Result := F ; |
|||
END;</lang> |
END;</lang> |
||
=== Recursive === |
=== Recursive === |
||
<lang pascal>function factorial(n: integer): integer; |
<lang pascal>function factorial(n: integer): integer; |