Ch 24 FPU (3) «ü¼Æ

³o¤@³¹¡A¤p¤ì°¸±N¤¶²Ð 8087 ªº­«¶bÀ¸¡A¶W¶V«ü¥O¡A±±¨î¦r²Õ¡A³Ì«áµo®i¥X´X­Ó¦³Ãö­pºâ«ü¼Æªº°Æµ{¦¡¡C

¶W¶V«ü¥O

©Ò¿×¶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ªG­n¨D 2 ªº¥ô·N¼Æ¦¸¤è±o¥Îµ{¦¡¨Ó­pºâ¡C°²¦p¦b 8087 µ{¦¡¤¤ªº¤Þ¼Æ¶W¹L³o­Ó½d³ò¡A·|¤Þ°_¿ù»~¦ý¬O 8087 «o¨S¦³Àˬd¾÷¨î¡A©Ò¥H­n¤p¤ß¨Ï¥Î¡C

F2XM1 «ü¥O

³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¤§©Ò¥H­n´î¤@ªº¥Øªº¬O¦pªG X «Ü¤p¡A«h 2X ·|«Ü±µªñ¤@¡A´î¥h¤@¥i¼W¥[¦³®Ä¼Æ¡C

FYL2X «ü¥O

³o­Ó«ü¥O¬O¥Î¨Ó­pºâ ST(1)*Log2 ST¡A³o­Ó«ü¥O·|¥ý¼u¥X ST µM«á¥H­pºâªºµ²ªG¨ú¥N ST ¼È¦s¾¹¡C³o­Ó«ü¥Oªº­­¨î¬O ST ¥²¶·¬°¥¿¼Æ¡C

FYL2XP1 «ü¥O

³o­Ó«ü¥O¬O­pºâ ST(1)*Log2( ST+1 )¡A­pºâ§¹¦¨¤§«á¡A·|¥ý¼u¥X ST¡AµM«á¦A¥H­pºâªºµ²ªG¨ú¥N ST ¼È¦s¾¹¡CST ¥²¶·¬O¤j©ó¹s¥B¤p©ó¤G¤À¤§®Ú¸¹¤Gªº¼Æ¡C³o­Ó«ü¥O¦b ST ¤§­È«Ü±µªñ 0 ®É¡A¤ñ FYL2X ¦³¸û¦nªº·Ç½T«×¡C

FPTAN «ü¥O

³o­Ó«ü¥O¥Î¨Ó­pºâ tan ST ¤§µ²ªG¡A¦Ó­pºâµ²ªG¬O¥H¤À¼Æ Y/X ªº§Î¦¡¦s¤J°ïÅ|¡A­pºâ«á¥ý§â tan ST ¤§­È±À¤J°ïÅ|(·í§@ Y ­È)¡A¦A§â 1 (·í§@ X ­È)±À¤J°ïÅ|¡A´«¥y¸Ü»¡³Ì«áªºµ²ªG¬O ST(1) ¬° tan ST¡AST ¬° 1¡C¦b 8087 µ¥¯Åªº FPU ¹Bºâ®É¡A­pºâ«e ST ¥²¶·¬O 0 ¨ì¥|¤À¤§¶ê©P²vªº®|«×¡F¦pªG¦b Pentium µ¥¯Å¤Î¨ä¥H¤Wªº CPU¡A°£¤F­pºâ«e ST ¶·¥H®|«×ªí¥Ü¥~¡A¦ü¥G¨S¦³½d³ò­­¨î¡C

FPATAN «ü¥O

³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¡A­pºâ Y/X ¤§¤Ï¥¿¤Á¨ç¼Æ¡A¦A§â­pºâµ²ªG¦s¦^°ïÅ|³»¡C¦pªG¬O¦b 8087 FPU ¤W¹Bºâ¡A­pºâ«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

FSIN «ü¥O

³o¬O¥Î¨Ó­pºâ°ïÅ|³»ªº¥¿©¶¨ç¼Æ (sin)¡A¦A§âµ²ªG±À¤J°ïÅ|³»¡A­pºâ«e°ïÅ|³»¨S¦³½d³òªº­­¨î¡A¦ý­n¨Ï¥Î®|«×¡A80387 µ¥¯Å¤Î¨ä¥H¤Wªº FPU ¤~´£¨Ñ³o­Ó«ü¥O¡C

FCOS «ü¥O

³o¬O¥Î¨Ó­pºâ°ïÅ|³»ªº¾l©¶¨ç¼Æ (cos)¡A¦A§âµ²ªG±À¤J°ïÅ|³»¡A­pºâ«e°ïÅ|³»¨S¦³½d³òªº­­¨î¡A¦ý­n¨Ï¥Î®|«×¡A80387 µ¥¯Å¤Î¨ä¥H¤Wªº FPU ¤~´£¨Ñ³o­Ó«ü¥O¡C

FSINCOS «ü¥O

³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 ­pºâ 2x ªº°Æµ{¦¡

­ì²z

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°²¦p­n­pºâ 2 ªº¥ô·N¦¸¤è¡A¥²¶·¥t¼g¤@­Ó°Æµ{¦¡¤~¦æ¡A¦Ó¥BÁÙ­n§Q¥Î¨ì¼Æ¾Ç¤Wªº­ì²z¡G

2a+b=2a*2b

À³¥Î¤W­z¼Æ¾Ç­ì²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

¦ý¬O¹ê»Ú¤W¼¶¼gµ{¦¡®É¡A¦pªG¥Î FRNDINT ¦V­tµL½a¤j¤è¦V±Ë¤J¡A¨D¥X¾ã¼Æ³¡¤À¡A¦A¥Î«ü¼Æ´î¥h¾ã¼Æ³¡¤À±o¨ì¤p¼Æ³¡¤À¡A¨º²Ä¤@ºØ±¡§Î»P²Ä¤TºØ±¡§Î¬O¤@¼Ëªº¡A²Ä¤GºØ±¡§Î»P²Ä¥|ºØ±¡§Î¬O¤@¼Ëªº¡A©Ò¥H¹ê»Ú¤W¥u­n¦Ò¼{¤p¼Æ³¡¤À¬O§_¶W¹L 0.5 ¨âºØ±¡§Î´N¥i¥H¤F¡C§¹¾ãªºµ{¦¡¦p¤U¡A§Ú±N¥¦¨ú¦W¬° TWO_PX0X.ASM( 0 ªí¥Ü 8087 ¥H¤W¥i¨Ï¥Î¡A²Ä¤G­Ó X ªí¥Ü¥u¯à¥Î©ó EXE ÀÉ)¡G

;¥Øªº¡G¨D 2 ªº¦¸¤è¼Æ¡A¦¹«ü¼Æ¥i¥H¬O¾ã¼Æ¡B­t¼Æ¡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²ÕÅܦ¨¦V­tµ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 ¦V­tµ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­Óµ{¦¡±N­pºâ 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³B­nª`·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¸g­pºâ¥X 23.8 ¤F¡C


¥Î Pentium ­pºâ 2x ªº°Æµ{¦¡

°²¦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¾ã¼Æ¡B­t¼Æ¡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²ÕÅܦ¨¦V­tµ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 ¦V­tµ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


¨D XY

Áöµ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§Ú­Ì¥u­n¥Î«ü¥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¡G­Y¿ù»~(¹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¬O­nª`·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ªG­n§â 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


¨Ñ COM µ{¦¡®w¨Ï¥Îªº°Æµ{¦¡

ÅܼƦì§}¿ù»~ªº°ÝÃD

«e­±©Ò«Ø¥ßªº¨â­Ó°Æµ{¦¡¡Gtwo_p_x_5x ¥H¤Î y_p_x_5x ¦]¬°¦³¨â­Ó°Ï¬q¡A¦]¦¹¥u¯à»s§@¦¨ EXE ÀÉ¡A¦pªG­n»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¬°¥u­n§â 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¤W­z°Æµ{¦¡¥[¤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

µ{¦¡½X¤º´OÅܼƮɡA¨ú±o¥¿½T¦ì§}¤§¤èªk

ª¾¹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¤W­zªº¿ù»~¦ì§}¡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¥u­n¨ú±o IP ¤§­È§Y¥i¡A¥i±¤Â½¹M©Ò¦³ 80X86 «ü¥O³£¨S¦³³o­Ó«ü¥O¡A¤£¹L§Ú­Ì¦³Åܳqªº¤èªk¡C·íµ{¦¡©I¥s°Æµ{¦¡®É¡A·|§â­n°õ¦æªº¦ì§}±À¤J°ïÅ|¡A¦]¦¹§Ú­Ì¥u­n¡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µ{¦¡½X¤º´OÅܼƥ¿½T¦ì§}»¡©ú¹Ï

THIS ¹Bºâ¤l

³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

°ò©³¬Û¹ï©w§}ªk

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

­â¶V°Ï¬q

¨ú±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

¾ã²z

ºî¦X¤W­z¡A©³¤Uªº two_p_x_5c °Æµ{¦¡ªº²Ä 17 ¦æ

fstcw   cs:cw[bx]

¨ä¹ê¬Û·í©ó

add     bx,cw
fstcw   cs:[bx]

two_p_x_5c ­ì©lµ{¦¡

¤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
;---------------------------------------
;¥Øªº¡G­pºâ 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²ÕÅܦ¨¦V­tµ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 ¦V­tµ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¥Î¤W­z¥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¥¿¦ì§}

¤W­zµ{¦¡ªº²Ä 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¦¹«á¥u­n¦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¦¹­­¨î¥D­n¬O¦b log ªº¤Þ¼Æ¥²¶·¬°¥¿­È¡C

µù¤T¡G

FSAVE/FNSAVE »P FRSTOR «ü¥O

¯à°÷§â 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
16 ¦ì¤¸¯u¹ê¼Ò¦¡®É¡AFSAVE ©Ò»Ý°O¾ÐÅé¤À°t¹Ï

¤U¹Ï¬° 16 ¦ì¤¸«OÅ@¼Ò¦¡®É¡AFSAVE ©Ò»Ý°O¾ÐÅé¤À°t±¡ªp¡A»Ý 94 ­Ó¦ì¤¸²Õ¡G
16 ¦ì¤¸«OÅ@¼Ò¦¡®É¡AFSAVE ©Ò»Ý°O¾ÐÅé¤À°t¹Ï

¤U¹Ï¬° 32 ¦ì¤¸¯u¹ê¼Ò¦¡®É¡AFSAVE ©Ò»Ý°O¾ÐÅé¤À°t±¡ªp¡A»Ý 108 ­Ó¦ì¤¸²Õ¡G
32 ¦ì¤¸¯u¹ê¼Ò¦¡®É¡AFSAVE ©Ò»Ý°O¾ÐÅé¤À°t¹Ï

¤U¹Ï¬° 32 ¦ì¤¸«OÅ@¼Ò¦¡®É¡AFSAVE ©Ò»Ý°O¾ÐÅé¤À°t±¡ªp¡A»Ý 108 ­Ó¦ì¤¸²Õ¡G
32 ¦ì¤¸«OÅ@¼Ò¦¡®É¡AFSAVE ©Ò»Ý°O¾ÐÅé¤À°t¹Ï

¥Ñ¤W­±¥|±i¹Ï¬Ý¨Ó¡A¤j­P¤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ªG­n§â 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


¦^¨ì­º­¶¡A ¨ì²Ä¤G¤Q¤T³¹¡A ¨ì²Ä¤G¤Q¤­³¹