hello,
i learned at school how to calculate factorials then when arrived at home i coded a small program, dunno if it'll work in all cases but here it goes :
xor ebx, ebx
xor eax, eax
xor edx, edx
mov eax, 5d ; number to calculate the factorial
mov ecx, eax
fact:
dec eax
cmp eax, 0
je end
imul ecx, eax
jmp fact
end:
int 3 ; factorial in ecx
if anyone wants to optimize and\or do something. :grin:
The Keeper
i learned at school how to calculate factorials then when arrived at home i coded a small program, dunno if it'll work in all cases but here it goes :
xor ebx, ebx
xor eax, eax
xor edx, edx
mov eax, 5d ; number to calculate the factorial
mov ecx, eax
fact:
dec eax
cmp eax, 0
je end
imul ecx, eax
jmp fact
end:
int 3 ; factorial in ecx
if anyone wants to optimize and\or do something. :grin:
The Keeper
The decrement will set the zero flag, so the comparison after it is not needed.
Mirno
Mirno
:)
The Keeper:
Do you have any idea how big 5D! is?
You would need a special proc and for culculating
and for displayng the value (it's bigger then number of atoms
in the universe)
and if you not speed up process Stirling formula
n!~ sqrt(2pi*n*n^n*e^-n),n-> ..
it would take a lot of time since you are going to work
with Veeeeeery big numbers in a circle.
I'd recommend you to read school textbook first ;)
0D! is max that signed 32 integer can hold (7328CC00h).
Of course for n where n! < 8000 0000h you don't need any
proc - just a table with 13 dwords wich holds values
from 1! to 13!
so if you know n you can get n! just by
mov eax,n
dec eax
mov eax,dword ptr
The Keeper:
Do you have any idea how big 5D! is?
You would need a special proc and for culculating
and for displayng the value (it's bigger then number of atoms
in the universe)
and if you not speed up process Stirling formula
n!~ sqrt(2pi*n*n^n*e^-n),n-> ..
it would take a lot of time since you are going to work
with Veeeeeery big numbers in a circle.
I'd recommend you to read school textbook first ;)
0D! is max that signed 32 integer can hold (7328CC00h).
Of course for n where n! < 8000 0000h you don't need any
proc - just a table with 13 dwords wich holds values
from 1! to 13!
so if you know n you can get n! just by
mov eax,n
dec eax
mov eax,dword ptr
mov eax,n
dec eax
mov eax,dword ptr
mov eax,dword ptr [-4]
Of course. :)
uhm i need the factorial only of small numbers :P
thanks all
in the future i'll code something better.
thanks all
in the future i'll code something better.
int factorial (int n)
{
int i, res = 1;
for ( i = 1; i <= n; i ++)
res *= i;
return res;
}
can it be compared to mine ? in terms of supporting big numbers?
{
int i, res = 1;
for ( i = 1; i <= n; i ++)
res *= i;
return res;
}
can it be compared to mine ? in terms of supporting big numbers?