³o¤@³¹¡A¤p¤ì°¸±N¤¶²Ð 8087 ªº«¶bÀ¸¡A¶W¶V«ü¥O¡A±±¨î¦r²Õ¡A³Ì«áµo®i¥X´XÓ¦³Ãöpºâ«ü¼Æªº°Æµ{¦¡¡C
©Ò¿×¶W¶V«ü¥O¬O«ü½ÆÂøªº¨ç¼Æ¹Bºâªº«ü¥O¡C8087 ¦³¤Ó¶W¶V«ü¥O¡A¤@ӥΩó«ü¼Æ¡A¨âӥΩó¦ÛµM¹ï¼Æ¡A¥t¥~¨âӥΩó¤T¨¤¨ç¼Æªºpºâ¡C¹ï©ó 8087 ªº¶W¶V«ü¥O©Ò¿é¤Jªº¤Þ¼Æ©M¼Æ¾Ç¤Wªº¤Þ¼Æ¤£¨£±o¬Û¦P¡A¨Ò¦p¨D 2 ªº X ¦¸¤è¡A¦b¼Æ¾Ç¤W X ¥i¥H¬O¥ô·NÈ¡A¦ý¥Î 8087 pºâ®É X «o¥u¯à¦b 0 ¨ì 0.5 ¤§¶¡¡A¦pªGn¨D 2 ªº¥ô·N¼Æ¦¸¤è±o¥Îµ{¦¡¨Ópºâ¡C°²¦p¦b 8087 µ{¦¡¤¤ªº¤Þ¼Æ¶W¹L³oÓ½d³ò¡A·|¤Þ°_¿ù»~¦ý¬O 8087 «o¨S¦³Àˬd¾÷¨î¡A©Ò¥Hn¤p¤ß¨Ï¥Î¡C
³oÓ«ü¥O¬O¥Î¨Ópºâ 2ST-1 µM«á±Nµ²ªG¦s¦^ ST ùØ¡CF2XM1 ùتº X ªí¥Ü ST ¼È¦s¾¹¡AM ªí¥Ü´îªk¤§·N¡A¥¦ªº»yªk´N¬O
F2XM1
¤£§t¥ô¦ó¹Bºâ¤¸¡C³oÓ«ü¥O¹Bºâ¤§«eÁÙ¦³¤@Ó¨î¡A¨º´N¬O X ¥²¶·¬O¦b 0 ¨ì 0.5 ¤§¶¡ªº¹ê¼Æ¤~¦æ¡A¥i¥Hµ¥©ó 0 ©Î 0.5¡F¦b Pentium µ¥¯Å¤Î¨ä¥H¤W ( µù¤@ )¡AX ¥i¥HÂX¥R¨ì¦b 0 ¨ì 1 ¤§¶¡¡C³oÓ«ü¥O¤§©Ò¥Hn´î¤@ªº¥Øªº¬O¦pªG X «Ü¤p¡A«h 2X ·|«Ü±µªñ¤@¡A´î¥h¤@¥i¼W¥[¦³®Ä¼Æ¡C
³oÓ«ü¥O¬O¥Î¨Ópºâ ST(1)*Log2 ST¡A³oÓ«ü¥O·|¥ý¼u¥X ST µM«á¥Hpºâªºµ²ªG¨ú¥N ST ¼È¦s¾¹¡C³oÓ«ü¥Oªº¨î¬O ST ¥²¶·¬°¥¿¼Æ¡C
³oÓ«ü¥O¬Opºâ ST(1)*Log2( ST+1 )¡Apºâ§¹¦¨¤§«á¡A·|¥ý¼u¥X ST¡AµM«á¦A¥Hpºâªºµ²ªG¨ú¥N ST ¼È¦s¾¹¡CST ¥²¶·¬O¤j©ó¹s¥B¤p©ó¤G¤À¤§®Ú¸¹¤Gªº¼Æ¡C³oÓ«ü¥O¦b ST ¤§È«Ü±µªñ 0 ®É¡A¤ñ FYL2X ¦³¸û¦nªº·Ç½T«×¡C
³oÓ«ü¥O¥Î¨Ópºâ tan ST ¤§µ²ªG¡A¦Ópºâµ²ªG¬O¥H¤À¼Æ Y/X ªº§Î¦¡¦s¤J°ïÅ|¡Apºâ«á¥ý§â tan ST ¤§È±À¤J°ïÅ|(·í§@ Y È)¡A¦A§â 1 (·í§@ X È)±À¤J°ïÅ|¡A´«¥y¸Ü»¡³Ì«áªºµ²ªG¬O ST(1) ¬° tan ST¡AST ¬° 1¡C¦b 8087 µ¥¯Åªº FPU ¹Bºâ®É¡Apºâ«e ST ¥²¶·¬O 0 ¨ì¥|¤À¤§¶ê©P²vªº®|«×¡F¦pªG¦b Pentium µ¥¯Å¤Î¨ä¥H¤Wªº CPU¡A°£¤Fpºâ«e ST ¶·¥H®|«×ªí¥Ü¥~¡A¦ü¥G¨S¦³½d³ò¨î¡C
³oÓ«ü¥O¬O¥Î¨Ópºâ arctan ( ST(1)/ST ) ªº¡AµM«á§âpºâµ²ªG¥H®|«×ªí¥Ü¦s¤J ST¡C¾ãÓpºâ¹Lµ{¬O¥ý¼u¥X°ïÅ|³»·í°µ¤À¥À(X)¡A¦A¼u¥X·sªº°ïÅ|³»( ¤]´N¬Oì¨Óªº ST(1) )·í°µ¤À¤l¡Apºâ Y/X ¤§¤Ï¥¿¤Á¨ç¼Æ¡A¦A§âpºâµ²ªG¦s¦^°ïÅ|³»¡C¦pªG¬O¦b 8087 FPU ¤W¹Bºâ¡Apºâ«e ST »P ST(1) ¥²¶·¬°¥¿È¡A¦Ó¦b Pentium ¤Î¨ä¥H¤Wªº CPU «hµL¦¹¨î¡C
¦b 80387 µ¥¯Å¤Î¨ä¥H¤Wªº FPU ÁÙ´£¨Ñªº§ó¦hªº¶W¶V¨ç¼Æ¡A¤p¤ì°¸¦b¤U±¤¶²Ð¡C
³o¬O¥Î¨Ópºâ°ïÅ|³»ªº¥¿©¶¨ç¼Æ (sin)¡A¦A§âµ²ªG±À¤J°ïÅ|³»¡Apºâ«e°ïÅ|³»¨S¦³½d³òªº¨î¡A¦ýn¨Ï¥Î®|«×¡A80387 µ¥¯Å¤Î¨ä¥H¤Wªº FPU ¤~´£¨Ñ³oÓ«ü¥O¡C
³o¬O¥Î¨Ópºâ°ïÅ|³»ªº¾l©¶¨ç¼Æ (cos)¡A¦A§âµ²ªG±À¤J°ïÅ|³»¡Apºâ«e°ïÅ|³»¨S¦³½d³òªº¨î¡A¦ýn¨Ï¥Î®|«×¡A80387 µ¥¯Å¤Î¨ä¥H¤Wªº FPU ¤~´£¨Ñ³oÓ«ü¥O¡C
³oÓ«ü¥O¥u¦³¦b 80387 µ¥¯Å¤Î¨ä¥H¤Wªº FPU ¤~´£¨Ñ¡A¥¦·|¼u¥X°ïÅ|³»µM«ápºâ sin ST »P cos ST ¤§È¡AµM«á§â sin ST ¤§µ²ªG±À¤J°ïÅ|¼È¦s¾¹¡A¦A§â con ST ¤§µ²ªG±À¤J°ïÅ|¼È¦s¾¹¡A©Ò¥H°ïÅ|³»¬°¾l©¶È¡A ST(1) ¬°¥¿©¶È¡C
8087 «ü¥Oùئ³¨âÓ¦³Ãö 2x ªº«ü¥O¡AFSCALE »P F2XM1¡A¦ý¬O«eªÌ¥u¯à¥Î¦b x ȬO¦b -32768 ©M 32768 ¤§¶¡ªº¾ã¼Æ¡A¦Ó«áªÌ¥u¯à¥Î¦b x ¬O¦b 0 ©M 0.5 ¤§¶¡ªº¹ê¼Æ¡A©Ò¥H°²¦pnpºâ 2 ªº¥ô·N¦¸¤è¡A¥²¶·¥t¼g¤@ӰƵ{¦¡¤~¦æ¡A¦Ó¥BÁÙn§Q¥Î¨ì¼Æ¾Ç¤Wªºì²z¡G
2a+b=2a*2b
À³¥Î¤Wz¼Æ¾Çì²z¡A§ÚÌ¥i¥H§â¥ô·N¹ê¼Æ¤À¦¨¾ã¼Æ³¡¥÷(a)»P¤p¼Æ³¡¥÷(b)¡A¦ý¬O¦Ò¼{¨ì F2XM1 ¥u¯à±µ¨ü¦b 0 ©M 0.5 ¤§¶¡ªº¹ê¼Æ¬°«ü¼Æ¡A¥H¤Î«ü¼Æ¬°t¼Æ®É¡A¥i¥H¤À¦¨¤U±¥|ºØ±¡§Î¡G
;¥Øªº¡G¨D 2 ªº¦¸¤è¼Æ¡A¦¹«ü¼Æ¥i¥H¬O¾ã¼Æ¡Bt¼Æ¡B¯BÂI¼Æ ;¿é¤J¡GST(0)¡G«ü¼Æ ;¿é¥X¡GST(0)¡G2ªº¦¸¤è¼Æ ;¨î¡G8087¥H¤W§¡¥i¨Ï¥Î¥B¥u¯à¥Î©ó EXE ÀÉ ;¦¹°Æµ{¦¡¥Î¨ì°ïÅ|¼È¦s¾¹²`«×¬° ST(3) ;ì²z¬O§Q¥Î 2a+b=2a*2b¡A¦]¬° 8087 «ü¥O FSCALE ¥u¯àpºâ 2 ªº¾ã ;¼Æ¦¸¤è¡AF2XM1 ¥u¯àpºâ 2 ªº¤p¼Æ¦¸¤è¡A¦¹¤p¼Æ¥²¶·¦b 0 ©M 0.5 ¤§¶¡ .8087 ;*************************************** data segment byte public 'data' ;10 half dd 0.5 ;11 µu¹ê¼Æ 0.5 cw dw ? ;12 ±±¨î¦r²Õ sw dw ? ;13 ª¬ºA¦r²Õ data ends ;*************************************** code segment byte public 'code' ;16 assume cs:code,ds:data ;17 public two_p_x_0x ;18 pªí¥Ü¨D«ü¼Æ¦¸¤è¡Bxªí«ü¼Æ¡B ;-----------------------------------0ªí¥Ü8087¥H¤W¥i¨Ï¥Î¡Bxªí¥Ü¥ÎEXE°õ¦æÀÉ two_p_x_0x proc near fstcw cw ;21 ¨ú±o±±¨î¦r²Õ fwait ;22 µ¥«Ý 8087 Àx¦s§¹²¦ push cw ;23 «O¦sì±±¨î¦r²Õ and cw,0f3ffh ;24 ¨Ï±±¨î¦r²ÕÅܦ¨¦VtµL½a¤j±Ë¤J¡A±ý¹F¦¹¥Ø or cw,00400h ;25 ªº¥²¶·¨Ï±±¨î¦r²Õ²Ä 10¡B11 ¦ì¤¸Åܬ° 01 fldcw cw ;26 ¸ü¤J·sªº±±¨î¦r²Õ fld st ; x ; x ;27 frndint ;i=int x; x ;28 ¦VtµL½a¤j±Ë¤J pop cw ;29 ¨ú¦^ªº±±¨î¦r²Õ fldcw cw ; i ; x ;30 ¸ü¤Jªº±±¨î¦r²Õ fsub st(1),st; i ; f=x-i ;31 ST(1)¬°¤p¼Æ³¡¤Àf fxch ; f ; i fld half ; 0.5 ; f ; i ;33 ¸ü¤J 0.5 fxch ; f ; 0.5 ; i ;34 ½Õ¾ã¤p¼Æ³¡ fprem ; adj f ; 0.5 ; i ;35 ¤À¬O§_¶W0.5 fstsw sw ;36 ¨ú±oª¬ºA¦r²Õ fstp st(1) ; f ; i ;37 ¥h±¼ 0.5 f2xm1 ; 2f-1 ; i ;38 ¨D 2 ªº¤p¼Æ³¡¤À¦¸¤è-1 fld1 ; 1 ; 2f-1 ; i ;39 ¸ü¤J 1 faddp st(1),st; 2f ; i ;40 §¹¦¨ 2 ªº¤p¼Æ³¡¤À¦¸¤è test sw,200h ;41 ¤ñ¸û¤p¼Æ³¡¤À¬O§_¤p©ó 0.5 jz less_half ;42 ¤p©ó fld1 ; 1 ; 2f ; i ;45 ¤j©óµ¥©ó®É¤p¼Æ³¡ fadd st,st ; 2 ; 2f ; i ;46 ¤ÀÁÙ±o¼¤W®Ú¸¹¤G fsqrt ; SQ(.5); 2f ; i ;47 ST ¬°®Ú¸¹¤G fmulp st(1),st;SQ()2f; i ;48 §¹¦¨ 2 ªº¤p¼Æ³¡¤À¦¸¤è less_half: fscale ; 2x ; i ;50 ¤w¨D±o 2x fstp st(1) ; 2x ;51 ¥h±¼¾ã¼Æ³¡¤À ret ;52 ªð¦^¥Dµ{¦¡ two_p_x_0x endp ;--------------------------------------- code ends ;*************************************** end two_p_x_0x
±z¥i¥H±N³oӰƵ{¦¡¥[¤J¦Û¤vªºµ{¦¡®w¡A³oӰƵ{¦¡§t¦³¨âӰϬq¡A©Ò¥H¥u¯à¥Î©ó EXE ®æ¦¡ªº°õ¦æÀÉ¡A·í±z¥Ñ¥Dµ{¦¡©I¥s³oӰƵ{¦¡®É¡A¥Dµ{¦¡ªºµ{¦¡½X°Ï¬qÀ³«Å§i¬°¡ycode segment public 'code'¡z¡A¸ê®Æ°Ï¬qÀ³«Å§i¬°¡ydata segment public 'data'¡z¡A³o¼Ë LINK.EXE ´N¯à¨Ï¥Dµ{¦¡ªº¸ê®Æ°Ï¬q»P two_p_x_0x °Æµ{¦¡ªº¸ê®Æ°Ï¬q¦X¦Ó¬°¤@¡A¥Dµ{¦¡ªºµ{¦¡½X°Ï¬q»P two_p_x_0x °Æµ{¦¡ªºµ{¦¡½X°Ï¬q¦X¦Ó¬°¤@¡A½Ð°Ñ¦Ò²Ä¤Q¤@³¹¡C
¤p¤ì°¸¨Ó¥Ü½d¦p¦ó¨Ï¥Î³oӰƵ{¦¡¡C©³¤U³oÓµ{¦¡±Npºâ 2 ªº 3.8 ¦¸¤è¡A¤p¤ì°¸§â¥¦©R¦W¬° TST2P.ASM¡ATST ¬O test ¤§·N¡C
.8087 ;*************************************** stack segment stack dw 40h dup (?) stack ends ;*************************************** data segment public 'data' power dq 3.8 answer dq ? data ends ;*************************************** code segment public 'code' assume cs:code,ds:data extrn two_p_x_0x:near ;--------------------------------------- main proc far start: push ds sub ax,ax push ax mov ax,data mov ds,ax finit fld power call two_p_x_0x fstp answer ret main endp ;--------------------------------------- code ends ;*************************************** end start
³oÓµ{¦¡«Ü²³æ¡A©Ò¥H¤p¤ì°¸¨S¦³¥[¤W¤°»òµù¸Ñ¡A¥u¦b°Ï¬q«Å§i³Bnª`·Nªº¦a¤è¥H¥Õ¦â¼Ð¥X¨Ó¦Ó¤w¡C
H:\HomePage\SOURCE>path h:\homepage\masm50;%path% [Enter] ¡÷ ³]©w¸ô®|¡A¥H«á§K¿é¤J¡y..\masm50\¡z H:\HomePage\SOURCE>masm tst2p; [Enter] Microsoft (R) Macro Assembler Version 5.00 Copyright (C) Microsoft Corp 1981-1985, 1987. All rights reserved. 51576 + 365352 Bytes symbol space free 0 Warning Errors 0 Severe Errors H:\HomePage\SOURCE>link tst2p [Enter] Microsoft (R) Personal Computer Linker Version 2.40 Copyright (C) Microsoft Corp 1983, 1984, 1985. All rights reserved. Run File [TST2P.EXE]:[Enter] List File [NUL.MAP]:[Enter] Libraries [.LIB]:myasmlib [Enter]
¤W±¬O²ÕĶ¥H¤Î³sµ²ªº¨BÆJ¡A©³¤U¥Î SYMDEB.EXE ¸ü¤J TST2P.EXE ¨ÓÆ[¹î¬Ý¬Ý¡C
H:\HomePage\SOURCE>symdeb tst2p.exe [Enter] Microsoft (R) Symbolic Debug Utility Version 4.00 Copyright (C) Microsoft Corp 1984, 1985. All rights reserved. Processor is [80286] -t [Enter] AX=0000 BX=0000 CX=0127 DX=0000 SP=007E BP=0000 SI=0000 DI=0000 DS=2201 ES=2201 SS=2211 CS=221B IP=0001 NV UP EI PL NZ NA PO NC 221B:0001 2BC0 SUB AX,AX -t [Enter] AX=0000 BX=0000 CX=0127 DX=0000 SP=007E BP=0000 SI=0000 DI=0000 DS=2201 ES=2201 SS=2211 CS=221B IP=0003 NV UP EI PL ZR NA PE NC 221B:0003 50 PUSH AX -t [Enter] AX=0000 BX=0000 CX=0127 DX=0000 SP=007C BP=0000 SI=0000 DI=0000 DS=2201 ES=2201 SS=2211 CS=221B IP=0004 NV UP EI PL ZR NA PE NC 221B:0004 B81922 MOV AX,2219 ¡÷¸ê®Æ°Ï¬qªº°Ï¬q¦ì§} -t [Enter] AX=2219 BX=0000 CX=0127 DX=0000 SP=007C BP=0000 SI=0000 DI=0000 DS=2201 ES=2201 SS=2211 CS=221B IP=0007 NV UP EI PL ZR NA PE NC 221B:0007 8ED8 MOV DS,AX -t [Enter] AX=2219 BX=0000 CX=0127 DX=0000 SP=007C BP=0000 SI=0000 DI=0000 DS=2219 ES=2201 SS=2211 CS=221B IP=0009 NV UP EI PL ZR NA PE NC 221B:0009 9B WAIT -dl 0 l2 [Enter] 2219:0000 66 66 66 66 66 66 0E 40 +0.38E+1 ¡÷ 2 ªº 3.8 ¦¸¤è 2219:0008 00 00 00 00 00 00 00 00 +0.0E+0 ¡÷ answer ¦ì§} -ds 10 l1 [Enter] 2219:0010 00 00 00 3F +0.5E+0 ¡÷¦b°Æµ{¦¡ two_p_x_0x ©Ò©w¸qªºÅÜ¼Æ half -dw ds:14 L2 [Enter] 2219:0014 0000 0000 ¡÷¦b°Æµ{¦¡ two_p_x_0x ©Ò©w¸qªºÅÜ¼Æ cw ©M sw -u cs:0 [Enter] 221B:0000 1E PUSH DS 221B:0001 2BC0 SUB AX,AX 221B:0003 50 PUSH AX 221B:0004 B81922 MOV AX,2219 221B:0007 8ED8 MOV DS,AX 221B:0009 9B WAIT 221B:000A DBE3 FINIT 221B:000C 9B WAIT -db ds:0 L30 [Enter] 2219:0000 66 66 66 66 66 66 0E 40-00 00 00 00 00 00 00 00 ffffff.@........ 2219:0010 00 00 00 3F 00 00 00 00-00 00 00 00 00 00 00 00 ...?............ 2219:0020 1E 2B C0 50 B8 19 22 8E-D8 9B DB E3 9B DD 06 00 .+@P8.".X.[c.]..
¥J²ÓÆ[¹î¾ãÓµ{¦¡ªº¸ê®Æ°Ï¬q¬O¦b 2219:0000 ¨ì 2219:0017 ³B¡A³Ì«e±ªº 8 Ӧ줸²Õ(¥Õ¦â)¬O 3.8¡A¦A¨Óªº 8 Ӧ줸²Õ(¬õ¦â)¬O answer ÅܼơA³o¨âÓ³£¦b¥Dµ{¦¡¤¤«Å§iªº¡F±µ¤U¨Óªº 4 Ӧ줸²Õ(ÂŦâ)¬O 0.5¡A¦A¨Óªº¤@Ó¦r²Õ(¾ï¦â)¬O cw¡A¦A¨Óªº¤@Ӧ줸²Õ(µµ¦â)¬O sw¡A³o¤TÓÅܼƬO¦b two_p_x_0x ¤¤«Å§i¡A©M¦b¥Dµ{¦¡¤¤ªº¸ê®Æµ²¦X¦¨¤@Ó¸ê®Æ°Ï¬q¡C
±µ¤U¨Ó¬Oµ{¦¡½X°Ï¬q¡A¤]´N¬O©R¦W¬°¡ycode¡zªº°Ï¬q¡A¸ê®Æ°Ï¬q«áÁÙ¦³ 8 Ӧ줸²Õ¨S¥Î¨ì¡A¦ý¬O code °Ï¬q«o±q 221B:0000 ³B¶}©l¡A³o¬O¦]¬°¨S¦³¯S§O«ü©ú MASM ·|§â°Ï¬q³]©w±q¨C¤@¸`(para)³B¶}©l¡A©Ò¿×¤@¸`¬O«ü 10H Ӧ줸²Õ¡A½Ð°Ñ¦Ò²Ä 11 ³¹¡C221B:0000 ³oÓ¦ì§}¨Æ¹ê¤W©M 2219:0020 ³oÓ¦ì§}¬O¦P¤@Ó¦ì§}¡A¤£«H¡H±z¬Ý¬Ý¥¦Ìªº¤º®e³£¬O 1E 2B C0 ¡K¡K¡C³Ì«á¦A¨Ó¬Ý¬Ý LINK.EXE ¬O¦p¦ó§â¥Dµ{¦¡ªºµ{¦¡½X»P two_p_x_0x °Æµ{¦¡ªºµ{¦¡½X³s¦b¤@°_¡C
-u cs:9 36 [Enter] 221B:0009 9B WAIT 221B:000A DBE3 FINIT 221B:000C 9B WAIT 221B:000D DD060000 FLD QWord Ptr [0000] 221B:0011 E80600 CALL 001A 221B:0014 9B WAIT 221B:0015 DD1E0800 FSTP QWord Ptr [0008] 221B:0019 CB RETF 221B:001A 9B WAIT 221B:001B D93E1400 FSTCW [0014] 221B:001F 9B WAIT 221B:0020 FF361400 PUSH [0014] 221B:0024 81261400FFF3 AND Word Ptr [0014],F3FF 221B:002A 810E14000004 OR Word Ptr [0014],0400 221B:0030 9B WAIT 221B:0031 D92E1400 FLDCW [0014] 221B:0035 9B WAIT 221B:0036 D9C0 FLD ST(0)
«Ü©úÅ㪺¡AÂŦⳡ¥÷´N¬O¥Dµ{¦¡¡A¾ï¦â³¡¥÷¬O two_p_x_0x °Æµ{¦¡¡A³o¬O¦]¬°¦b°Æµ{¦¡¤¤¡A°²«ü¥O¡ysegment¡z¥Î¤F¡ybyte¡z¿ï¶µ¡A©Ò¥H°Æµ{¦¡ªºµ{¦¡½X°Ï¬q¥i¥H¥Ñ¥ô·N¦ì§}¶}©l¡A¦]¦¹ LINK.EXE ±N°Æµ{¦¡ºò±Kªº±µ¦b¥Dµ{¦¡«á±¡C½Ð°Ñ¦Ò²Ä 11 ³¹¥H¨D¿Ä·|³e³q¡C
-g [Enter] Program terminated normally (0) -DL 221B:0 L2 [Enter] 221B:0000 66 66 66 66 66 66 0E 40 +0.38E+1 221B:0008 1F E1 DB DA 8C DB 2B 40 +0.1392880901273798E+2 ¡÷23.8
°õ¦æ¬Ý¬Ý¡AªGµM¤w¸gpºâ¥X 23.8 ¤F¡C
°²¦p¨Ï¥Î Pentium ¨Ópºâ 2x ªº¸Ü¡A±¡§Î´N¨S¦³³o»ò½ÆÂø¡A¦]¬° Pentium µ¥¯Å¥H¤Wªº CPU (©Î NPU) ¨ä F2XM1 ªº«ü¼Æ¥i¥H¬O¦b 0 ¨ì 1 ¤§¶¡¡A¬G¤£¥Î¦A¦Ò¼{«ü¼Æªº¤p¼Æ³¡¤À¬O§_¶W¹L 0.5¡A§¹¾ãªº°Æµ{¦¡¦p¤U¡A¤p¤ì°¸±N¥¦ªºì©lÀɮרú¦W¬° TWO_PX5X.ASM¡G
.8087 ;*************************************** data segment byte public 'data' cw dw ? ;04 ±±¨î¦r²Õ data ends ;*************************************** code segment byte public 'code' assume cs:code,ds:data public two_p_x_5x ;--------------------------------------- ;¥Øªº¡G¨D 2 ªº¦¸¤è¼Æ¡A¦¹«ü¼Æ¥i¥H¬O¾ã¼Æ¡Bt¼Æ¡B¯BÂI¼Æ ;¿é¤J¡GST(0)¡G«ü¼Æ ;¿é¥X¡GST(0)¡G2ªº¦¸¤è¼Æ ;¨î¡GPentium ¥H¤W§¡¥i¨Ï¥Î¥B¥u¯à¥Î©ó EXE ÀÉ ;¦¹°Æµ{¦¡¥Î¨ì°ïÅ|¼È¦s¾¹²`«×¬° ST(3) ;³Æµù¡G1.¦¹°Æµ{¦¡¥i¥H¥Î¦b pentium ¤Î¨ä¥H¤Wµ¥¯Åªº FPU¡C ; 2.¦¹°Æµ{¦¡ì²z¬O§Q¥Î 2a+b=2a*2b¡Aa ªí¥Ü¾ã¼Æ³¡¤À¡Abªí¥Ü¤p¼Æ³¡¤À two_p_x_5x proc near fstcw cw ;19 ¨ú±o±±¨î¦r²Õ fwait ;20 µ¥«Ý pentium Àx¦s§¹²¦ push cw ;21 «O¦sì±±¨î¦r²Õ and cw,0f3ffh;22 ¨Ï±±¨î¦r²ÕÅܦ¨¦VtµL½a¤j±Ë¤J¡A±ý¹F¦¹¥Ø or cw,00400h;23 ªº¥²¶·¨Ï±±¨î¦r²Õ²Ä 10¡B11 ¦ì¤¸Åܬ° 01 fldcw cw ;24 ¸ü¤J·sªº±±¨î¦r²Õ fld st ; x ; x ;25 frndint ;i=int x; x ;26 ¦VtµL½a¤j±Ë¤J pop cw ;27 ¨ú¦^ªº±±¨î¦r²Õ fldcw cw ; i ; x ;28 ¸ü¤Jªº±±¨î¦r²Õ fsub st(1),st ; i ; f=x-i ;29 ST(1)¬°¤p¼Æ³¡¤À¡Af fxch ; f ; i ;30 ¥æ´« f2xm1 ; 2f-1 ; i ;31 ¨D 2 ªº¤p¼Æ³¡¤À¦¸¤è fld1 ; 1 ; 2f-1 ; i ;32 ¸ü¤J 1 faddp st(1),st ; 2f ; i ;33 §¹¦¨ 2 ªº¤p¼Æ³¡¤À¦¸¤è fscale ; 2x ; i ;34 ¨Ï 2 fstp st(1) ; 2x ;35 ¥h±¼¾ã¼Æ³¡¤À ret ;36 ªð¦^¥Dµ{¦¡ two_p_x_5x endp ;--------------------------------------- code ends ;*************************************** end two_p_x_5x
³oӰƵ{¦¡¤]¥i¥H¥[¤J§Ú̪ºµ{¦¡®w¤¤¡A²{¦bªº¹q¸£µ¥¯Å³£¦b Pentium !!! ¥H¤W¡A¦]¦¹³oӰƵ{¦¡À³¸Ón¤ñ two_p_x_0x ÁÙ±`¥Î¤~¹ï¡C
ÁöµM FPU ¨Ã¨S¦³´£¨Ñª½±µpºâ XY ªº«ü¥O¡A¦ý¬O¦³¤F¨D 2X ªº°Æµ{¦¡¡A«Ü®e©ö´N¯à§Q¥Î¼Æ¾Ç¤½¦¡¼g¥X¨D XY ªº°Æµ{¦¡¡C
XY = 2log2XY = 2Ylog2X
®Ú¾Ú¤W±ªº¤½¦¡¡A§ÚÌ¥un¥Î«ü¥O FYL2X ¨D¥X Ylog2X §Y¥i ( ¦ý¦³¨î¡A½Ð°Ñ¦Òµù¤G )¡A¦A§â³oÓ¼ÆȦs¦b FPU ªº°ïÅ|³»¡A©I¥s two_p_x_5x §Y¥i¨D¥X XY¡Aµ{¦¡¦p¤U¡G
.8087 ;*************************************** data segment byte public 'data' sw dw ? ;04 ª¬ºA¦r²Õ data ends ;*************************************** code segment byte public 'code' assume cs:code,ds:data ;--------------------------------------- ;pºâ XY ¤§È¡Aì²z¡GXY=2log2XY=2Ylog2X ;¿é¤J¡GST - ©³¼Æ¡AX ; ST1- «ü¼Æ¡AY ;¿é¥X¡GY¿ù»~(¹sªº¹s¦¸¤è©Î©³¼Æ¬°tÈ)¡A«h¶i¦ìºX¼Ð³Q³]©w¡F ; Y¨S¿ù»~¡A«h¶i¦ìºX¼Ð³Q²M°£¡A¥B ST ¬° X ªº Y ¦¸¤è¡AXY¡A°ïÅ|²`«×´î¤@ ;¨î¡G³oӰƵ{¦¡¥u¯à¥Î¦b Pentium ¥H¤W¡A²ÕĶ¦¨ EXE ÀÉ public x_p_y_5x extrn two_p_x_5x:near x_p_y_5x proc near ftst push ax fstsw sw fwait mov ax,sw ;23 §âª¬ºA¦r²Õ²¾¤J AX sahf ;24 §âª¬ºA¦r²Õªº°ª¦ì¤¸³¡¥÷²¾¤JºX¼Ð jz zero ;25 ©³¼Æ¬°0 jc err1 ;--st0--;--st1--;26 ©³¼Æ¬°t¼Æ ; X ; Y fyl2x ; Ylog2X; call two_p_x_5x ; XY ; exit: clc ;30 ²M°£¶i¦ìºX¼Ð pop ax ret zero: fcomp ;34 ©³¼Æ¬°¹s¡A¼u¥X©³¼Æ ftst ;35 Àˬd«ü¼Æ¬O§_¬°¹s fstsw sw mov ax,sw sahf jz err2 fcomp ;40 ©³¼Æ¬°¹s¡A«ü¼Æ¤£¬°¹s fldz ;41 ¼u¥X©³¼Æ(²Ä34¦æ)¦A¼u¥X jmp exit ;42 «ü¼Æ(¤W¤@¦æ)¡A¦A¸ü¤J¹s err1: fcomp ;44 err2: fcomp ;45 «ü¼Æ»P©³¼Æ§¡¬°¹s©Î©³¼Æ¬°t¼Æ stc ;46 ³]©w¶i¦ìºX¼Ð pop ax ret x_p_y_5x endp ;--------------------------------------- code ends ;*************************************** end x_p_y_5x
³oӰƵ{¦¡¨S¤°»ò·sªºÆ[©À¤F¡A¥u¬Onª`·Nªº¬O¦b¼Æ¾Ç¤W¡A¹sªº¹s¦¸¤è¬OµL·N¸qªº¡A¦]¦¹¤p¤ì°¸¥[¤W¤F¤@¬qµ{¦¡Àˬd«ü¼Æ»P©³¼Æ¬O§_¦P®É¬°¹s¡A¦pªG¬O³o¼Ëªº¸Ü¨º´N³]©w¶i¦ìºX¼Ð¶Ç¦^¥Dµ{¦¡¡A¨Ï¥Dµ{¦¡ª¾¹D³o¬O¿é¤J¿ù»~ªº¤Þ¼Æ¡C
¦pªGn§â x_p_y_5x »s§@¦¨µ{¦¡®w¡A¨Ñµ¹¨ä¥Lµ{¦¡©I¥s¡AÁÙ¦³¤@ÂI·å²«¡C¸Õ¬Ý x_p_y_5x ¥Î¥h¨âÓ°ïÅ|¼È¦s¾¹¡A¦Ó two_p_x_5x ¥Î¥h¥|Ó¡A¦pªG¥Dµ{¦¡¥»¨¤w¦b FPU ùبϥΤTÓ°ïÅ|¼È¦s¾¹¡AÅãµM´N¶W¹L¤F¡C¦]¦¹¡A³Ì¦n¬O¦³¤èªk¯à°÷§â FPU ªºª¬ºA«O¦s°_¨Ó¡Aµ¥ x_p_y_5x nªð¦^¥Dµ{¦¡¤§«e¡A¦A¦^¦s¡C©¯¦n FPU ªº¬ãµo¹Î¶¤¦¤w³]p¤F¤@¨t¦C«ü¥O¡A¥i¥H§â FPU ªºª¬ºA¦s¤J°O¾ÐÅéùØ¡A½Ð°Ñ¦Òµù¤T¡C
«e±©Ò«Ø¥ßªº¨âӰƵ{¦¡¡Gtwo_p_x_5x ¥H¤Î y_p_x_5x ¦]¬°¦³¨âӰϬq¡A¦]¦¹¥u¯à»s§@¦¨ EXE ÀÉ¡A¦pªGn»s§@¦¨ COM ÀÉ©Ò¯à¨Ï¥Îªº°Æµ{¦¡·|¥²¶·§JªA¥t¤@Ó°ÝÃD¡A¨º´N¬O°Æµ{¦¡ªº¸ê®Æ»Pµ{¦¡½X¬O²V¦b¦P¤@°Ï¬qùØ¡A·í¦s¨ú°Æµ{¦¡ªºÅܼƮɡACPU ©Ò±o¨ìªºÅܼƦì§}¬O¿ù»~ªº¡C
¥H two_p_x_5x ¬°¨Ò¡A¦pªG±z¥H¬°¥un§â cw ²¾¨ì°Æµ{¦¡ªºµ{¦¡½X¤º¡A¨Ã§R¥h data °Ï¬q¡AÅܦ¨¤U±³o¼Ë¡A¦s¦¨ TWO_PX5C.ASM¡G
.8087 ;*************************************** code segment byte assume cs:code,ds:code public two_p_x_5c ;--------------------------------------- two_p_x_5c proc near fstcw cw fwait push cw and cw,0f3ffh or cw,00400h fldcw cw fld st ; x ; x ; frndint ;i=int x; x ; pop cw ; fldcw cw ; i ; x ; fsub st(1),st ; i ; f=x-i ; fxch ; f ; i ; f2xm1 ; 2f-1 ; i ; fld1 ; 1 ; 2f-1 ; i ; faddp st(1),st ; 2f ; i ; fscale ; 2x ; i ; fstp st(1) ; 2x ; ret ;ªð¦^¥Dµ{¦¡ cw dw ? ;cw ÅÜ¼Æ two_p_x_5c endp ;--------------------------------------- code ends ;*************************************** end two_p_x_5c
¦pªG¤Wz°Æµ{¦¡¥[¤Jµ{¦¡®w¡A¦A¥H¤U±ªº¥Dµ{¦¡³sµ²¡G
.8087 ;*************************************** code segment public 'code' assume cs:code,ds:code extrn two_p_x_5c:near org 100h ;--------------------------------------- main proc far start: jmp short begin p1 dq 0.5 ;0.5 ¦¸¤è ans1 dq ? ;¨D 2 ªº 0.5 ¦¸¤èµª®×³B p2 dq -2.2 ;-2.2 ¦¸¤è ans2 dq ? ;¨D 2 ªº -2.2 ¦¸¤è begin: finit fld p1 call two_p_x_5c fstp n1 fld p2 call two_p_x_5c fstp n2 ret main endp ;--------------------------------------- code ends ;*************************************** end start
µ²ªG¡Acw ÅܼƷ|¦b 40H ³B¡A¤£«Hªº¸Ü¡A½Ð¬Ý SYMDEB.EXE ¸ü¤Jªº±¡§Î¡G
Microsoft (R) Symbolic Debug Utility Version 4.00 Copyright (C) Microsoft Corp 1984, 1985. All rights reserved. Processor is [80286] -u [Enter] 220E:0100 EB20 JMP 0122 ¡÷¸õ¹L¸ê®Æ°Ï 220E:0102 0000 ADD [BX+SI],AL 220E:0104 0000 ADD [BX+SI],AL 220E:0106 0000 ADD [BX+SI],AL 220E:0108 E03F LOOPNZ 0149 220E:010A 0000 ADD [BX+SI],AL 220E:010C 0000 ADD [BX+SI],AL 220E:010E 0000 ADD [BX+SI],AL -u 122 [Enter] 220E:0122 9B WAIT 220E:0123 DBE3 FINIT 220E:0125 9B WAIT 220E:0126 DD060201 FLD QWord Ptr [0102] 220E:012A E81300 CALL 0140 ¡÷©I¥s two_p_x_5c °Æµ{¦¡ 220E:012D 9B WAIT 220E:012E DD1E0A01 FSTP QWord Ptr [010A] 220E:0132 9B WAIT -u 140 [Enter] 220E:0140 9B WAIT 220E:0141 D93E4000 FSTCW [0040] ¡÷§â±±¨î¦r²Õ¦s¤J CW ÅÜ¼Æ 220E:0145 9B WAIT ¦ý CW ¦ì§}¬O¿ùªº 220E:0146 FF364000 PUSH [0040] 220E:014A 81264000FFF3 AND Word Ptr [0040],F3FF 220E:0150 810E40000004 OR Word Ptr [0040],0400 220E:0156 9B WAIT 220E:0157 D92E4000 FLDCW [0040] -u 179 [Enter] 220E:0179 9B WAIT 220E:017A D9FD FSCALE 220E:017C 9B WAIT 220E:017D DDD9 FSTP ST(1) 220E:017F C3 RET 220E:0180 0000 ADD [BX+SI],AL ¡÷¥¿½Tªº CW ÅܼƩҦb³B
±z·|µo²{¡ACW ÅܼÆÅܦ¨¦b 40H ªº¦ì§}¤F¡A³o·íµM¬O¤£¹ïªº¡ACOM Àɪºµ{¦¡¬O¥Ñ 100H ³B¶}©l¡A100H ¤§«e¬O PSP¡C¤§©Ò¥H·|³o¼Ë¬O¦]¬° MASM §â dw µ¥°²«ü¥O³£¬Ý¦¨ª½±µ±µ¦bµ{¦¡½Xªº CPU «ü¥O¡AMASM §â³oÓ°O¾ÐÅé¦ì§}«O¯dµ¹ CW ¨Ï¥Î¡C·í¥Î LINK ³sµ²®É¡A¤]¬O§â³oÓ°O¾ÐÅé¦ì§}±µ¦bµ{¦¡½X«á±¡A¨Ã¤£¬O±µ¦b¸ê®Æ«á±¡A©Ò¥H¦s¨ú CW ÅܼƮɡACW ªí¥Ü¡y¸ÓÅܼƶZÂ÷°Æµ{¦¡°_©l¦ì§}¦h¤Ö¦ì¤¸²Õ¡z¡A¦ý¤£¬O³sµ²«áªº¥¿½T¦ì§}¡C±z¥i¥H¦b°Æµ{¦¡²ÕĶ®É¡A»s§@¦CªíÀÉÆ[¹îÃÒ©ú³o¤@ÂI¡G
H:\HomePage\SOURCE>masm two_px5c [Enter] Microsoft (R) Macro Assembler Version 5.00 Copyright (C) Microsoft Corp 1981-1985, 1987. All rights reserved. Object filename [two_px5c.OBJ]:[Enter] Source listing [NUL.LST]: two_px5c[Enter] ¡÷»s§@¦CªíÀÉ Cross-reference [NUL.CRF]: [Enter] 50904 + 366040 Bytes symbol space free 0 Warning Errors 0 Severe Errors
Æ[¹î TWO_PX5C.LST ±z¥i¥H¬Ý¨ì¥H¤U¤ù¬q¡G
N a m e Type Value Attr CW . . . . . . . . . . . . . . . L WORD 0040 CODE TWO_P_X_5C . . . . . . . . . . . N PROC 0000 CODE Global Length = 0042 @FILENAME . . . . . . . . . . . TEXT two_px5c
CW ÅܼƦb 0040H ªº¦a¤è¡A¥B¦b°Æµ{¦¡³Ì«á±¡Aªø«×¬°¦r²Õ¡Aªø¤@Ó¦r²Õ¡A©Ò¥H¾ãÓ TWO_P_X_5C ªø 42H Ӧ줸²Õ¡C
ª¾¹D¿ù»~ªºì¦]¤F¡A±µ¤U¨Ón¦p¦ó¸Ñ¨M©O¡H§Ú̲{¦b¤w¸gª¾¹D·íµ{¦¡®w¤ºªº°Æµ{¦¡¤º´O¸ê®Æ©ÎÅܼƮɡA³o¨Ç¸ê®Æ©ÎÅܼƩҪí¥Üªº¦ì§}¨Ã¤£¬O³sµ²«á¯u¥¿¦ì§}¡A¦Ó¬O¶ZÂ÷¸Ó°Æµ{¦¡°_©l¦ì§}¦h¤ÖӦ줸²Õ¡A©Ò¥HÅܼƯu¥¿¦ì§}À³¸Ó¬O¡y¸ÓÅܼƶZÂ÷°Æµ{¦¡°_©l¦ì§}¦h¤ÖӦ줸²Õ¡z¥[¤W¡y°Æµ{¦¡°_©l¦ì§}¡z¡A¦Ó¡y¸ÓÅܼƶZÂ÷°Æµ{¦¡°_©l¦ì§}¦h¤ÖӦ줸²Õ¡z¨ä¹ê´N¬O¤Wzªº¿ù»~¦ì§}¡A¤]´N¬O¸ÓÅܼƩҥNªíªº¦ì§}¡C
¦Ü©ó¡y°Æµ{¦¡°_©l¦ì§}¡zÀ³¬°¡y°Æµ{¦¡¬Y¤@Ó¥¿¦b°õ¦æ¤§«ü¥O¦ì§}¡z´î¥h¡y¸Ó«ü¥O¶ZÂ÷°Æµ{¦¡°_©l¦ì§}¦h¤Ö¦ì¤¸²Õ¡z¡C¨ä¹ê¡y°Æµ{¦¡¬Y¤@Ó¥¿¦b°õ¦æ¤§«ü¥O¦ì§}¡z´N¦s¦b CS:IP ùØ¡A©Ò¥H¥un¨ú±o IP ¤§È§Y¥i¡A¥i±¤Â½¹M©Ò¦³ 80X86 «ü¥O³£¨S¦³³oÓ«ü¥O¡A¤£¹L§Ú̦³Åܳqªº¤èªk¡C·íµ{¦¡©I¥s°Æµ{¦¡®É¡A·|§ân°õ¦æªº¦ì§}±À¤J°ïÅ|¡A¦]¦¹§ÚÌ¥un¡y°²¸Ë¡z©I¥s°Æµ{¦¡¡A¦A¨ì°ïÅ|¨ú¥X°ïÅ|³»´N±o¨ì¥¿°õ¦æªº¦ì§}¤F¡C¦Ó¡y¸Ó«ü¥O¶ZÂ÷°Æµ{¦¡°_©l¦ì§}¦h¤Ö¦ì¤¸²Õ¡z¥i¥H¥Î¤@Ó¹Bºâ¤l¡ATHIS¡A¨Ó¨ú±o(µy«á¤¶²Ð THIS)¡C
¬Ý§¹¤W±»¡©ú¡A¤£³Q·d±oÀY©ü²´ªá¤~©Ç¡A½Ð°Ñ¦Ò¤U¹Ï¡B¤W¤å¡B©³¤Uªº two_p_x_5c °Æµ{¦¡ì©l½X¥H¤Î¥Î SYMDEB ¸ü¤Jªº±¡§Î¡A¥Î¤O·Q·Q¬Ý§a¡C©ÎªÌ°²¦p±zÁÙ¦³§ó¦nªº¤èªk»¡©ú³o¬q½ÆÂøªº¦ì§}Ãö«Y¡A½Ð¨Ó«H«ü¾É¡A¤p¤ì°¸¦b¦¹ÁÂÁ¡C
³oÓ¹Bºâ¤l¬O¥Î¨Ó¨ú±o THIS ©Ò¦b¦ì§}¶Zµ{¦¡°_©l¦ì§}¦h¤ÖӦ줸²Õ¡C¥¦¥²¶·¦b«á±±µ¤W§ÎºA (type)¡A§ÎºA¥i¥H¬O BYTE¡BWORD¡BDWORD¡BQWORD¡BTBYTE¡A¦pªG¬O¥Î¦b¼Ð°O¡A¨ä§ÎºA¥i¥H¬O NEAR¡BFAR¡BPROC¡C
¥Ñ°ïÅ|¤¤¨ú±oªº¡y°Æµ{¦¡¬Y¤@Ó¥¿¦b°õ¦æ¤§«ü¥O¦ì§}¡z´î¥h¥Ñ THIS ¹Bºâ¤l¨ú±oªº¡y¸Ó«ü¥O¶ZÂ÷°Æµ{¦¡°_©l¦ì§}¦h¤Ö¦ì¤¸²Õ¡z´N¬O¡y°Æµ{¦¡°_©l¦ì§}¡z¡A§â¥¦¦s¤J BX ¼È¦s¾¹¡C
BX ¤§È¦A¥[¤W¡y¸ÓÅܼƶZÂ÷°Æµ{¦¡°_©l¦ì§}¦h¤ÖӦ줸²Õ¡z´N¬OÅܼƥ¿½T¦ì§}¡A³o®É¥²¶·¥Î¡y°ò©³¬Û¹ï©w§}ªk¡z¨Ó¨ú±oÅܼƥ¿½T¦ì§}¡G
[BX+¬Û¹ïÈ] [BP+¬Û¹ïÈ]
¬Û¹ïÈ¥i¥H¬O±`¼Æ©ÎÅܼơA¦pªG¬OÅܼƪº¸Ü¡A¤]¥i¥H¼g¦¨
ÅܼÆ[BX] ÅܼÆ[BP]
¥H³oÓµ{¦¡¬°¨Ò¡Acw[bx] ªº·N«ä¬O·|¨ì BX ¼È¦s¾¹»P cw ¬Û¥[«á©Ò±oªº¦ì§}¥h¨ú±o¸Ó¦ì§}ªº¼ÆÈ¡A¦pªG¨S¦³¯S§O¥Î¡yâ¶V°Ï¬q¡z«h·|¨ú±o DS:BX+cw ¦ì§}¤§È¡C¦pªG¼È¦s¾¹¬O BP ªº¸Ü¡A«h·|¨ú±o SS:BP+¬Û¹ïÈ©Ò«üªº¦ì§}¤§¼ÆÈ¡C
¨ú±oÅܼƦì§}«á¡AÁÙ¦³¤@Ó°ÝÃD¦³«Ý§JªA¡A¨º´N¬O§ÚÌ©Ò¨ú±oªº¦ì§}¨ä¹ê¥u¬O°¾²¾¦ì§}¡A¦ÓÅܼƧ¹¾ãªº¦ì§}¬O¥]§t°Ï¬q¦ì§}¡A¥i¬O³oÓÅܼƥ]§t¦b°Æµ{¦¡¤º¡A°Æµ{¦¡·|³Q LINK.EXE ¦w±Æ¦bµ{¦¡½Xªº°Ï¬q¡A¨Ã«D¦b¸ê®Æ°Ï¬q¡A¦]¦¹¦b¦s¨ú¸ÓÅܼƮɡA¥²¶·«ü©w¦bµ{¦¡½X°Ï¬q¡A½Ð°Ñ¦Òì©lµ{¦¡²Ä 17 ¦æ¥H¤Î²Ä 19 ¨ì²Ä 22 ¦æªº¼gªk¡A¤]°_°Ñ¦Ò²Ä 9 ³¹¼È¦s¾¹¶¡±µ©w§}ªº¨º¤@¬q¸¨¡C
ºî¦X¤Wz¡A©³¤Uªº two_p_x_5c °Æµ{¦¡ªº²Ä 17 ¦æ
fstcw cs:cw[bx]
¨ä¹ê¬Û·í©ó
add bx,cw fstcw cs:[bx]
¤p¤ì°¸§â two_p_x_5x °Æµ{¦¡µyµy§ï¼gÅܦ¨ two_p_x_5c¡A¦p¤U¡G
;*************************************** code segment byte assume cs:code,ds:code public two_p_x_5c ;--------------------------------------- ;¥Øªº¡Gpºâ 2 ªº¥ô·N¦¸¤è ;¿é¤J¡GST--«ü¼Æ ;¿é¥X¡GST--2 ªº¾¤è¼Æ ;³Æµù¡G1.¦¹°Æµ{¦¡¥i¥H¥Î¦b pentium ¤Î¨ä¥H¤Wµ¥¯Åªº FPU ¨Ñµ¹ COM¡BEXE ÀÉ©I¥s¡C ; 2.¦¹°Æµ{¦¡ì²z¬O§Q¥Î 2a+b=2a*2b¡Aa ªí¥Ü¾ã¼Æ³¡¤À¡Abªí¥Ü¤p¼Æ³¡¤À two_p_x_5c proc near push bx ;12 µ{¦¡¶}©l³B call rel_ad ;13 ¡y°²¸Ë¡z©I¥s rel_ad addr equ this word ;14 addr°O¿ý¡y¸Ó«ü¥O¶ZÂ÷°Æµ{¦¡°_©l¦ì§}¦h¤Ö¦ì¤¸²Õ¡z rel_ad: pop bx ;15 ¡y°Æµ{¦¡¬Y¤@Ó¥¿¦b°õ¦æ¤§«ü¥O¦ì§}¡z¦s©óBX sub bx,offset addr ;16 BX ¬°¡y°Æµ{¦¡°_©l¦ì§}¡z fstcw cs:cw[bx] ;17 ¨ú±o±±¨î¦r²Õ fwait ;18 µ¥«Ý pentium Àx¦s§¹²¦ push cs:cw[bx] ;19 «O¦sì±±¨î¦r²Õ and cs:cw[bx],0f3ffh;20 ¨Ï±±¨î¦r²ÕÅܦ¨¦VtµL½a¤j±Ë¤J¡A±ý¹F¦¹¥Ø or cs:cw[bx],00400h;21 ªº¥²¶·¨Ï±±¨î¦r²Õ²Ä 10¡B11 ¦ì¤¸Åܬ° 01 fldcw cs:cw[bx] ;22 ¸ü¤J·sªº±±¨î¦r²Õ fld st ; x ; x ;23 frndint ;i=int x; x ;24 ¦VtµL½a¤j±Ë¤J pop cs:cw[bx] ;25 ¨ú¦^ªº±±¨î¦r²Õ fldcw cs:cw[bx] ; i ; x ;26 ¸ü¤Jªº±±¨î¦r²Õ fsub st(1),st ; i ; f=x-i ;27 ST(1)¬°¤p¼Æ³¡¤À¡Af fxch ; f ; i ;28 ¥æ´« f2xm1 ; 2f-1 ; i ;29 ¨D 2 ªº¤p¼Æ³¡¤À¦¸¤è fld1 ; 1 ; 2f-1 ; i ;30 ¸ü¤J 1 faddp st(1),st ; 2f ; i ;31 §¹¦¨ 2 ªº¤p¼Æ³¡¤À¦¸¤è fscale ; 2x ; i ;32 ¨Ï 2 fstp st(1) ; 2x ;33 ¥h±¼¾ã¼Æ³¡¤À pop bx ;34 ¦s¦^ BX ret ;35 ªð¦^¥Dµ{¦¡ cw dw ? ;36 ±±¨î¦r²Õ two_p_x_5c endp ;--------------------------------------- code ends ;*************************************** end two_p_x_5c
¤p¤ì°¸§â·sקï«áªº two_p_x_5c ¥[¤Jµ{¦¡®w¦A¥Î¤Wz¥Dµ{¦¡«·s³sµ²¡A¥Î SYMDEB ¸ü¤J¨ä COM ÀÉÆ[¹î¡G
-u 140 [Enter] ¡÷ª½±µ¨ì two_p_x_5c °Æµ{¦¡°_©l³B 2118:0140 53 PUSH BX 2118:0141 E80000 CALL 0144 2118:0144 5B POP BX 2118:0145 81EB0400 SUB BX,0004 2118:0149 9B WAIT 2118:014A 2ED9BF5100 FSTCW CS:[BX+0051] 2118:014F 9B WAIT 2118:0150 2EFFB75100 PUSH CS:[BX+0051] -g 140 [Enter] AX=0000 BX=0000 CX=0093 DX=0000 SP=FFFC BP=0000 SI=0000 DI=0000 DS=2118 ES=2118 SS=2118 CS=2118 IP=0140 NV UP EI PL NZ NA PO NC 2118:0140 53 PUSH BX ¡÷°Æµ{¦¡°_©l©ó 140H -t [Enter] AX=0000 BX=0000 CX=0093 DX=0000 SP=FFFA BP=0000 SI=0000 DI=0000 DS=2118 ES=2118 SS=2118 CS=2118 IP=0141 NV UP EI PL NZ NA PO NC 2118:0141 E80000 CALL 0144 ¡÷ °²¸Ë©I¥s°Æµ{¦¡ rel_ad -t [Enter] AX=0000 BX=0000 CX=0093 DX=0000 SP=FFF8 BP=0000 SI=0000 DI=0000 DS=2118 ES=2118 SS=2118 CS=2118 IP=0144 NV UP EI PL NZ NA PO NC 2118:0144 5B POP BX ¡÷¥Ñ°ïÅ|¨ú±o©I¥s«áªð¦^¦ì§} -t [Enter] AX=0000 BX=0144 CX=0093 DX=0000 SP=FFFA BP=0000 SI=0000 DI=0000 DS=2118 ES=2118 SS=2118 CS=2118 IP=0145 NV UP EI PL NZ NA PO NC 2118:0145 81EB0400 SUB BX,0004 ¡÷ addr ¶Z°Æµ{¦¡°_©l³B 4 Ӧ줸²Õ -t [Enter] AX=0000 BX=0140 CX=0093 DX=0000 SP=FFFA BP=0000 SI=0000 DI=0000 DS=2118 ES=2118 SS=2118 CS=2118 IP=0149 NV UP EI PL NZ NA PO NC 2118:0149 9B WAIT -t [Enter] AX=0000 BX=0140 CX=0093 DX=0000 SP=FFFA BP=0000 SI=0000 DI=0000 DS=2118 ES=2118 SS=2118 CS=2118 IP=014A NV UP EI PL NZ NA PO NC 2118:014A 2ED9BF5100 FSTCW CS:[BX+0051] CS:0191=0000 -u 187 [Enter] ¡x¡÷°ò©³¬Û¹ï©w§}ªk 2118:0187 DEC1 FADDP ST(1),ST 2118:0189 9B WAIT 2118:018A D9FD FSCALE 2118:018C 9B WAIT 2118:018D DDD9 FSTP ST(1) 2118:018F 5B POP BX 2118:0190 C3 RET 2118:0191 0000 ADD [BX+SI],AL ¡÷ CW ¯u¥¿¦ì§}
¤Wzµ{¦¡ªº²Ä 15 ¦æ¡APOP BX ´N¬O¨ú±o¡y¬Y¤@Ó¥¿¦b°õ¦æ¤§«ü¥O¦ì§}¡z¡A¦Ó²Ä 14 ¦æªº addr equ this word ©Ò¥Nªíªº¼ÆÈ¡A´N¬O¡yPOP BX ³oÓ«ü¥O¶ZÂ÷°Æµ{¦¡°_©l¦ì§}¦h¤Ö¦ì¤¸²Õ¡z¡Crel_ad:©M POP BX ¦b°O¾ÐÅéùØ©Ò¦ûªº¦ì§}¡A¦b MASM ²ÕĶ®É¨Ã¨S¦³§¹¥þ½T©w¡AMASM ¥u¬O±N¥¦¶ZÂ÷°Æµ{¦¡ªº°_©l¦ì§}¦h¤ÖӦ줸²Õ¼g¤J OBJ ÀÉ¡A«Ý³sµ²®É¤~¬Ý¥Dµ{¦¡ªº¤j¤p¯u¥¿pºâ¥X¨Ó¡Caddr ©Ò¦ûªº¦ì§}¦b MASM ²ÕĶ®É¤w¸g½T©w¡A³sµ²®É¤]¤£·|§ó§ï¡C©Ò¥H°²¦p two_p_x_5c °Æµ{¦¡¤£»P¨ä¥Lµ{¦¡³sµ²(¤£³Q¨ä¥Lµ{¦¡©I¥s)¡A³æ¿W¸ü¤J°O¾ÐÅ餺¡Aaddr¡Brel_ad:¡BPOP BX ³o¤TÓ©Ò¦ûªº¦ì§}³£¬O¬Û¦Pªº¡A¦ý¬O¦pªG¥¦»P¨ä¥¦µ{¦¡³sµ²®É¡Arel_ad:¡BPOP BX ©Ò¦ûªº¦ì§}·|ÀH¥Dµ{¦¡¤j¤pÅÜ°Ê¡A¦ý¬O addr ¤´µM¤£ÅÜ¡C
·íµ{¦¡²Ä 13 ¦æ¡y°²¸Ë¡z©I¥s°Æµ{¦¡®É¡A·|§â¤U¤@Ón°õ¦æªº«ü¥O POP BX ¦ì§}±À¤J°ïÅ|¡A²Ä 14 ¦æ¬O°²«ü¥O¡A¥u¬O¼gµ¹²ÕĶ¾¹¬Ýªº¡A©Ò¥H²Ä 13 ¦æ°õ¦æ§¹²¦ª½±µ¨ì²Ä 15 ¦æ¡APOP BX¡A¨ú±o°ïÅ|³»ºÝªº¼ÆÈ¡A¤]´N¬O POP BX¡y¬Y¤@Ó¥¿¦b°õ¦æ¤§«ü¥O¦ì§}¡z¡A¤U¤@¦æ´î¥h¡yPOP BX ³oÓ«ü¥O¶ZÂ÷°Æµ{¦¡°_©l¦ì§}¦h¤Ö¦ì¤¸²Õ¡z´N±o¨ì¡y°Æµ{¦¡°_©l¦ì§}¡z¡A¦¹«á¥un¦s¨úÅܼơA¥u»Ý¥Î¡yÅܼƦW[BX]¡z´N¯à±o¨ì¥¿½T¦ì§}¡C
µù¤@¡G80287¡B80387¡B80487 ªº F2XM1 ªº¤Þ¼Æ³¡¤À¬O¦b 0 ¨ì 0.5 ÁÙ¬O 0 ¨ì 1.0 ¤§¶¡¡A¤p¤ì°¸¨S¦³§ó¸Ô²Óªº¸ê®Æ¡A©Ò¥HµLªk½T©w¡C¦Ó Pentium µ¥¯Åªº¹q¸£¡A¤p¤ì°¸ÁÙ¦³¤@¥x Pentium-100 ªºµ§°O«¬¹q¸£¡A©Ò¥H¥i¥H´ú¸Õ½T©w¦b 0 ¨ì 1.0 ¤§¶¡¡C
µù¤G¡G¦¹¨î¥Dn¬O¦b log ªº¤Þ¼Æ¥²¶·¬°¥¿È¡C
µù¤T¡G
¯à°÷§â x87 ªºª¬ºA¦s¤J°O¾ÐÅ骺«ü¥O¦³ FSAVE ¤Î FNSAVE¡A»P¤§¬Û¹ïªº«ü¥O¬O FRSTOR¡C´«¥y¸Ü»¡¡AFRSTOR ¬O§â°O¾ÐÅ餺®e¡A¦s¦^ x87 ¬Û¹ïÀ³ªº¼È¦s¾¹ùØ¡C¨ä»yªk¬O¡G
FSAVE m94/108byte FNSAVE m94/108byte
FSAVE ¥i¥H§â x87 ªº±±¨î¦r²Õ¡Bª¬ºA¦r²Õ¡B¼ÐÅÒ¦r²Õ¡B«ü¥O«ü¼Ð¡B¹Bºâ¤¸«ü¼Ð¤Î 8 Ó°ïÅ|¼È¦s¾¹¦s¤J°O¾ÐÅ餺¡AµM«á¦A«¸m x87¡C³o¨Ç¼È¦s¾¹©Ò¦s¤Jªº¥Ø¼Ð°O¾ÐÅé®e¶q¬O 94 ¦ì¤¸²Õ©Î 108 ¦ì¤¸²Õ¥H¤Î°O¾ÐÅé¤À°t¦ì§}¡A»Ýµø·í®É FPU ©Ò³BªºÀô¹Ò¨M©w¡A¥i¥H°Ñ¦Ò¤U¹Ï¡G
¤U¹Ï¬° 16 ¦ì¤¸¯u¹ê¼Ò¦¡®É¡AFSAVE ©Ò»Ý°O¾ÐÅé¤À°t±¡ªp¡A»Ý 94 Ӧ줸²Õ¡G
¤U¹Ï¬° 16 ¦ì¤¸«OÅ@¼Ò¦¡®É¡AFSAVE ©Ò»Ý°O¾ÐÅé¤À°t±¡ªp¡A»Ý 94 Ӧ줸²Õ¡G
¤U¹Ï¬° 32 ¦ì¤¸¯u¹ê¼Ò¦¡®É¡AFSAVE ©Ò»Ý°O¾ÐÅé¤À°t±¡ªp¡A»Ý 108 Ӧ줸²Õ¡G
¤U¹Ï¬° 32 ¦ì¤¸«OÅ@¼Ò¦¡®É¡AFSAVE ©Ò»Ý°O¾ÐÅé¤À°t±¡ªp¡A»Ý 108 Ӧ줸²Õ¡G
¥Ñ¤W±¥|±i¹Ï¬Ý¨Ó¡A¤jP¤W¥i¥H»¡¡A¦b 16 ¦ì¤¸ùØ¡A»Ý·Ç³Æ 94 Ӧ줸²Õ¡A±q²Ä 14 Ӧ줸²Õ¶}©l¦s¤J°ïÅ|¼È¦s¾¹¡F¦b 32 ¦ì¤¸®É¡A»Ý·Ç³Æ 108 Ӧ줸²Õ¡A±q²Ä 28 Ӧ줸²Õ¶}©l¦s¤J°ïÅ|¼È¦s¾¹¡C¦Ü©ó FNSAVE ªº¥Îªk©M FSAVE ´X¥G¬Û¦P¡A®t§O¬O¦b©ó¡A°õ¦æ FSAVE «e¡A¦pªG¦³¨Ò¥~µo¥Í¡AFSAVE »Ýµ¥ x87 ³B²z§¹¨Ò¥~ªº±¡§Î¡A¦AÀx¦s¸ê®Æ¡FFNSAVE «h¤£µ¥«Ý¨Ò¥~³B²z¦n¡A´NÀx¦s¸ê®Æ¡C
¦pªGn§â FSAVE/FNSAVE ¦s¤J°O¾ÐÅ骺¸ê®Æ¡A¦A«×¦s¦^ x87 ùتº¦UӼȦs¾¹ùØ¡A¥i¥H¨Ï¥Î FRSTOR «ü¥O¡AFRSTOR «ü¥Oªº»yªk¬°¡G
FRSTOR m94/108byte
¸ò FSAVE/FNSAVE ¤@¼Ë¡AFRSTOR ·|§â 94 Ӧ줸²Õ©Î 108 Ӧ줸²Õªº¸ê®Æ¡A¸ü¤J¨ì x87 ùج۹ïÀ³ªº¼È¦s¾¹ùØ¡A¨Ó·½°O¾ÐÅé¤À°tªº±¡§Î¡A¤]¸ò FASVE/FNSAVE ±¡§Î¤@¼Ë¡C
¥t¥~¡A¶¶±a¤@´£¡AÁÙ¦³¨â²Õ«ü¥O¡G²Ä¤@²Õ¬O FSTENV/FNSTENV »P FLDENV¡F²Ä¤G²Õ¬O FXSAVE »P FXRSTOR¡C²Ä¤@²Õ«ü¥O¤¤ªº FSTENV »P FNSTENV ¬O§â x87 ªºÀô¹Ò¦s¤J°O¾ÐÅéùØ¡AµM«á¾B¸n©Ò¦³¨Ò¥~¦ì¤¸¡FFLDENV «h¬O§â¨ä«á©Ò±µªº°O¾ÐÅ餺®e¡A¦s¦^ x87 Àô¹ÒùØ¡C³o¤TÓ«ü¥Oªº»yªk¬O¡G
FSTENV m14/28byte FNSTENV m14/28byte FLDENV m14/28byte
FSTENV/FNSTENV »P FLDENV «ü¥Oùتº x87 Àô¹Ò ( environment ) ¥]§t±±¨î¦r²Õ¡Bª¬ºA¦r²Õ¡B¼ÐÅÒ¦r²Õ¡B«ü¥O«ü¼Ð¡B¹Bºâ¤¸«ü¼Ð©M«ü¥O½X¡A¤]´N¬O»¡¡A©M FSAVE/FNSAVE/FRSTOR ¤ñ¸û¡A¤Ö¤F 8 Ó°ïÅ|¼È¦s¾¹¡C©Ò±µªº¥Øªº°O¾ÐÅé¤j¤p¡A©M FSAVE/FNSAVE/FRSTOR ¬Û¤ñ¡A¤]¤Ö¤F 8 Ó°ïÅ|¼È¦s¾¹¡C