|
源代码网推荐
**---------------------------------- C program "caculate pi" 20000位 2s on PC 1.7GHz,RAM256,win2000 by sunnisdu@hotmail.com 山东大学 -------------------------------------*/ #include "stdafx.h" #include <stdio.h> #include <stdlib.h> #include <string.h> #include <math.h> #include <time.h>
unsigned int *arrBase; unsigned int *arrCac; unsigned int *arrResult; unsigned int DecNum=1000; unsigned int NUM; unsigned int StartPos; unsigned int StartPos4; void initArr(unsigned int* arr) { _asm{ mov ecx, NUM mov ebx, arr _init: mov dword ptr [ebx],0 add ebx,4 loop _init } } void addArr(unsigned int* arr,unsigned int* arr2) { __asm{ mov ecx, NUM mov esi, arr mov edi, arr2 mov eax, ecx shl eax, 2 add esi, eax add edi, eax clc _add: sub esi, 4 sub edi, 4 mov eax, [edi] adc [esi],eax loop _add }
} void subArr(unsigned int* arr,unsigned int* arr2) { _asm { mov ecx, NUM dec ecx mov esi, arr mov edi, arr2 clc _sub: mov eax, [edi+ecx*4] sbb [esi+ecx*4],eax loop _sub } } void mulArr(unsigned int* arr,unsigned int num) { _asm{ mov ecx,NUM mov ebx,ecx shl ebx,2 add ebx,arr xor edx,edx mov edi,num xor esi,esi _mul: sub ebx,4 mov eax,[ebx] mul edi add eax,esi mov [ebx],eax adc edx,0 mov esi,edx loop _mul } } void divArr(unsigned int *arr,unsigned int num) { __asm{ mov ebx,arr mov ecx,NUM xor edx,edx _div: mov eax,[ebx] div num mov [ebx], eax add ebx, 4 loop _div } } /* caculate arctan(1/num), and store the result to arr */ void arctanX(unsigned int num) { unsigned int dd; unsigned int remain=0; unsigned int loopN; dd=(long)num*num; loopN=(int)(32*NUM*log(2)/log(5)); initArr(arrBase); initArr(arrCac); arrBase[0]=1; divArr(arrBase,num); StartPos=1; _asm mov ebx,1
forloopN: _asm mov eax, StartPos _asm shl eax, 2 _asm mov StartPos4,eax _asm mov edi, arrCac _asm add edi, StartPos4 _asm mov esi, arrBase _asm add esi, StartPos4 _asm mov ecx, NUM _asm sub ecx, StartPos _asm xor edx, edx _asm test ebx,2 _asm jnz cond2 cond1: fori1: _asm mov eax, [esi] _asm div ebx addCac: _asm add [edi], eax _asm jnc fori11 _asm push edi addCarry: _asm sub edi, 4 _asm add dword ptr [edi], 1 _asm jc addCarry _asm pop edi fori11: _asm add edi, 4 _asm add esi, 4 _asm loop fori1 _asm jmp divarrBase cond2: fori2: _asm mov eax, [esi] _asm div ebx subCac: _asm sub [edi], eax _asm jnc fori22 _asm push edi subCarry: _asm sub edi, 4 _asm sub dword ptr [edi],1 _asm jc subCarry _asm pop edi fori22: _asm add esi, 4 _asm add edi, 4 _asm loop fori2 divarrBase: _asm xor eax, eax _asm xor edx, edx _asm mov esi, dd _asm mov edi, arrBase _asm mov ecx, NUM forBase: _asm mov eax,[edi] 源代码网供稿.
|