Morgan - Numerical Methods (523161), страница 46
Текст из файла (страница 46)
this is in radians.;expects argument in quadword format, expects to return the same;input must be x^2<1;taylorsinproc uses bx cx dx di si, argument:qword, sine:wordinvoke polyeval, argument, sine, addr polysin, 10rettaylorsin endp; ******;polyeval- evaluates polynomials according to Horner's rule;expects to be passed a pointer to a table of coefficients,;a number to evaluate, and the degree of the polynomial;the argument conforms to the quadword fixedpoint formatpolyeval408proc uses bx cx dx di si, argument:qword, output :word,coeff:word, n:bytelocalcf:qword, result[8]:wordpushfcldsubax, axTRANS.ASM AND TABLE.ASMreprepmovleastoswleamovstoswcx, 4di, word ptr cfmovsubmovsi, word ptr coeffbx, bxbl, byte ptr nshlshlshlbx, 1bx, 1bx, 1addmovmovmovmovleaaddadcsi, bxax, wordbx, wordcx, worddx, worddi, wordword ptrword ptradcadcword ptr [di][4], cxword ptr [di][6], dxinvokesmul64, argument, cf, addr resultlealeamovmovswsi, word ptr result [4]di, word ptr cfcx,4decjnsbyte ptr neval;clear the accumulatordi, word ptr resultcx,8eval:rep;point at table;point at coefficient of n;degree;this is the beginning of our;approximation;multiply by eight for the;quadwordptr [si]ptr [si][2]ptr [si][4]ptr [si][6]ptr cf[di], ax[di][2], bx;add new coefficient to;accumulator;decrement pointer409NUMERICAL METHODSpolyeval_exit:movleamovmovswreppopfretpolyeval endpdi, word ptr outputsi, word ptr cfcx,4;write to the output;;log using a table and linear interpolation;logarithms of negative numbers require imaginary numbers;natural logs can be derived by multiplying result by 2.3025;lgl0proc uses bx cx si di, argument:word, logptr:wordlocalpowers_of_two:bytepushfstdrepsubmovmovaddstoswax,axcx, 4di, word ptr logptrdi, 6movaddmovaddmovorsi, word ptr logptrsi, 6di, word ptr argumentdi, 6ax, word ptr [di]ax, axexitjsrepe410;increment down for zero check;to comesubmovcmpsw;clear log output;point at output which is zero;most significant word;point at input;most significant word;we don't do negativesax, axcx, 4;find the first nonzero, or;returnTRANS.ASM AND TABLE.ASM;zerojeexitreposition_argument:si,movsi,adddi,movinccxmovax,subax,shlax,subsi,shlax,shlax,shlax,movbl,movswrepmovmovkeep_shifting:orjsshlrclrclrclincjmpdone_with_shiftmovmovsubmovshlword ptr argument6si4cx1ax111al;shift so msb is a one;point at input;most significant word;shift the one eight times;make this a one;determine number of emptywords;words to bytes;point to first nonzero word;multiply by eight;shiftsi, word ptr argumentax, word ptr [si][6]ax, axdone_with_shiftword ptr [si][0], 1word ptr [si][2], 1word ptr [si][4], 1ax, 1blshort keep-shifting;shift until msb is a oneword ptr [si][6],axbyte ptr powers_of_two, blbx, bxbl, ahbl, 1;ax will be a pointeraddbx, offset word ptr logl0_tblmovax, word ptr [bx];count shifts as powers of two;normalize;will point into 127 entry table;get rid of top bit to form;actual pointer;linear interpolation;get first approximation (floor)411NUMERICAL METHODSincincmovbxbxbx, word ptr [bx]subxchgbx, axax, bxmulmovsubaddbyte ptr [si][6]al, ahah, ahax, bxget_power:movbl, bytebh, bhbx,1bx,1si, wordsi, bxdx, dxax, worddx, worddi, wordword ptrmovsubmovmovword ptr [di][4],dxcx,cxword ptr [di],cxword ptr [di][6],cxpopfretlgl0412endp;multiply by fraction bits;drop fractional places;add interpolated value to;original;need to correct for power;of twobl, 31subsubshlshlleaaddsubaddadcmovmovexit:;and following approximation;(ceil);find differenceptr powers_of_two;point into this tableptr logl0_powerptr [si]ptr [si][2]ptr logptr[di][2],ax;add log of power;write result to qword fixed;pointTRANS.ASM AND TABLE.ASM;sqrt using a table and linear interpolation;this method has real problems as the powers increasesqrtt proc uses bx cx si di, argument:word, sqrptr:wordlocalpowers-of_two:bytepushfstdreprepe;increment upsubmovmovaddstoswax,cx,di,di,ax4word ptr sqrptr6movaddmovaddmovorjssi, word ptr sqrptrsi, 6di, word ptr argumentdi, 6ax, word ptr [di]ax, axexitsubmovcmpswax, axcx, 4jeexit;clear sqrt output;clear sqrt output;pointer to input;we don't do negatives;find the first nonzero, or;return;zeroreposition_argument:movsi,addsi,movdi,inccxmovax,subax,shlax,subsi,shlax,word ptr argument6si4cx1ax1;shift the one eight times;this was a zero;determine number of emptywords;bytes to words;point to first nonzero word413NUMERICAL METHODSshlshlmovmovswrepmovmovkeep_shifting:orjsshlrclrclrclincjmpax, 1ax, 1bl, alax, axdone_with_shiftword ptr [si][0], 1word ptr [si][2], 1word ptr [si][4], 1ax, 1blshort keep_shiftingdone_with_shiftmovmovsubmovshladdword ptr [si][6],axbyte ptr powers_of_two, blbx, bxbl, ahbl, 1bx, offset word ptr sqr_tbl;multiply by eight;shiftsi, word ptr argumentax, word ptr [si][6];normalizelinear interpolation414movincincmovsubxchgax,bxbxbx,bx,ax,mulmovsubaddbyte ptr [si][6]al, ahah, ahax, bxmovsubshlbl, byte ptr powers_of_twobh, bhbx,1word ptr [bx]word ptr [bx]axbx;multiply by fraction bits;factor out fractional places;add interpolated value to;originalTRANS.ASM AND TABLE.ASMleaaddsubmulmovmovmovsubmovmovsi, wordsi, bxdx, dxword ptrdi, wordword ptrword ptrcx,cxword ptrword ptrptr sqr_power[si]ptr sqrptr[di][2],ax[di][4],dx;multiply by inverse of root[di],cx[di][6],cxexit:popfretsqrtt endp;;sines and cosines using a table and linear interpolation;(degrees)dcsin proc uses bx cx si di, argument:word, cs_ptr:word, cs_flag:bytelocalpowers_of_two:byte, sign:bytepushfstdrepsubmovmovmovaddstoswaddmovmovaddmov;increment downax, axbyte ptr sign, alcx,4di, word ptr cs_ptrdi,6di,si,di,di,cx,8diword ptr argument64;clear sign flag;clear sin/cos output;first check arguments for zero;reset pointer415NUMERICAL METHODSrepecmpswjejmp;find the first nonzero, or;returnzero-exitprepare-argumentszero_exit:cmpjnejmpbyte ptr cs_flag, alcos_0exitincincadddecmovjmpaxaxsi,axaxword ptr [si][4],axexit;ax is zero;sin(0) = 0cos_0:prepare_arguments:movmovsubmovidivorjnsaddsi,ax,dx,cx,cxword ptr argumentword ptr [si][4]dx360dx, dxquadrantdx, 360quadrant:movbx, dxmovsubmovdivax, dxdx, dxcx, 90cxcmpbyte ptr cs_flag, 0;point di at base of output;make ax a one;cos(0) = 1;one;get integer portion of angle;modular arithmetic to reduce;angle;we want the remainder;angle has gotta be positive for;this;to work;we will use this to compute the;value of the function;put angle in ax;and this to compute the sign;ax holds an index to the;quadrantswitch:416;what do we wantTRANS.ASMjecos_range:cmpjgjmpcchk_180:cmpjgnotnegaddANDTABLE.ASMdo-sinax, 0cchk_180walk_upjmpax, 1cchk_270byte ptr signbxbx, 180walk_backcchk_270:cmpjgnotsubjmpax, 2clast_90byte ptr signbx, 180walk-upclast_90:negaddjmpbxbx, 360walk_backdo_sin:;use incrementing method;set sign flag;use decrementing method;set sign flag;find the range of the argumentcmpjgnegaddjmpschk_180:cmpjgax, 0schk_180bxbx, 90walk_back;use decrementing methodax, 1schk_270417NUMERICAL METHODSsubjmpschk_270:cmpjgnotnegaddjmpslast_90:notsubjmp:;;walk_up:shladdmovmovorjeincincmovmovsubjncnegmulnotnegjcinc418bx, 90walk_upax, 2slast_90byte ptr signbxbx, 270walk_back;use incrementing method;set sign flagbyte ptr signbx, 270walk_up;set sign flagbx, 1;use angle to point into the;tablebx, offset word ptr sine_tbldx, word ptr [bx];get cos/sine of angleax, word ptr [si][2];get fraction bitsax, axwrite_result;linear interpolationbx;get next approximationbxcx, dxax, word ptr [bx];find differenceax, dxpos_res0axword ptr [si][2];multiply by fraction bitsdxaxleave_walk_updxTRANS.ASM AND TABLE.ASMjmppos_res0:mulleave_walk_up:addjmpwalk_back:shladdmovmovorjedecdecmovmovsubjncnegmulnotnegjcincjmppos_res1:mulleave_walk_back:addwrite_result:movmovmovleave-walk-upword ptr [si][2]dx, cx;by fraction bits and addin;anglewrite_resultbx, 1;point into tablebx, offset word ptr sine_tbldx, word ptr [bx];get cos/sine of angleax, word ptr [si][2];get fraction bitsax, axwrite_resultbxbxcx, dxax, word ptr [bx]ax, dxpos_res1axword ptr [si][2]dxaxleave-walk-backdxleave-walk-back;get next incremental cos/sine;get difference;multiply by fraction bitsword ptr [si][2];multiply by fraction bitsdx, cx;by fraction bits and add in;angledi, word ptr cs_ptrword ptr [di], axword ptr [di][2], dx;stuff result into variable;setup output for qword fixed;point419NUMERICAL METHODSsubax, axmovmovcmpjenotnotnotnegjcaddadcadcwordwordbyteexitwordwordwordwordexitwordwordword;radix point between the double;wordsptr [di][4], axptr [di][6], axptr sign, alptrptrptrptr[di][6][di][4][di][2][di][0]ptr [di][2],1ptr [di][4],axptr [di][6],axexit:popfretdcsin endp;; ******;gets exponent of floating point word;fr_xp procuses si di, fp0:dword, fp1:word, exptr:wordlocalflp0:qword, flp1:qwordpushfcldrep420xorleamovstoswax,axdi,word ptr flp0cx,4leasi,word ptr fp0TRANS.ASM AND TABLE.ASMreprepleamovmovswdi,word ptr flp0[2]cx,2invokefrxp, flp0, addr flp1, exptrleamovmovmovswsi,word ptr flp1[2]di,word ptr fp1cx,2popfretfr_xp endp;frxp performs an operation similar to the c function frexp.
used;for floating point math routines.;returns the exponent -bias of a floating point number.;it does not convert to floating point first, but expects a single;precision number on the stack.frxpprocuses di, float:qword, fraction:word, exptr:wordpushfcldmovmovmovsubororjeshlrclsubdi, word ptr exptrax, word ptr float[4]dx, word ptr float[2]cx, cxcx, axcx, dxmake_it_zeroax, 1cl, 1ah, 7ehmovbyte ptr [di],ah;assign pointer to exponent;get upper word of float;it is a zero;save the sign;subtract bias to place float;.5<=x<1421NUMERICAL METHODSmovshrrcrmovmovleamovmovswrepfrxp_exit:popfretmake_it_zero:submovmovstoswrepjmpfrxp endpah, 7ehcl, 1ax, 1word ptr float[4], axdi, word ptr fractionsi, word ptr floatcx, 4;replace the signax, axbyte ptr [di], aldi, word ptr fractionfrxp_exit; ******;creates float from fraction and exponent;ld_xp procuses si di, fp0:dword, power:word, exp:bytelocalflp0:qword,result:qwordpushfcldxorax,axdi,word ptr flp0cx,4repleamovstoswsi,word ptr fp0di,word ptr flp0[2]cx,2replealeamovmovsw422TRANS.ASM AND TABLE.ASMinvokerepleamovmovmovswldxp, flp0, addr result, expsi,word ptr result[2]di,word ptr powercx,2popfretld_xp endp;ldxp is similar to ldexp in c, it is used for math functions;takes from the stack, an input float(extended and returns a pointer to;a value to;the power of two;passed with it.ldxp procmovmovsubororuses di, float:qword, power:word, exp:byte;get upper word of float;extended bits are not checkedjeshlrclmovaddjcax, word ptr float[4]dx, word ptr float[2]cx, cxcx, axcx, dxreturn_zeroax, 1cl, 1ah, 7ehah, byte ptr expld_overflowshrrcrmovcl, 1word ptr ax, 1word ptr float[4], ax;return the sign;position exponent;save the signldxp_exit:423NUMERICAL METHODSrepmovmovleamovswretcx, 4di, word ptr powersi, word ptr floatretld_overflow:movsubmovmovjmpreturn_zero:submovmovstoswrepjmpldxp endpword ptr float[4], 7f80hax, axword ptr float[2], axword ptr float[0], axldxp_exitax, axdi, word ptr powercx, 4ldxp_exit;; ******; FX_SQR;accepts integers.;Remember that the powers follow the powers of two, i.e., the root of a doubleword;is a word, the root of a word is a byte, the root of a byte is a nibble, etc.;new_estimate = (radicand/last_estimate+last_estimate)/2,last_estimate=new_estimate.fx_sqr proc uses bx cx dx di si, radicand:dword, root:wordlocalestimate:word, cntr:bytebyte ptr cntr, 16bx, bx424;to test radicandTRANS.ASM AND TABLE.ASMmovmovorjsjejmpzero_exit:orjnesign_exit:stcsubmovjmpax, word ptr radicanddx, word ptr radicand[2]dx, dxsign_exitzero_exitfind_rootax, axfind_root;not zero;no negatives or zeros;indicate error in the operationax, axdx, axroot_exitfind_root:subjcbyte ptr cntr, 1root-exitfind_root1:orjeshrrcrjmpdx, dxfitsdx, 1ax, 1find_root1;must be zero;some kind of estimatemovsubmovdivmovword ptr estimate, axdx, dxax, word ptr radicand[2]word ptr estimatebx, ax;store first estimate of rootmovdivmovax, word ptr radicandword ptr estimatedx, bxaddax, word ptr estimate;will exit with carry set and an;approximate root;cannot have a root greater;than 16 bits foe;a 32 bit radicand!fits:;save quotient from division of;upperword;divide lower word;concatenate quotients;(radicand/estimate+estimate)/;2425NUMERICAL METHODSadcshrrcrdx, 0dx, 1ax, 1orjnecmpjneclcdx, dxfind_rootax, word ptr estimatefind_rootroot_exit:movmovmovretfx_sqr endp;to prevent any modular aliasing;is the estimate still changing?;clear the carry to indicate;successdi, word ptr rootword ptr [di], axword ptr [di][2], dx;; ******school_sqr;accepts integersschool_sqrproc uses bx cx dx di si, radicand:dword, root:wordlocalsubmovmovorjsjejmpzero_exit:orjnesign_exit:sub426estimate:qword, bits:bytebx, bxax, word ptr radicanddx, word ptr radicand[2]dx, dxsign_exitzero_exitsetupax, axsetupax, ax;not zero;no negatives or zeros;indicate error in the operation;can't do negativesTRANS.ASM AND TABLE.ASM;zero for failmovstcjmpdx, axmovmovmovsubmovmovmovmovmovbyte ptrword ptrword ptrax, axword ptrword ptrbx, axcx, axdx, axbits, 16estimate, axestimate[2], dxfindroot:shlrclrclrclwordwordwordwordptrptrptrptrestimate, 1estimate[2], 1estimate[4], 1estimate[6], 1shlrclrclrclwordwordwordwordptrptrptrptrestimate, 1estimate[2], 1estimate[4], 1estimate[6], 1shlrclax, 1bx, 1movmovshlrcladdadccx,dx,cx,dx,cx,dx,root_exitsetup:subtract_root:subsbbjncestimate[4], axestimate[6], ax;root;intermediateaxbx1110word ptr estimate[4], cxword ptr estimate[6], dxr_plus_one;double shift radicand;shift root;root*2;+l;accumulator-2*root+l427NUMERICAL METHODSaddadcjmpr-plus-one:addadccontinue_loop:decjneclcroot_exit:movmovmovretschool_sqrword ptr estimate[4], cxword ptr estimate[6], dxcontinue_loopax, 1bx, 0byte ptr bitsfindrootdi, word ptr rootword ptr [di], axword ptr [di][2], bxendp; ******;fp-cosfp_cos proc uses si di, fp0:dword, fp1:wordlocalpushfcldxorleamovrep stoswlealeamovrep movsw428flp0:qword, result:qword, sign:byteax,axdi,word ptr flp0cx,4si,word ptr fp0di,word ptr flp0[2]cx,2;r+=lTRANS.ASM AND TABLE.ASMsubmoval, albyte ptr sign, alinvokemovorjnsnotfladd, flp0, half_pi, addr flp0ax, word ptr flp0[4]ax, axpositivebyte ptr signinvokeflsin, flp0, addr result, signmovmovmovmovmovax, worddx, worddi, wordword ptrword ptr;is it less than zero?;positive:ptr result[2]ptr result[4]ptr fp1[di], ax[di][2], dxpopfretfp_cos endp;;******;fp_sin;;fp_sin proc uses si di, fp0:dword, fp1:wordlocalpushfcldxorleamovrep stoswflp0:qword, result:qword, sign:byteax,axdi,word ptr flp0cx,4429NUMERICAL METHODSlealeamovrep movswsi,word ptr fp0di,word ptr flp0[2]cx,2submovmovorjnsnotal, albyte ptr sign, alax, word ptr flp0[4]ax, axpositivebyte ptr signinvoke;is it less than zero?;positive:flsin, flp0, addr result, signinvokeround, result, addr resultmovmovmovmovmovax, worddx, worddi, wordword ptrword ptrptr result[2]ptr result[4]ptr fp1[di], ax[di][2], dxpopfretfp_sinendp;;******;flsin;flsin proclocalpushfcld430uses bx cx dx si di, fp0:qword, fp1:word, sign:byteresult:qword, temp0:qword, temp1:qword,y:qword, u:qwordTRANS.ASM AND TABLE.ASMinvokeflcomp, fp0, ymaxcmpjlax, 1absxerror_exit:leasubmovstoswrepjmp;error, entry value too;largedi, word ptr resultax, axcx, 4writeoutabsx:movorjnsandmovax, word ptr fp0[4]ax, axdeconstruct_exponentax, 7fffhword ptr fp0[4], ax;make absolutedeconstruct_exponent:invokeflmul, fp0, one_over_pi, addr result;x/piinvokeintrnd, result, addr temp0;intrnd(x/pi)movax, word ptr temp0[2]movmovanddx,word ptr temp0[4]cx, dxcx, 7f80hshlmovsubsubcx,cl,ch,cl,jsnot-odd1chch7fh;determine if integerhas;odd or even;number of bits;get rid of sign and;mantissa portion;subtract bias (-1) from;exponent431NUMERICAL METHODSincorjeextract_int:shlrclrcllooptestjenotnot_odd:clcl, clxpiax, 1dx, 1word ptr bx, 1extract_intdh, 1xpibyte ptr sign;position as fixedpointxpi:invoke;extended precision multiply;by piflmul, sincos[8*0], temp0, addr result;intrnd(x/pi)*c1invokeflsub, fp0, result, addr result;|x|-intrnd(x/pi)invokeflmul, temp0, sincos[8*1], addr temp1;intrnd(x/pi)*c2invokeflsub, result, temp1, addry;ychk_eps:invokeinvokeorjnsleasubmovstoswrepjmp432flabs, y, addr temp0flcomp, temp0, epsax, axr_gdi, word ptr resultax, axcx, 4writeout;is the argument less than eps?TRANS.ASM AND TABLE.ASMr_g:invokeflmul, y, y, addr u;evaluater(g);((r4*g+r3)*g+r2)*g+rl)*ginvokeinvokeflmul, u, sincos[8*5], addr resultfladd, sincos[8*4], result, addr resultinvokeinvokeflmul, u, result, addr resultfladd, sincos[8*3], result, addr resultinvokeinvokeflmul, u, result, addr resultfladd, sincos[8*2], result, addr resultinvokeflmul, u, result, addr result;result == zfxr:invokeflmul, result, y, addr resultinvokefladd, result, y, addr result;r*r+fhandle_sign:cmpjnexorbyte ptr sign, -1writeoutword ptr result[4], 8000h;result * signwriteout:movleamovmovswrepdi, word ptr fp1si, word ptr resultcx, 4flsin_exit:popfretflsin endp433NUMERICAL METHODS;; ******; fp_tan;fp_tan proclocaluses si di, fp0:dword, fp1:wordflp0:qword,result:qwordreppushfcldxorleamovstoswsi,word ptr fp0di,word ptr flp0[2]cx,2replealeamovmovswinvokefltancot, flp0, addr resultmovmovmovmovmovax, worddx, worddi, wordword ptrword ptrpopfretfp_tanendp;;******;fltancot434ax,axdi,word ptr flp0cx,4ptr result[2]ptr result[4]ptr fp1[di], ax[di][2], dxTRANS.ASM AND TABLE.ASMfltancot proclocaluses bx cx dx si di, fp0:qword, fp1:wordflp0:qword, result:qword, temp0:qword, temp1:qword,sign:byte, xnum:qword, xden:qword, xn:qword, f:qword,g:qword, fxpg:qword, qg:qwordpushfcldsubmovax, axbyte ptr sign, aldi, word ptr gcx, 4repleamovstoswdi, word ptr fcx, 4repleamovstoswshlrclshrword ptr fp0[4], 1byte ptr sign, 1word ptr fp0[4], 1invokecmpflcomp, fp0, ymaxax, 1continuedi, word ptr resultax, axcx, 4repjlleasubmovstoswjmpcontinue:shlshrrcr;clear the sign flag;place input argument in;variable;place input argument in;variable;absolute value for comparison;error,entry value too largefltancot_exitword ptr fp0[4], 1byte ptr sign, 1word ptr fp0[4], 1;restore sign435NUMERICAL METHODSinvokeflmul, fp0, two-over-pi, addr result;x*2/piinvokeintrnd, result, addr xn;intmd(x*2/pi)movax, word ptr xn[2]movmovanddx, word ptr xn[4]cx, dxcx, 7f80hshlmovsuborjesubcx, 1cl, chch, chcl, clnot-oddcl, 7fhjsincorjeandorextract_int:shlrclrcllooptestjemovnot_odd:436not-oddclcl, clnot-odddx, 7fhdx, 80hax, 1dx, 1word ptr bx, 1extract_intdh, 1not_oddbyte ptr sign, -1;determine if integer has odd;or even;number of bits;get rid of sign and;mantissa portion;subtract bias (-1) from;exponent;restore hidden bit;position as fixedpointinvokeinvokeflmul, xn, tancot[8*0], addr temp0flsub, fp0, temp0, addr temp0;(x-xn*c1)invokeflmul, xn, tancot[8*1], addr temp1TRANS.ASM AND TABLE.ASM;xn*c2invokeflsub, temp0, temp1, addr f;(x-xn*c1)-xn*c2reprepinvokeinvokeorjnslealeamovmovswlealeamovmovswjmpcompute:invokerepflabs, f, addr temp1flcomp, temp1, epsax, axcomputesi, word ptr fdi, word ptr xnumcx, 4;|f|<eps?si, word ptr onedi, word ptr xdencx, 4;1.0->xden;f->xnumcompute-resultflmul, f, f, addr g;f*f->ginvokeinvokeinvokeflmul, g, tancot[8*3], addr temp0flmul, f, temp0, addr temp0fladd, temp0, f, addr fxpg;fxpg=(p2*g+pl)*g*f;+ finvokeinvokeinvokeinvokeflmul, g, tancot[8*6], addr temp0fladd, temp0, tancot[8*5], addr temp0flmul, g, temp0, addr temp0fladd,temp0,tancot[8*4], addr qg;qg = (q2 * g + q1) * g +q0lealeamovmovswleasi, word ptr fxpgdi, word ptr xnumcx, 4si, word ptr qg437NUMERICAL METHODSrepleamovmovswdi, word ptr xdencx, 4compute_result:movorjexorjmpal, byte ptr signal, alxnum_xdenword ptr xnum[4],8000hshort xden_xnumxden_xnum:invokejmpfldiv, xden, xnum, fp1fltancot_exitxnum_xden:invokefldiv, xnum, xden, fpl;even or odd;make it negativefltancot_exit:popfretfltancot endp;;******;fp_sqrfp_sqr proc438uses si di, fp0:dword, fp1:wordlocalflp0:qword, result:qwordpushfcldxorleaax,axdi,word ptr flp0TRANS.ASMmovstoswcx,4lealeamovmovswsi,word ptr fp0di,word ptr flp0[2]cx,2invokeflsqr, flp0, addr resultinvokeround, result, addr resultmovmovmovmovmovax, worddx, worddi, wordword ptrword ptrANDTABLE.ASMptr result[2]ptr result[4]ptr fp1[di], ax[di][2], dxpopfretfp_sqr endp;; ******; flsqrflsqr proclocaluses bx cx dx si di, fp0:qword, fp1:wordresult:qword, temp0:qword, temp1:qword, exp:byte,xn:qword, f:qword, yO:qword, m:bytepushfcldleadi, word ptr xn439NUMERICAL METHODSreprepsubmovstoswax, axcx, 4invokecmpjecmpjemovsubmovstoswnotandmovflcomp, fp0, zeroax, 1okax, 0got-resultdi, word ptr fp1ax, axcx, 4jmpgot_result:movsubmovstoswrepjmpaxax, 7f80hword ptr result[4],axflsqr_exit;error, entry value too large;make it plus infinitydi, word ptr fp1ax, axcx, 4flsqr_exitok:invokefrxp, fp0, addr f, addr exp ;get exponentinvokeinvokeflmul, f, y0b, addr temp0fladd, temp0, y0a, addryinvokeinvokemovshlsubshrmov;two passes through;(x/r+r)/2 is all we needfldiv, f, y0, addr temp0fladd, y0, temp0, addr temp0ax, word ptr temp0[4]ax, 1;should always be safeah, 1ax, 1;subtracts one half byword ptr temp0[4], axheron:440TRANS.ASM AND TABLE.ASM;decrementing the exponent;oneinvokeinvokemovshlsubshrmovmovfldiv, f, temp0, addr temp1fladd, temp0, temp1, addr temp0ax, word ptr temp0[4]ax, 1ah, 1ax, 1word ptr y0[4], axax, word ptr temp0[2]movmovmovsubmovword ptrax, wordword ptrax, axword ptrmovmovsarjncal, byte ptr expcl, alal, 1evninvokeflmul, y0, sqrt_half, addr y0movincsaral, clalal, 1movcl, almovshladdax, word ptr y0[4]ax, 1ah, cl;should always be safe;subtracts one half by;decrementing the exponent;oney0[2], axptr temp0y0, axy0[6], axchk_n:;arithmetic shiftodd:;adjustment for uneven;exponentevn:;n/2->mpower:write_result:shrmovax, 1word ptr y0[4], ax441NUMERICAL METHODSleamovmovmovswrepsi, word ptr y0di, word ptr fp1cx, 4flsqr_exit:popfretflsqr endp;;******;lgb - log to base 2;input argument must be be l<= x < 2;multiply the result by .301029995664 (4d104d42h) to convert to base 10;higher powers of 2 can be derivedby counting the number of shifts required;to bring the number between 1 and 2, calculating that lgb then adding, as the;integer portion, the number of shifts as that is the power of the number.lgbrep442procuses bx cx dx di si, argument:qword, result:wordlocalk:byte, z:qwordmovsubmovstoswincmovdi,word ptr resultax,axc x , 4movmovmovax, word ptr argumentbx, word ptr argument[2]dx, word ptr argument[4]shrrcrrcrdx, 1bx, 1ax, 1;make y zeroalbyte ptr k, al ;make k == 1;z=argument/2;scale argument for zTRANS.ASM AND TABLE.ASMleamovmovmovdi, wordword ptrword ptrword ptrptr z[di], ax[di][2], bx[di][4], dxmovmovmovax, word ptr argumentbx, word ptr argument[2]dx, word ptr argument [4]subcmpjnecmpjneinccmpjnecx, cxax, cxnot_done_yetbx, axnot_done_yetcxdx, axnot_done_yetjmplogb_exitxl:not_done_yet:subsbbjc;argument between 1.0 and 2.0;test for 1.0ax, word ptr zbx, word ptr z[2]shift;x-z<l?movmovmovword ptr argument, axword ptr argument[2], bxword ptr argument[4], dx:x<-x-zsubmovcx, cxcl, byte ptr kshrrcrrcrloopmovdx, 1bx, 1ax, 1shiftkword ptr z, axreduce:shiftk:;z<-argument<<k443NUMERICAL METHODSmovmovword ptr z[2], bxword ptr z[4], dxsubmovcmpjabx, bxbl, byte ptr kbl, 20logb_exitdecshlshlshlblbx, 1bx, 1bx, 1leamovmovmovmovaddadcadcjmpsi, wordax, wordcx, worddx, worddi, wordword ptrword ptrword ptrxlshrrcrrcrword ptr z[4], 1word ptr z[2], 1word ptr z, 1incbyte ptr kjmpxl;point into table of qwordsptr log2ptr [si][bx]ptr [si][bx][2]ptr [si][bx][4]ptr result[di], ax[di][2], cx[di][4], dxshift:logb_exit:retlgbendp;; ******;pwrb - base 10444to power;get log of powerTRANS.ASM AND TABLE.ASM;input argument must be be l<= x <2procuses bx cx dx di si, argument:qword, result:wordpwrbreplocalk:byte, z:qwordmovsubmovstoswincstoswdecstoswmovdi, word ptr resultax, axcx, 2byte ptr k, al;make k = 0movmovmovax, word ptr argumentcx, word ptr argument[2]dx, word ptr argument[4];argument 0<= x < 1subcmpjnecmpjnecmpjnebx, bxax, bxnot_done_yetcx, bxnot_done_yetdx, bxnot_done_yetjmppwrb_exit;y;make y oneaxaxx0:not_done_yetsubmovcmpjabx, bxbl, byte ptr kbl, 20hpwrb_exitshlshlshlbx, 1bx, 1bx, 1leasi, word ptr power10;testfor 0.0;point into table of qwords445NUMERICAL METHODScmpjbjacmpjbdx, word ptr [si][bx][4]increasereducecx, word ptr [si][bx][2]increasereduceax, word ptr [si][bx]increasesubsbbsbbmovmovmovax, wordcx, worddx, wordword ptrword ptrword ptrsubmovcx, cxcl, byte ptr kmovmovmovmovcmpsi, word ptrax, word ptrbx, word ptrdx, word ptrcl, 0no_shiftkjbjacmpreduce:jeptr [si][bx]ptr [si][bx][2]ptr [si][bx][4]argument, axargument[2], cxargument[4], dx;x<-x-zresult[si][si][2][si][4]shiftk:shrrcrrcrloopno_shiftk:addadcadcjmpincrease:446dx, 1bx, 1ax, 1shiftkword ptr [si], axword ptr [si][2], bxword ptr [si][4], dxx0;z<-argument<<kTRANS.ASMincjmpANDTABLE.ASMbyte ptr kx0pwrb_exit:retpwb endp;******;circular- implementation of the circular routine, a subset of the CORDIC devices;;circularproc uses bx cx dx di si, x:word, y:word, z:wordlocalsmallx:qword, smally:qword, smallz:qword, i:byte,shifter:worddi, word ptr smallxsi, word ptr xcx, 4repleamovmovmovswdi, word ptr smallysi, word ptrycx, 4repleamovmovmovswdi, word ptr smallzsi, word ptr zcx, 4repleamovmovmovswsubmovax, axbyte ptr i, al;i=0447NUMERICAL METHODSmovmovbx, axcx, axsubmovmovax, axal, iword ptr shifter, axmovmovmovmovmovsi,ax,bx,cx,dx,cmpjeword ptr shifter, 0load_smallxtwist:wordwordwordwordwordptrptrptrptrptrx[si][si][2][si][4][si][6];multiply by 2ˆ-ishiftx:sarrcrrcrrcrdecjnzload_smallx:movmovmovmov448dx, 1cx, 1bx, 1ax, 1word ptr shiftershiftxwordwordwordwordptrptrptrptrsmallx, axsmallx[2], bxsmallx[4], cxsmallx[6], dxsubmovmovax, axal, iword ptr shifter, axmovmovmovmovmovsi,ax,bx,cx,dx,cmpword ptr shifter, 0wordwordwordwordwordptrptrptrptrptr;note the arithmetic shift;for sign extension;x=x>>iy[si][si][2][si][4][si][6];multiply by 2^-iTRANS.ASMjeANDTABLE.ASMload_smallyshifty:sarrcrrcrrcrdecjnzload_smally:movmovmovmovget_atan:submovshlshlleamovmovdx, 1cx, 1bx, 1ax, 1word ptr shiftershiftywordwordwordwordbx,bl,bx,bx,si,ax,dx,ptrptrptrptrsmally, axsmally[2], bxsmally[4], cxsmally[6], dxbxi11word ptr atan_arrayword ptr [si][bx]word ptr [si][bx] [2]movmovsubmovmovword ptrword ptrax, axword ptrword ptrsmallz, axsmallz[2], dxmovmovorjnssi, word ptr zax, word ptr [si][6]ax, axpositive;note the arithmetic shift;for sign extension;y=Y>>i;got to point into a dword table;z=atan[i]smallz[4], axsmallz[6], axtest_Z:negative:movmovmovmovax,bx,cx,dx,wordwordwordwordptrptrptrptrsmallysmally[2]smally[4]smally[6]449NUMERICAL METHODSmovaddadcadcadcdi, wordword ptrword ptrword ptrword ptrptr x[di], ax[di][2], bx[di][4], cx[di][6], dxmovmovmovmovax,bx,cx,dx,ptrptrptrptrmovsubsbbsbbsbbdi, wordword ptrword ptrword ptrword ptrptr y[di], ax[di][2], bx[di][4], cx[di][6], dxmovmovmovmovax,bx,cx,dx,ptrptrptrptrmovaddadcadcadcdi, wordword ptrword ptrword ptrword ptrjmpfor_nextpositive:movmovmovmovmovsubsbb450wordwordwordwordwordwordwordword;x += ysmallxsmallx[2]smallx[4]smallx[6];Y -= xsmallzsmallz[2]smallz[4]smallz[6]ptr z[di], ax[di][2], bx[di][4], cx[di][6], dxax, word ptr smallybx, word ptr smally [2]cx, word ptr smally[4]dx, word ptr smally[6]di, word ptr xword ptr [di], axword ptr [di][2], bx;x += yTRANS.ASM AND TABLE.ASMsbbsbbword ptr [di][4], cxword ptr [di][6], dx;x -= ymovmovmovmovmovaddadcadcadcax, wordbx, wordcx, worddx, worddi, wordword ptrword ptrword ptrword ptrptr smallxptr smallx[2]ptr smallx[4]ptr smallx[6]ptr y[di], ax[di][2], bx[di][4], cx[dil[6], dx;Y += xmovmovmovmovmovsubsbbsbbsbbax, wordbx, wordcx, worddx, worddi, wordword ptrword ptrword ptrword ptrptr smallzptr smallz[2]ptr smallz[4]ptr smallz[6]ptr z[di], ax[di][2], bx[di][4], cx[di][6], dx;x -= yfor_next:inccmpjajmpbyte ptr ibyte ptr i, 32circular-exittwist;bump exponentcircular-exitretcircularendp;;******;icirc- implementation of the inverse circular routine, a subset of the cordic;devices;451NUMERICAL METHODSicirc proc uses bx cx dx di si, x:word, y:word, z:wordlocalsmallx:qword, smally:qword, smallz:qword, i:byte,shifter:worddi, word ptr smallxsi, word ptr xcx, 4repleamovmovmovswdi, word ptr smallysi, word ptrycx, 4repleamovmovmovswdi, word ptr smallzsi, word ptr zcx, 4repleamovmovmovswsubmovmovmovax, axbyte ptr i, al ;i=0bx, axcx, axsubmovmovax, axal, iword ptr shifter, axmovmovmovmovmovsi,ax,bx,cx,dx,twist:cmp452wordwordwordwordwordptrptrptrptrptrx[si][si][2][si][4][si][6]word ptr shifter, 0;multiply by2ˆ-iTRANS.ASM AND TABLE.ASMjeload_smallxshiftx:sarrcrrcrrcrdecjnzload_smallx:movmovmovmovdx, 1cx, 1bx, 1ax, 1word ptr shiftershiftxwordwordwordwordptrptrptrptrsmallx, axsmallx[2], bxsmallx[4], cxsmallx[6], dxsubmovmovax, axal, iword ptr shifter, axmovmovmovmovmovsi,ax,bx,cx,dx,cmpjeword ptr shifter, 0load_smally;x=X>>iword ptryword ptr [si]word ptr [si][2]word ptr [si][4]word ptr [si][6]shifty:sarrcrrcrrcrdecjnzload_smally:movmovmovmovdx, 1cx, 1bx, 1ax, 1word ptr shiftershiftywordwordwordwordptrptrptrptrsmally, axsmally[2], bxsmally[4], cxsmally[6], dx;y=Y>>iget_atan:453NUMERICAL METHODSsubmovshlshlleamovmovbx,bl,bx,bx,si,ax,dx,bxi11word ptr atan_arrayword ptr [si][bx]word ptr [si][bx][2]movmovsubmovmovword ptrword ptrax, axword ptrword ptrmovmovorjssi, word ptr yax, word ptr [si][6]ax, axpositivesmallz, axsmallz[2], dx;got to point into a dword table;z=atan[i]smallz[4], axsmallz[6], axtest_Y:negative:movmovmovmov454ax,bx,cx,dx,wordwordwordwordptrptrptrptrsmallysmally[2]smally[4]smally[6]movaddadcadcadcdi, wordword ptrword ptrword ptrword ptrptr x[di], ax[di][2], bx[di][4], cx[di][6], dxmovmovmovmovax,bx,cx,dx,ptrptrptrptrmovsubsbbdi, word ptr yword ptr [di], axword ptr [di][2], bxwordwordwordwordsmallxsmallx[2]smallx[4]smallx[6];x += yTRANS.ASM AND TABLE.ASMsbbsbbword ptr [di][4], cxword ptr [di][6], dxmovmovmovmovax,bx,cx,dx,movaddadcadcadcdi, wordword ptrword ptrword ptrword ptrjmpfor_nextpositive:movmovmovmovmovsubsbbsbbsbbwordwordwordwordptrptrptrptr;Y -= xsmallzsmallz[2]smallz[4]smallz[6]ptr z[di], ax[di][2], bx[di][4], cx[di][6], dx-x += yax, wordbx, wordcx, worddx, worddi, wordword ptrword ptrword ptrword ptrptr smallyptr smally[2]ptr smally[4]ptr smally[6]ptr x[di], ax[dil[2], bx[di][4], cx[di][6], dx;x -= ymovmovmovmovmovaddadcadcadcax, wordbx, wordcx, worddx, worddi, wordword ptrword ptrword ptrword ptrptr smallxptr smallx[2]ptr smallx[4]ptr smallx[6]ptr y[di], ax[di][2], bx[di][4], cx[di][6], dx;Y += xmovmovax, word ptr smallzbx, word ptr smallz[2]455NUMERICAL METHODSmovmovmovsubsbbsbbsbbfor_next:inccmpjajmpcx, worddx, worddi, wordword ptrword ptrword ptrword ptrptr smallz[4]ptr smallz[6]ptr z[di], ax[di][2], bx[di][4], cx[di][6], dx;x -= ybyte ptr ibyte ptr i, 32icircular_exittwisticircular_exit:reticirc endp; ******;hyper- implementation of the hyperbolic routine, a subset of the cordic devices;hyper proc uses bx cx dx di si, x:word, y:word, z:wordrep456localsmallx:qword, smally:qword, smallz:qword, i:byte,shifter:wordleamovmovmovswdi, word ptr smallxsi, word ptr xcx, 4leamovmovdi, word ptr smallysi, word ptr ycx, 4TRANS.ASM AND TABLE.ASMrepmovswdi, word ptr smallzsi, word ptr zcx, 4repleamovmovmovswsubincmoval, alalbyte ptr i, al ;i=1twister:callfor_next:cmpjnecallchk_13:cmpjnecallchk_max:inccmpjajmpnear ptr twistbyte ptr i, 4chk_13near ptr twistbyte ptr i, 13chk_maxnear ptr twist;add in repeating termbyte ptr ibyte ptr i, 32hyper_exittwisterhyper_exit:rettwist:submovmovax, axal, iword ptr shifter, axmovmovmovsi, word ptr xax, word ptr [si]bx, word ptr [si][2]457NUMERICAL METHODSmovmovcx, word ptr [si][4]dx, word ptr [si][6]shiftx:sarrcrrcrrcrdecjnzload_smallx:movmovmovmovdx, 1cx, 1bx, 1ax, 1word ptr shiftershiftxwordwordwordwordptrptrptrptrsmallx, axsmallx[2], bxsmallx[4], cxsmallx[6], dxsubmovmovax, axal, iword ptr shifter, axmovmovmovmovmovsi,ax,bx,cx,dx,;x=X>>iword ptryword ptr [si]word ptr [si][2]word ptr [si][4]word ptr [si][6]shifty:sarrcrrcrrcrdecjnzload_smally:movmovmovmovget_atan:458dx, 1cx, 1bx, 1ax, 1word ptr shiftershiftywordwordwordwordptrptrptrptrsmally, axsmally[2], bxsmally[4], cxsmally[6], dx;y=Y>>iTRANS.ASM AND TABLE.ASMsubmovshlshlleamovmovbx,bl,bx,bx,si,ax,dx,bxi11word ptr atanh_arrayword ptr [si][bx]word ptr [si][bx][2]movmovsubmovmovword ptrword ptrax, axword ptrword ptrmovmovorjnssi, word ptr zax, word ptr [si][6]ax, axpositivesmallz, axsmallz[2], dx;got to point into a dword table;z=atanh[i]smallz[4], axsmallz[6], axtest_Z:negative:movmovmovmovax,bx,cx,dx,wordwordwordwordptrptrptrptrsmallysmally[2]smally[4]smally[6]movsubsbbsbbsbbdi, wordword ptrword ptrword ptrword ptrptr x[di], ax[di][2], bx[di][4], cx[di][6], dxmovmovmovmovax,bx,cx,dx,ptrptrptrptrmovsubsbbsbbdi, wordword ptrword ptrword ptrwordwordwordword;x -= ysmallxsmallx[2]smallx[4]smallx[6]ptr y[di], ax[di][2], bx[di][4], cx459NUMERICAL METHODSsbbword ptr [di][6], dxmovmovmovmovax,bx,cx,dx,movaddadcadcadcdi, word ptr zword ptr [di], axword ptr [di][2], bxword ptr [di][4], cxword ptr [di][6], dxtwist_exitjmppositive:movmovmovmovmovaddadcadcadc460wordwordwordwordax, wordbx, wordcx, worddx, worddi, wordword ptrword ptrword ptrword ptrptrptrptrptr;Y -= xsmallzsmallz[2]smallz[4]smallz[6];x += yptr smallyptr smally[2]ptr smally[4]ptr smally[6]ptr x[di], ax[di][2], bx[di][4], cx[di][6], dx;x += ymovmovmovmovmovaddadcadcadcax, word ptr smallxbx, word ptr smallx [2]cx, word ptr smallx [4]dx, word ptr smallx [6]di, word ptryword ptr [di], axword ptr [di][2], bxword ptr [di][4], cxword ptr [di][6], dx;Y += xmovmovmovmovmovax,bx,cx,dx,di,word ptrword ptrword ptrword ptrwordptrsmallzsmallz[2]smallz[4]smallz[6]zTRANS.ASM AND TABLE.ASMsubsbbsbbsbbtwist_exit:retnwordwordwordwordptrptrptrptr[di], ax[di][2], bx[di][4], cx[di][6], dx;x -= yhyper endp;;******;ihyper- implementation of the inverse hyperbolic routine, a subset of the;CORDIC devices.;ihyper proc uses bx cx dx di si, x:word, y:word, z:wordlocalsmallx:qword, smally:qword, smallz:qword, i:byte,shifter:worddi, word ptr smallxsi, word ptr xcx, 4repleamovmovmovswdi, word ptr smallyrepleamovmovmovswdi, word ptr smallzsi, word ptr zcx, 4repleamovmovmovswsubincal, alalsi, word ptr ycx,4461NUMERICAL METHODSmovtwister:callfor_next:cmpbyte ptr i, al ;i=0near ptr twistjnebyte ptr i, 4chk_13callnear ptr twistcmpjnebyte ptr i, 13chk_maxcallnear ptr twistchk_13:chk_max:inccmpjabyte ptr ibyte ptr i, 32ihyper_exitjmptwisterihyper_exit:ret;twist:movsubax, axal, imovword ptr shifter, axmovmovsi, word ptr xax, word ptr [si]movmovbx, word ptr [si][2]cx, word ptr [si][4]movdx, word ptr [si][6]sardx, 1rcrrcrcx, 1shiftx:462bx, 1rcrax, 1decjnzword ptr shiftershiftx;add in repeating termTRANS.ASM AND TABLE.ASMload_smallx:movmovmovmovwordwordwordwordptrptrptrptrsmallx, axsmallx[2], bxsmallx[4], cxsmallx[6], dxsubmovmovax, axal, iword ptr shifter, axmovmovmovmovmovsi,ax,bx,cx,dx,wordwordwordwordwordptrptrptrptrptr;x=X>>iy[si][si][2][si][4][si][6]shifty:sarrcrrcrrcrdecjnzload_smally:movmovmovmovget_atan:submovshlshlleamovmovmovmovdx, 1cx, 1bx, 1ax, 1word ptr shiftershiftywordwordwordwordbx,bl,bx,bx,si,ax,dx,ptrptrptrptrsmally, axsmally[2], bxsmally[4], cxsmally[6], dxbxi11word ptr atanh_arrayword ptr [si][bx]word ptr [si][bx][2]word ptr smallz, axword ptr smallz[2], dx;y=Y>>i;got to point into a dword table;z=atanh[i]463NUMERICAL METHODSsubmovmovax, axword ptr smallz[4], axword ptr smallz[6], axmovmovorjssi, word ptr yax, word ptr [si][6]ax, axpositivetest_Y:negative:movmovmovmov464ax,bx,cx,dx,wordwordwordwordptrptrptrptrsmallysmally[2]smally[4]smally[6]movsubsbbsbbsbbdi, wordword ptrword ptrword ptrword ptrptr x[di], ax[di][2], bx[di][4], cx[di][6], dxmovmovmovmovax,bx,cx,dx,ptrptrptrptrmovsubsbbsbbsbbdi, wordword ptrword ptrword ptrword ptrptr y[di], ax[di][2], bx[di][4], cx[di][6], dxmovmovmovmovax,bx,cx,dx,ptrptrptrptrmovadddi, word ptr zword ptr [di], axwordwordwordwordwordwordwordword;x -= ysmallxsmallx[2]smallx[4]smallx[6]smallzsmallz[2]smallz[4]smallz[6];Y -= xTRANS.ASM AND TABLE.ASMadcadcadcjmpword ptr [di][2], bxword ptr [di][4], cxword ptr [di][6], dxtwist-exit;z += zpositive:movmovmovmovmovaddadcadcadcax, wordbx, wordcx, worddx, worddi, wordword ptrword ptrword ptrword ptrptr smallyptr smally[2]ptr smally[4]ptr smally[6]ptr x[di], ax[di][2], bx[di][4], cx[di][6], dx;x += ymovmovmovmovmovaddadcadcadcax, wordbx, wordcx, worddx, worddi, wordword ptrword ptrword ptrword ptrptr smallxptr smallx[2]ptr smallx[4]ptr smallx[6]ptr y[di], ax[di][2], bx[di][4], cx[di][6], dx;Y += xmovmovmovmovmovsubsbbsbbsbbax, wordbx, wordcx, worddx, worddi, wordword ptrword ptrword ptrword ptrptr smallzptr smallz[2]ptr smallz[4]ptr smallz[6]ptr z[di], ax[di][2], bx[di][4], cx[di][6], dx;z -= ztwist_exit:retnihyper endp465NUMERICAL METHODS; ******;rinit - initializes random number generator based upon input seeda.datadwordIMAX equrantop wordran1dwordxsubi dword6906932767IMAX256 dup (0)lhinit byte0h;global iterative seed for;random number generator, change;this value to change default;global variable signalling;whether the generator has be;initialized or not.coderinitproc uses bx cx dx si di, seed:dwordleadi, word ptr ran1movmovmovmovax, wordword ptrax, wordword ptrmovcx, 256fill-array:invokemovmovaddlooprinit_exit:466ptr seed[2]xsubi[2], axptr seedxsubi, axcongruentword ptr [di], axword ptr [di][2], dxdi, 4fill-array;put in seed variable;get seedTRANS.ASM AND TABLE.ASMsubnotmovretrinitax, axaxbyte ptr init, alendp;;; ******;congruent -performs simple congruential algorithm;congruent proc uses bx cxmovax, word ptr xsubimulword ptr amovbx, axmovcx, dxmovax, word ptr xsubi[2]mulword ptr aaddax, cxadcdx, 0addadcmovmovmovretcongruent endpax, word ptr xsubi;a*seed (mod2^32);lower word of result;upper word;a multiplication by one is just;an add, right?dx, word ptr xsubi[2]dx, bxword ptr xsubi, bxword ptr xsubi[2], ax;;******;irandom- generates random floats using the linear congruential methodirandomproc uses bx cx dx si di467NUMERICAL METHODSsi, word ptr ran1leaal, byte ptr initmovoral, alalready-initializedjneinvokerinit, xsubialready_initialized:invokecongruentandax, 0ffhshlax, 1shlax, 1si, axaddmovdi, siinvokecongruentmovbx, word ptr [si]movcx, word ptr [si][2]movword ptr [di], axmovword ptr [di][2], dxword ptr xsubi, bxmovword ptr xsubi[2], cxmovmovmulax, bxword ptr rantopmovax, dxretirandom;end468endp;check for initialization;default to 1;get a random number;every fourth byte, right?;multiply by four;point to number in array;so we can put one there too;get number from array;replace it with another;seed for next random;scale output by rantop, the;maximum size of the random;number if rantop were made;0ffffH, the value could be used;directly as a fractionTRANS.ASM AND TABLE.ASMTABLE.ASM.dosseg.model small, c, os_dosinclude math.inc;.data;;sines(degrees)sine_tbl wordword;;log(x/128)log10_tbl wordword0ffffh,0fe98h,0fa67h,0f378h,0egdeh,0ddb3h,0cf1bh,0be3eh,0fff6h,0fe17h,0f970h,0f20dh,0e803h,0db6fh,0cc73h,0bb39h,0ffd8h,0fd82h,0f865h,0f08fh,0e617h,0d919h,0cgbbh,0b826h,0ffa6h, 0ff60h, 0ff06h,0fcdgh, 0fc1ch, 0fb4bh,0f746h, 0f615h, 0f4dOh,0eeffh, 0ed5bh, 0eba6h,0e419h, 0e208h, 0dfe7h,0d6b3h, 0d43bh, 0d1b3h,0c6f3h, 0c41bh, 0c134h,0b504h, 0b1d5h, 0ae73h0ab4ch,09679h,08000h,0681fh,04f1bh,03539h,01acah,Oh0a7f3h,092d5h,07c1ch,06406h,04ad8h,030d8h,0164fh,0a48dh,08f27h,0782fh,05fe6h,04690h,02c74h,011dbh,0a1lbh,08b6dh,07438h,05bbeh,04241h,0280ch,00d65h,09d9bh,087a8h,07039h,0578eh,03deeh,023aOh,008efh,09a10h,083d9h,06c30h,05358h,03996h,01f32h,00477h,00000h,0036bh,0085dh,00d18h,011a2h,015feh,000ddh,00442h,0092ah,00dddh,0125fh,016b4h,001b9h,00517h,009f6h,00ea0h,0131bh,01769h,00293h,005ebh,00ac1h,00f63h,013d5h,0181ch,006bdh,00b8ah,01024h,0148fh,018cfh,0078eh,00c51h,010e3h,01547h,01980h01a30h, 01adfh, 01b8dh, 01c3ah, 01ce6h, 01dg1h,469NUMERICAL METHODS01e3bh, 01ee4h, 01f8ch, 02033h, 020d9h, 0217eh,02222h, 022c5h, 02367h, 02409h, 024a9h, 02548h,025e7h, 02685h, 02721h, 027bdh, 02858h, 028f3hword0298ch,02d14h,03080h,033d1h,0370ah,02a25h,02da8h,0310fh,0345ch,03792h,02abdh,02e3bh,0319eh,034e7h,03818h,02b54h,02ecdh,0322ch,03571h,0389eh,02beah,02f5fh,032b9h,035fah,03923h,02c7fh,02ff0h,03345h,03682h,039a8hword03a2ch,03d38h,0402fh,04312h,045e3h,03ab0h,03db8h,040ach,0438ch,04659h,03b32h,03e37h,04128h,04405h,046cfh,03bb5h,03eb6h,041a3h,0447dh,04744h,03c36h,03f34h,0421eh,044f5h,047b9h,03cb7h,03fb2h,04298h,0456ch,0482ehword048a2h, 04915h, 04988h, 049fbh, 04a6dh, 04adeh,04b50h, 04bc0h, 04c31h, 04ca0h, 04d10h;log(2**x)log10_power dword 000000h, 004d10h, 009a20h, 00e730h, 013441h, 018151h,01ce61h, 021b72h, 026882h, 02b592h, 0302a3h, 034fb3h,039cc3h, 03e9d3h, 0436e4h, 0483f4h, 04d104h, 051e15h,056b25h, 05b835h, 060546h, 065256h, 069f66h, 06ec76h,073987h, 078697h, 07d3a7h, 0820b8h, 086dc8h, 08bad8h,0907e9h, 0954f9h;;sqrt(x+128)*2**24;these are terribly rough, perhaps combined with Euclid's method;they would produce high quality numberssqr_tblword0b504h, 0b5b9h, 0b66dh, 0b720h, 0b7d3h, 0b885h,0b936h, 0b9e7h, 0ba97h, 0bb46h, 0bbfSh, 0bca3h,0bd50h, 0bdfdh, 0beagh, 0bf55h, 0c000h, 0c0aah,0c154h, 0c1fdh, 0c2a5h, 0c34eh, 0c3f5h, 0c49ch,0c542h, 0c5e8h, 0c68eh, 0c732h, 0c7d7h, 0c87ahword4700cg1dh, 0c9c0h, 0ca62h, 0cb04h, 0cba5h, 0cc46h,0cce6h, 0cd86h, 0ce25h, 0cec3h, 0cf62h, 0d000h,TRANS.ASM AND TABLE.ASM0d09dh, 0d13ah.