shr offtop,1
В детстве баловался:
Код
program FuckToReal;
const DataSize = 16384;
ResultSize = 60000;
type PResult = ^TResult;
TResult = array[0..0] of Char;
var Data: array[0..DataSize - 1] of Word;
Result: PResult;
Digits, N: Integer;
SymbolIndex, i: Word;
begin
GetMem(Result, ResultSize);
Write('N>');
Readln(N);
FillChar(Data, SizeOf(Data), 0);
Data[0] := 1;
Digits := 1;
Write('Calculating... ');
{ Calulating of factorial by long binary multiplication }
asm
push bp
mov bp,N
@@NextPass:
push ds
pop es
lea si,Data
mov di,si
cld
xor bx,bx
mov cx,Digits
@@NextDigit:
lodsw
mul bp
add ax,bx
adc dx,0
stosw
mov bx,dx
loop @@NextDigit
or bx,bx
jz @@Exit
inc Digits
mov cx,1
jmp @@NextDigit
@@Exit:
dec bp
cmp bp,1
ja @@NextPass
pop bp
end;
Writeln('Done');
Write('Converting... ');
{ Building a decimal representation of long binary number }
SymbolIndex := ResultSize;
asm
push bp
mov bp,Digits
dec bp
shl bp,1
lea bp,Data[bp]
les di,Result
add di,ResultSize-1
mov bx,10
std
@@NextSymbol:
xor dx,dx
mov si,bp
cmp [si],bx
jae @@NextDigit
sub bp,2
@@NextDigit:
lodsw
div bx
mov [si+2],ax
cmp si,offset Data
jae @@NextDigit
mov al,dl
add al,'0'
stosb
dec SymbolIndex
cmp bp,offset Data
jae @@NextSymbol
pop bp
end;
Writeln('Done');
for i := SymbolIndex to ResultSize - 1 do Write(Result^[i]);
Writeln;
FreeMem(Result, ResultSize);
end.
Считала 10000! (с точностью до едениц) на Pentium 100 MHz за 37 секунд.