$REGISTER NONE FUNCTION PBMAIN() PRINT "Number=?"; INPUT LINE c$ count&=VAL(c$) REM GET an estimate of the result AND find how many digits it has PRINT "Working out estimate of";count&;"!" y##=0 FOR r&=1 TO count& y##=y##+LOG10(r&) NEXT k##=EXP10( FRAC(y##)) PRINT count&;"!=";k##;"E"INT(y##);"approx." limit&=(INT(y##)+1)/LOG10(2)/32+1 :REM No.of 32 BIT words needed TO store answer limit2&=(INT(y##)+1)/9 :REM noof 32 BIT words needed TO store the decimal digits (9/WORD) %RDTSC=&h310f PRINT PRINT "Working out full answer.. this may take a long time." k&=0 cnt&=0 hwm&=0 DIM a???(limit&+2),f???(limit2&+2) a???=VARPTR(a???(0)) f???=VARPTR(f???(0)) t!=TIMER !mov ecx,count& !mov edi,a??? !mov [edi],ecx !dec ecx !mov eax,1 !mov hwm&,eax lp2: !mov edi,a??? !mov ebx,0 !mov esi,hwm& lp: !mov eax,[edi] !mul ecx !add eax,ebx !mov [edi],eax !adc edx,0 !add edi,4 !mov ebx,edx !dec esi !jns lp !mov edi,hwm& !add edi,edi !add edi,edi !add edi,a??? !mov eax,[edi] !test eax,&hffffffff !jz skip !inc hwm& skip: !dec ecx !jnz lp2 PRINT "Time=" TIMER-t! print t!=TIMER PRINT "Converting answer to decimal.. this may also take a long time." 'now need to convert to decimal !mov esi,limit2& !add esi,esi !add esi,esi !mov ecx,1000000000 !mov eax, limit& !mov hwm&,eax lp5: !mov ebx,hwm& !mov edi,ebx !add edi,edi !add edi,edi !add edi,a??? !mov edx,[edi] !test edx,&hffffffff !mov edx,0 !jnz lp4 !dec hwm& lp4: !mov eax,[edi] !div ecx !mov [edi],eax !sub edi,4 !dec ebx !jns lp4 !add esi,f??? !mov [esi],edx !sub esi,f??? !sub esi,4 !jns lp5 PRINT "time=",(TIMER-t!) PRINT PRINT "Writing answer to file " +TRIM$(STR$(count&))+"!.txt" n$= "c:\windows\desktop\"+TRIM$(STR$(count&))+"!.txt" OPEN n$ FOR OUTPUT AS #1 FOR k&=0 TO limit2& IF f???(k&)<>0 THEN EXIT FOR NEXT x$=TRIM$(FORMAT$(f???(k&),"#########")) PRINT #1,x$; FOR r& = k&+1 TO limit2& x$=FORMAT$(f???(r&),"000000000") PRINT #1,x$; NEXT CLOSE #1 'PRINT "lp=",HEX$(CODEPTR(lp)) 'PRINT "lp4=",HEX$(CODEPTR(lp4)) DO LOOP UNTIL INSTAT END FUNCTION REM 1000000!= 8.26393049892028 E 5565708