ªþ¿ý¤G 80x86 ¤Î 80x87 ¼È¦s¾¹


8086 ¼È¦s¾¹

¼È¦s¾¹¬O¦b CPU ¤¤¤@­Ó¼È®ÉÀx¦s¸ê®Æªº¦a¤è¡C¥¦¦³ÂI¨à¹³°O¾ÐÅé ( DRAM )¡A¦ý¬O¤£¹³°O¾ÐÅé³o»ò¤j¡A¤@­Ó¼È¦s¾¹¥u¦³¤@­Ó¡B¨â­Ó©Î¥|­Ó¦ì¤¸²Õªº¤j¤p¡A¨ì¤F AMD64¡BINTEL64 ( ©Î¦XºÙ x86-64 ) ªº CPU ®É¥N¡A¼È¦s¾¹¤~¦³¥|¦r²Õ ( QWORD¡A¦@ 64 ¦ì¤¸ ) ªº¤j¤p¡CCPU ¥i¥Hª½±µ¹ï¼È¦s¾¹§@¥[¡B´î¡B­¼¡B°£¡B¥B¡B©Î¡B·h²¾µ¥¹Bºâ¡C8086/8088 ¦@¦³ 14 ­Ó 16 ¦ì¤¸ªº¼È¦s¾¹¡A¨ä¦WºÙ³£¥H¨â­Ó­^¤å¦rªí¥Ü¡A¤j­P¥i¤À¬°¥H¤U¥|Ãþ¡C

1.³q¥Î¼È¦s¾¹

¦@¦³¥|­Ó¡A¨ä¦WºÙ¤À§O¬O AX¡BBX¡BCX¡BDX¡A¦b²Õ¦X»y¨¥µ{¦¡¤¤¤j­P¨S¦³¤Ó¤jªº®t§O¡A¦ý¬O¨ä¤¤¥u¦³ AX ( accumulator¡A¤]ºÙ¬°²Ö¥[¾¹) ¥i§@¬°°£ªk©Î­¼ªk¤¤ªº³Q°£¼Æ»P³Q­¼¼Æ¡A·í 16 ¦ì¤¸¤£°÷¤j®É¡A±`±`¥Î DX:AX ¨Óªí¥Ü 32 ¦ì¤¸¡C¦¹¥~³o¥|­Ó¼È¦s¾¹¡A¥u¦³ BX ( base register¡A¤]ºÙ¬°°ò©³¼È¦s¾¹) ¥i¥H³Q§@¬°¦ì§}¦s¨ú¤§¥Î¡CCX ¤]ºÙ¬°­p¼Æ¼È¦s¾¹ ( count register)¡A¥Î©ó­pºâ°j°é¤§¦¸¼Æ©Î¦r¦ê³B²z¤§¦¸¼Æ¡CDX ¤]ºÙ¬°¸ê®Æ¼È¦s¾¹ ( data register)¡A¥i¥Î¨Ó¦s¨ú°ð¡C

³o¥|­Ó¼È¦s¾¹¤]¥i¥H¤À¦¨¨â­Ó 8 ¦ì¤¸ªº¼È¦s¾¹¨Ó¨Ï¥Î¡A¨Ò¦p AX ¥i³Q¤À¦¨¸û§Cªº 8 ¦ì¤¸ºÙ¬° AL¡A¥H¤Î¸û°ªªº 8 ¦ì¤¸ AH ¨Ó¨Ï¥Î¡C¨ä¾l BX¡BCX¡BDX ¤]³£Ãþ¦ü¡C

2.«ü¼Ð»P¯Á¤Þ¼È¦s¾¹

¦³¤­­Ó¡A¨ä¦WºÙ¤À§O¬O SP¡BBP¡BIP¡BSI¡BDI¡C«e­±¨â­Ó SP (stack pointer¡AºÙ¬°°ïÅ|«ü¼Ð)»P(base pointer¡A¤]ºÙ¬°°ò©³«ü¼Ð)¬O»P°ïÅ|(stack)¦³Ãöªº¼È¦s¾¹¡A½Ð°Ñ¦Ò²Ä¤­³¹¤º®e¦³Ãö°ïÅ|ªº³¡¥÷¡A¥HÀò±o¸Ô²Óªº°ïÅ|¸ê®Æ¡C°ïÅ|¬O¤@¶ô°Ï°ì¡A¥Î¨Ó¼È®É¦s©ñ¸ê®Æ¤§¥Î¡A¦b 8086/8088 ¤¤¡A°ïÅ|¬O¥Ñ³Ì°ª¦ì§}¤¤¶}©l¦s©ñ¡A¨C¦¸³£¥²¶·¦s¤J¤@­Ó¦r²Õªºªø«×¡A¨Ã¥Î¤@²Õ«ü¼Ð¡A¨Óªí¥Ü°ïÅ|¤w¸g¨Ï¥Î¨ì¨º¨à¤F¡A³o²Õ«ü¼Ð´N¬O SS:SP¡C¤]´N¬O»¡¡A·í¦¨¬O­n±N¸ê®Æ¦s¤J°ïÅ|®É¡A¸Ó¸ê®ÆÀ³¸Ó¦s©ñ¦b SS:SP ©Ò«üªº¦ì§}¦A§C 2 ­Ó¦ì¤¸²Õ¡AµM«á CPU ¦A¨Ï SP ¤§¤º®e´î 2¡A¨Ï SP ¦A«ü¨ì¤U¤@­Ó¥¼¨Ï¥ÎªºªÅ¶¡¡C

¨º¤°»ò±¡§Î·|­n±N¸ê®Æ¦s¤J°ïÅ|¤º©O¡H¦³¦n´XºØ±¡§Î¡A¨Ò¦p©I¥s°Æµ{¦¡®É¡A·|¹w¥ý§âªð¦^¦ì§}¦s¤J°ïÅ|¡Q©I¥s¤¤Â_®É¤]¬O¦p¦¹¡CBP ³q±`¥Î©ó©I¥s°Æµ{¦¡®É¡A¶Ç»¼°Ñ¼Æ¤§¥Î¡C

IP (instruction pointer¡AºÙ¬°«ü¥O«ü¼Ð) °t¦X CS Åܦ¨ CS:IP¡A«ü¦V±N­n°õ¦æªº 8086/8088 ¦ì§}¡C·í CPU ­n°õ¦æµ{¦¡®É¡A¥²¶·¨ì°O¾ÐÅé¥h´£¨ú­n°õ¦æªº«ü¥O¡A¦Ó­n¨ì¨º¤@­Ó°O¾ÐÅé¦ì§}¥h´£¨ú«ü¥O©O¡H³o®É CPU ´N·|¨ì CS:IP «ü¨ìªº¦ì§}¥h´£¨ú¡C¦bµ{¦¡¤¤¡A¤@¯ë¬O¨S¦³¿ìªk§ïÅÜ CS:IP ªº­È¡A°£«D¬O¸õÅD (jmp¡Bjzµ¥) «ü¥O©Î¬O©I¥s (call¡Bretµ¥) «ü¥O¡C

SI (source index¡AºÙ¬°¨Ó·½¯Á¤Þ¼È¦s¾¹) ©M DI (destination index¡AºÙ¬°¥Øªº¯Á¤Þ¼È¦s¾¹) ³q±`¬O¥Î¨Ó·í§@¦ì§}«ü¼Ð¡A¤]¥i¥Î§@¥[´îªk¡C³o¤­­Ó¼È¦s¾¹¡A¨C¤@­Ó³£¤£¯à¤À¶}¨Ó·í§@¨â­Ó 8 ¦ì¤¸ªº¼È¦s¾¹¨Ï¥Î¡C

3.°Ï¬q¼È¦s¾¹

¦³ CS¡BDS¡BES¡BSS ¥|­Ó¡A¤À§Oªí¥Üµ{¦¡½X(code segment register)¡B¸ê®Æ(data segment register)¡BÃB¥~(extra segment register)¡B°ïÅ|(stack segment register)°Ï¬q¤§¥Î¡C¦b DOS ¨t²Î¤¤¡A¨C¤@­Ó°Ï¬q®e¶q¥u¦³ 64KBytes¡C

·í¸ê®Æ°Ï¬q¤£°÷¥Î®É¡A´N¥i¥H¥ÎÃB¥~°Ï¬q¨Ó¸É¨¬¡A¨Ò¦p·Q­n±N¤@­Ó°Ï¬qªº¬Y¨Ç¤º®e½Æ»s¨ì¥t¤@°Ï¬q¤¤¡A´N¥i¥H¦P®É«ü©w DS¡BES ¤À§Oªí¥Ü³o¨â­Ó°Ï¬q¡C

4.ºX¼Ð¼È¦s¾¹

ºX¼Ð¼È¦s¾¹ (flag register) ¬O¤@­Ó 16 ¦ì¤¸ªº¼È¦s¾¹¡A¦ý¥u¦³¨ä¤¤¤E­Ó¦ì¤¸¦³¥Î¨ì¡A¥¦­Ì¤À´²¦b³o¤Q¤»­Ó¦ì¤¸¤¤¡A±Ä¥Î³oºØ¤À´²¤è¦¡¬O¬°¤F»P¦¡ªº 8080 CPU ªººX¼Ð¬Û¦P¡A¨ä¤À¥¬¦p¤U¹Ï©Ò¥Ü¡G

³o 9 ­ÓºX¼Ð¥i¤À¬°¤TÃþ¡Gª¬ºAºX¼Ð ( status flag )¡B±±¨îºX¼Ð ( control flag ) »P¨t²ÎºX¼Ð ( system flag )¡Cª¬ºAºX¼Ð¥]§t CF¡BPF¡BAF¡BZF¡BSF ©M OF¡A¥¦­Ì·|¨ü¨ìºâ³N¡B¤ñ¸û©ÎÅÞ¿è¹Bºâµ²ªGª¬ºAªº¼vÅT¡A¦Ó¨ÏºX¼Ð³Q³]©w ( set¡A¨ä­È¬° 1 )¡A©Î³Q²M°£ ( clear¡A¨ä­È¬°¹s )¡C²Ä 10 ¦ì¤¸ªº DF ¥Î¨Ó±±¨î±½´y¡B·h²¾¡B·j´M¦r¦êªº¤è¦V¡AÄݩ󱱨îºX¼Ð¡C¦Ü©ó IF¡BTF ¬°³]­p§@·~¨t²Î¡B°£¿ù®É¤~»Ý­n¥Î¨ì¡AÄÝ©ó¨t²ÎºX¼Ð¡A¤@¯ëÀ³¥Îµ{¦¡«Ü¤Ö¨Ï¥Î¡C©³¤U²³æ¤¶²Ð³o¨ÇºX¼Ð¡G

¦WºÙ¦ì¤¸ ª¬ºA»¡©ú
¶i¦ìºX¼Ð
carry flag
CF
0 CF=1¡ACY
CF=0¡ANC
·í¹Bºâµo¥Í¶i¦ì©Î­É¦ì®É¡ACF ³Q³]¬° 1¡F¤Ï¤§³]¬° 0¡C¨Ò¦p¨â¼Æ¬Û¥[¡G
        mov     ax,8000h
        add     ax,8000h
8000h¡Ï8000h À³¬° 10000h¡Aµo¥Í¶i¦ì¡AÁöµM AX ¬° 0¡A¦ý¬O·|¨Ï CF ³]¬°¤@¡Aªí¥Ü¶i¦ì¡C
¦P¦ìºX¼Ð
parity flag
PF
2 PF=1¡APE
PF=0¡APO
¹Bºâªºµ²ªG´«¦¨¤G¶i¦ì«á¡A³Ì§Cªº 8 ­Ó¦ì¤¸¤¤¡A­Y¦³°¸¼Æ­Ó 1¡A«h¦¹¦ì¤¸³]¬° 1¡A¤Ï¤§¬° 0¡C
»²§U¶i¦ìºX¼Ð
auxiliary carry flag
AF
4 AF=1¡AAC
AF=0¡ANA
·í¹Bºâ¹Lµ{¤¤¡A²Ä 3 ¦ì¤¸»P²Ä 4 ¦ì¤¸¤§¶¡µo¥Í¶i¦ì©Î­É¦ì®É¡AAF ³Q³]¬° 1¡A§_«h³Q³]¬° 0¡A±`¥Î©ó BCD ªº¹Bºâ¡C
¹sºX¼Ð
zero flag
ZF
6 ZF=1¡AZR
ZF=0¡ANZ
¹Bºâµ²ªG¬°¹s®É¡AZF ·|³Q³]©w¬° 1¡C­Y¤ñ¸û¬Û¦P¨â¼Æ¡A ZF ¤]·|³Q³]¬°¤@¡A­Y¤ñ¸û¤£¬Û¦Pªº¨â¼Æ¡AZF ·|³Q²M°£¬°¹s¡C¨Ò¦p¡G
        mov     ax,8000h
        add     ax,8000h
¬Û¥[«á¡AAX ¬°¹s¡A¬G ZF ³]¬°¤@¡C
²Å¸¹ºX¼Ð
sign flag
SF
7 SF=1¡ANG
SF=0¡APL
¹Bºâµ²ªGªº³Ì°ª¦ì¤¸¬° 1 ®É¡ASF ·|³Q³]¬° 1 ( ªí¥Ü­t¼Æ )¡A§_«h³Q²M°£¡C
³´¨ÀºX¼Ð
trap flag
TF
8 ¡@ ¥Î©ó³æ¨B°lÂÜ°£¿ù®É¡A©Ò¥H¤]ºÙ¬°°lÂܺX¼Ð ( trace flag )¡A¨Ò¦p¦b MS-DOS ªº DEBUG ¤¤¡A´N¬O§Q¥Î TF ¹F¨ì³æ¨B°lÂܪº¥Øªº¡C·í TF ³]¬°¤@®É¡A¨C°õ¦æ¤@­Ó«ü¥O«K·|µo¥Í¤¤Â_¡A¦¹¤¤Â_´N±N°õ¦æ¸Ó«ü¥O«á¼È¦s¾¹¦C¥X¡C
¤¤Â_ºX¼Ð
interrupt flag
IF
9 IF=1¡AEI
IF=0¡ADI
·í IF ³Q³]©w®É¡A¥i¾B¸nªºµwÅ餤Â_¤~¯à¨Ï CPU ²£¥Í¤¤Â_®ÄªG¡F¤Ï¤§©Ò¦³¥i¾B¸nªºµwÅ餤Â_§¡·|³Q§í¨î¡C¦ý¬O¤£¥i¾B¸n¤¤Â_¥H¤Î CPU ²£¥Íªº¨Ò¥~«o§¹¥þ¤£¨ü IF ¼vÅT¡C
¤è¦VºX¼Ð
direction flag
DF
10 DF=1¡ADN
DF=0¡AUP
·í DF ³Q²M°£®É ( §Y DF=0 )¡A³B²z¦r¦êªº¯Á¤Þ¼È¦s¾¹·|»¼¼W¡A©¹°ª¦ì§}¤è¦V³B²z¡A¤Ï¤§«h»¼´î¡C
·¸¦ìºX¼Ð
overflow flag
OF
11 OF=1¡AOV
OF=0¡ANV

·í¹Bºâµ²ªGµLªk®e¯Ç©ó¥Øªº¹Bºâ¤¸¤¤¡A¦¹ºX¼Ð·|³Q³]¬°¤@¡C¤j­P¥i¤À¤TºØ±¡§Î¡G(1)¨â¦P¸¹¼Æ¬Û¥[©Î¨â²§¸¹¼Æ¬Û´î¡A(2)­¼°£¹Bºâ®É¡A©Ò±oªº¿n©Î°Ó¶W¹L¹Bºâ¤¸¦s©ñ½d³ò¡A¦b²¾¦ì©Î±ÛÂà«ü¥O®É¡A³Ì°ª¦ì¤¸­È¨ü¨ì§ó°Ê ( 0 Åܦ¨ 1 ©Î 1 Åܦ¨ 0 )¡C( ¸Ô²Ó±¡§Î½Ð°Ñ¾\²Ä 35 ³¹·¸¦ì¡C )

¤W­±ªºªí»¡©úºX¼Ð¼È¦s¾¹ªº·N¸q¡C¥HºX¼Ð¼È¦s¾¹ªº¦ì¤¸ 0 ¬°¨Ò¡A¦ì¤¸ 0 ºÙ¬°¡y¶i¦ìºX¼Ð¡z¡A·í¥¦³Q³]©w®É¡A¨ä­È¬° 1¡A¦b DEBUG ùØ¥H CY ªí¥Ü¡F³Q²M°£®É¡A¨ä­È¬° 0¡A¦b DEBUG ùØ¥H NC ªí¥Ü¡C©³¤U¦C¥X DEBUG ¤¤°õ¦æ r «ü¥O«áªº·N¸q¡G

-r [Enter]
AX=0000  BX=0000  CX=0025  DX=0000  SP=FFFE  BP=0000  SI=0000  DI=0000
DS=10F7  ES=10F7  SS=10F7  CS=10F7  IP=0100   NV UP EI PL NZ NA PO NC
10F7:0100 EB19           JMP    0119

¥Õ¦âªº³¡¤À´N¬OºX¼Ðªºª¬ºA¡A½Ð¬Ý¤Uªí¡G

ºX¼Ð¦WºÙ ³]©w(1)²M°£(0)
CF¡A¶i¦ì(¬O/§_)
PF¡A¦P¦ì ( °¸¼Æ/©_¼Æ )
AF¡A»²§U¶i¦ì ( ¬O/§_ )
ZF¡A¹s ( ¬O/§_ )
SF¡A²Å¸¹ ( ¬O/§_ )
IF¡A¤¤Â_ ( ¤¹³\/§í¨î )
DF¡A¤è¦V ( »¼´î/»¼¼W )
OF¡A·¸¦ì ( ¬O/§_ )
CY
PE
AC
ZR
NG
EI
DN
OV
NC
PO
NA
NZ
PL
DI
UP
NV


80x87 ¼È¦s¾¹

³Ì¦­¨Ï¥Î¦b IBM PC ¤Î¬Û®e¾÷ºØªº FPU ¬O 8087¡A«á¨Ó¤S¤À§O¦³¶i¶¥ªº 80287¡B80387¡A¦o­Ì¦XºÙ¬° x87¡Cx87 ¦@¦³¤­Ãþ¼È¦s¾¹¡A¥¦­Ì¬O°ïÅ|¼È¦s¾¹ ( register stack )¡Bª¬ºA¦r²Õ ( status word )¡B±±¨î¦r²Õ ( control word )¡B¼ÐÅÒ¦r²Õ ( tag word )¡B¨Ò¥~«ü¼Ð ( exception pointer )¡C

1.°ïÅ|¼È¦s¾¹

x87 ¦@¦³¤K­Ó°ïÅ|¼È¦s¾¹¡A¨ä¦WºÙ¬O ST(0)¡BST(1)¡BST(2)¡K¡KST(7)¡A¨ä¤¤ ST(0) ³QºÙ¬°°ïÅ|³» ( TOS¡ATop Of Stack )¡A¦b²Õ¦X»y¨¥¤¤¤]¥i²¼g¦¨ ST¡C³o¤K­Ó°ïÅ|¼È¦s¾¹¨C¤@­Ó³£¦³ 80 ¦ì¤¸ªº¤j¤p¨Ó¦s©ñ¯BÂI¼Æ¡A¨Ã¥B¥H¼È®É¹ê¼Æªº§ÎºA¦s©ñ¡A¥i¥H»¡¬Û·íªº·Ç½T¡C·í x87 °õ¦æ FLD¡BFILD µ¥«ü¥O¡A±q°O¾ÐÅ餤ªº¾ã¼Æ¡Bµu¹ê¼Æµ¥¤£¦P®æ¦¡¸ü¤J¼Æ­È®É¡Ax87 ¯à¦Û°ÊÂà´«¦¨¼È®É¹ê¼Æ®æ¦¡¨ì°ïÅ|¼È¦s¾¹ùØ¡F·í x87 ¹J¨ì¹³ FIST¡BFST µ¥«ü¥O¡A­n§â°ïÅ|¼È¦s¾¹¤ºªº¼Æ­È¦s¤J°O¾ÐÅ餤¡Ax87 ·|¦Û°ÊÂà´«¦¨©Ò«ü©wªº®æ¦¡¡C

x87 ¥i¥H°õ¦æ³\¦h½ÆÂøªº­pºâ¡A¦p¨D¥¿©¶¡B¾l©¶¡B¹ï¼Æ¡K¡Kµ¥¹Bºâ¡A³£¬O¥H°ïÅ|¼È¦s¾¹¤ºªº¼È®É¹ê¼Æ¬°¹Bºâªº¸ê®Æ¡A¦]¦¹¤]ºÙ¬°¸ê®Æ¼È¦s¾¹ ( data register )¡C¦³³\¦hªº¹Bºâ³£¬O·|²o¯A¨ì TOS ¡A¦³®É¤]¦³ TOS ©M¨ä¥L°ïÅ|¼È¦s¾¹°µ¹Bºâ¡A©Ò¥H TOS ±`±`¬O¥i¥H¬Ù²¤¡Aµ{¦¡³]­p®v±o¤p¤ß³oºØ¡yÁô§t¡zªº¼gªk¡A¥H§K³y¦¨§xÂZ¡C

³o 8 ­Ó°ïÅ|¼È¦s¾¹ªº¦WºÙ¡AST(0)¡BST(1)¡BST(2)¡K¡Kµ¥µ¥¡A¨Ã¤£¬O©T©w«ü¬Y­Ó°ïÅ|¼È¦s¾¹¡C¦Ó¬O¥Ñª¬ºA¦r²Õ ( ©³¤U»¡©ú ) ªº¤T­Ó ST ¦ì¤¸«ü©w°ïÅ|³»¡A¦Ó¤U¤@­Ó°ïÅ|¼È¦s¾¹´N¬O ST(1)¡B¦A¤U¤@­Ó´N¬O ST(2)¡K¡K¡C

2.±±¨î¦r²Õ

³o­Ó 16 ¦ì¤¸ªº¼È¦s¾¹¨M©w¤F x87 ¹ï¤£¦P¨Ò¥~±ø¥óªº³B²z¡B¦p¦ó±Ë¤J¡B±±¨î¹ê¼Æºë½T«×µ¥µ¥¡C±±¨î¦r²Õªº¦U­ÓÄæ¦ì¦p¤U¹Ï©Ò¥Ü¡G

x87 ±±¨î¦r²Õ
¹ï©ó±±¨î¦r²Õ»¡©ú¦p¤U¡G
  1. X ( ¤]ºÙ¬° IC¡Ainfinity control bit¡AµL­­¤j±±¨î¦ì¤¸ )¡G8087¡B80287 ¦³¨âºØ¤è¦¡¥i¥H¹ï¡yµL½a¤j¡z»P¦³­­¼Æ§@¤ñ¸û¡A¤@ºØ¬O§â¥¿µL½a¤j»P­tµL½a¤j¬Ý¦¨¼Æ½u¤Wªº¨âºÝ¡A¨S¦³¼Æ¤ñ¥¿µL½a¤jÁÙ¤j¡A¤]¨S¦³¼Æ¤ñ­tµL½a¤jÁÙ¤p¡A³o¼Ëªº¤è¦¡¤U¦³­­¼Æ¬O¥i¥H©M¥¿¡B­tµL½a¤j¤ñ¸û¡C¥t¤@ºØ¬O§â¥¿¡B­tµL½a¤j¬Ý¦¨¦P¤@ÂI¡A¬Û·í©ó§â¼Æ½u¶¦X¡A³o®É¦³­­¼Æ¤£¥i¥H©M¥¿¡B­tµL½a¤j¤ñ¸û¡C«eªÌºÙ¡yaffine closure¡z¡AIC ³]¬° 1¡F«áªÌºÙ¡yprojective closure¡z¡AIC ³]¬° 0¡A³oºØ¤è¦¡¤]¬O FINIT «áªº¤º©w­È¡C¦b«á¨Óªº FPU ùØ¡A¨ÃµL¤Ó¤j¥Î³B¡A¦ý¤´«O¯d¤U¨Ó¡A¬°¤F»P 8087¡B80287 ¬Û®e¡C

  2. RC ( rounding control bits¡A±Ë¤J±±¨î¦ì¤¸ )¡G²Ä 10¡B11 ¦ì¤¸¬O¥Î¨Ó¨M©w¦p¦ó°µ±Ë¤J°Ê§@ªº¡C
    RC±Ë¤J±±¨î »¡©ú¨Ò¤l
    00¥|±Ë¤­¤J ¦V³Ìªñªº¾ã¼Æ
    ³{¥|±Ë¥h¡A¹J¤­¶i¦ì
    4.5 ==> 5
    -4.5 ==> -5
    01¦V­tµL½a¤j±Ë¤J ¥¿­È±Ë¥h¤p¼Æ³¡¤À
    ­t­È±Ë¥h¤p¼Æ³¡¤À«á¦A´î¤@
    4.5 ==> 4
    -4.4 ==> -5
    10¦V¥¿µL½a¤j±Ë¤J ¥¿­È±Ë¥h¤p¼Æ³¡¤À«á¦A¥[¤@
    ­t­È±Ë¥h¤p¼Æ³¡¤À
    4.5 ==> 5
    -4.5 ==> -4
    11¦V¹s±Ë¥h ¤£½×¥¿­t­È§¡±Ë¥h¤p¼Æ³¡¤À 4.5 ==> 4
    -4.5 ==> -4


  3. PC ( precision control bits¡Aºë±K«×±±¨î¦ì¤¸ )¡G³o¬O¬°¤F°t¦X¬Y¨Ç¹q¸£¼t°Ó©Ò»s³y¸û§Cºë±K«×ªº¾÷¾¹¦Ó³]ªº¡A¨ä¹ê¦b 8087 ¤º³¡ªº°ïÅ|¼È¦s¾¹³£¬O¥H 80 ¦ì¤¸ªººë±K«× ( ¥ç§Y 64 ¦ì¤¸¦³®Ä¼Æ¡B15 ¦ì¤¸«ü¼Æ¤Î¤@¦ì¤¸²Å¸¹ )¡A¦s©ñ¤Î³B²z¸ê®Æ¡C·íµM¡A¦pªG¦³®Ä¼Æªººë±K«×§C¡A³B²z®É¶¡´N¤ñ¸ûµu¡A¦]¦¹¦pªG¤£¶·°ªºë±K«×¡A¦Ó¤S­n¨D§Ö³tªº±¡§Î¤U¡A¥i¥H³]©w PC ¦ì¤¸¡CPC ¦ì¤¸ªºªí¥Ü¤è¦¡¬O¡G
    00  ªí¥Ü 24 ¦ì¤¸¦³®Ä¼Æ
    01  «O¯d¥¼¨Ï¥Î
    10  ªí¥Ü 53 ¦ì¤¸¦³®Ä¼Æ
    11  ªí¥Ü 64 ¦ì¤¸¦³®Ä¼Æ¡@¡@¤º©w­È
  4. ²Ä 0 ¨ì²Ä 5 ¦ì¤¸¤À§O¬O³B²z¨Ò¥~®Éªº¾B¸n¤è¦¡¡A©Ò¿×¨Ò¥~¬O«ü 80x87 ¹Bºâ®Éµo¥Í¤£¦Xªkªº¾Þ§@¡B°£¥H¹s¡B°ª¹L¤W­­¡B§C©ó¤U­­¡B¤Ï±`­È¡Bºë½T«×¿ù»~³o¤»ºØ±¡§Î¡C·íµo¥Í³o¤»ºØ±¡§Îªº¥ô¦ó¤@ºØ¡A¬O§_­nµo¥X°T¸¹¡A³qª¾ 80x86¡C¦pªG­nÅý 80x86 ª¾¹DºÙ¤§¬°¡y¥¼¾B¸n¡z(unmasked) ¦¹®É¸Ó¹ïÀ³¦ì¤¸³]¬°¹s¡A¨º»ò¦pªGµo¥Í¨Ò¥~®É¡A¥i³y¦¨µ{¦¡¤¤Â_¦Ó¸õ¨ì³]­pªÌ©Ò³]­pªºµ{¦¡¨Ó³B²z¡C¦pªG¤£¨Ï 80x86 ª¾¹DºÙ¬°¡y³Q¾B¸n¡z¡A¹ïÀ³¦ì¤¸³]¬°¤@¡A·í¨Ò¥~µo¥Í®É 80x87 ¯à¦Û°Ê³B²z¡C¦]¬° 80x87 ¹ï¦UºØ¨Ò¥~ªº³B²z¤è¦¡¡A¥i»¡³]­p±o¬Û·í¤£¿ù¡A¦]¦¹¤º©w­È³]¬°¤@¡C¦b FINIT ¤§«á¡A¤]¬O§â³o¤»­Ó¦ì¤¸³]¬° 1¡C¥H¤U¹ï³o¤»ºØ¨Ò¥~±¡§Î¾B¸n¤ÏÀ³°µ»¡©ú¡G

IM¡BDM¡BZM ³o¤T­Ó¦ì¤¸¬O x87 ¦b°õ¦æ«ü¥O¤§«e¡A´N¯à°»´ú¨ìªº¡FOM¡BUM¡BPM «h¬O¦b«ü¥O°õ¦æ«á¡A¤~¯à°»´ú¨ì¡C

3.ª¬ºA¦r²Õ

ÅU¦W«ä¸q¡A³o­Ó¼È¦s¾¹¬O¥Î¨Óªí¥Ü 80x87 ª¬ºAªº¡A¨äµ²ºc¦p¤U¹Ï¡G

x87 ª¬ºA¦r²Õ
¥¦¥]§t¤F¥|¶µ¸ê°T¡C
  1. ¦£¸L«ü¥Ü¾¹ ( busy indicator )¡G¦b²Ä 15 ¦ì¤¸¡A³o­Ó¦ì¤¸ªí¥Ü 8087 ¬O§_¥¿¦b°õ¦æ©R¥O©Î¹Bºâ¡A¨Ã¨S¤Ó¤jªº¥Î³B¡C

  2. ±ø¥ó½X ( condition code )¡G¦b²Ä 14¡B10¡B9¡B8 ¦ì¤¸¡A¥H C3¡BC2¡BC1¡BC0 ªí¥Ü¡A³o´X­Ó¦ì¤¸·|¨ü FTST¡BFCOM¡BFXAM µ¥«ü¥Oªº¼vÅT¡A¤@¯ë³£¬O¥Î¨Ó¤ñ¸û¤j¤p¡A¨M©wµ{¦¡¬yµ{¤À¤ä©Ò¥Î¡C

  3. °ïÅ|³»ºÝ«ü¼Ð ( TOP¡Atop of stack pointer )¡G²Ä 13¡B12¡B11 ¦ì¤¸¡A³o¤T­Ó¦ì¤¸¬O¥Î¨Ó«ü¥Ü²{¦bªº°ïÅ|³»¬O¨º¤@­Ó°ïÅ|¼È¦s¾¹¡C

  4. ¿ù»~ºK­nª¬ºA¡G²Ä 7 ­Ó¦ì¤¸¬° ES ( error summary status )¡A·í¦ì¤¸ 0 ¨ì 5 ¤¤ªº¥ô¤@­Ó¦ì¤¸³]©w®É¡A¦¹¦ì¤¸´N·|³]©w¡C­Y¦¹®É¥¼¸n¾Bªº¸Ü¡A´N·|©I¥s¬ÛÃöªºµ{¦¡°õ¦æ¨Ò¥~³B²z¡C

  5. °ïÅ|¿ù»~¡G²Ä 6 ­Ó¦ì¤¸ºÙ¬° SF ( stack fault ) ¦ì¤¸¡C·í°ïÅ|¼È¦s¾¹¤¤¡Aµo¥Í°ª¹L¤W­­©Î§C©ó¤U­­®É¡Ax87 ·|³]©w¦¹¦ì¤¸¡C

  6. «ü¥Ü¨Ò¥~¡G²Ä 5¡B4¡B3¡B2¡B1¡B0 ¦ì¤¸¡A¨ä§@¥Î¦p¤Uªí¡G

4.¼ÐÅÒ¦r²Õ

8087 ¦³¤@­Ó 16 ¦ì¤¸ªº¼ÐÅÒ¦r²Õ¡A¼ÐÅÒ¦r²Õùئ³¤K­Ó¼ÐÅÒ¡A¨C¨â­Ó¦ì¤¸¬°¤@­Ó¼ÐÅÒ¡A¤À§O¹ïÀ³¨ì¤K­Ó°ïÅ|¼È¦s¾¹¡C¦p¤U¹Ï¡G

x87 ªº¼ÐÅÒ¦r²Õ

¨C­Ó¼ÐÅÒ¥Nªí¬Û¹ïÀ³ªº°ïÅ|¼È¦s¾¹¤º¦s¤Jªº¼Æ­È§ÎºA¡C

  1. 00¡G¥i¥Î¼Æ­È¡A¥]§t¥¿±` ( normal ) ©Î²§±`­È ( unnormal )¡C
  2. 01¡G¹s¡C
  3. 10¡G«D¼Æ­È ( NaN¡ANot a Number )¡BµL½a¤j ( NaN¡ANot a Number )¡B¤Ï±`­È ( denormal )¡C
  4. 11¡GªÅªº¡C

8087 ©Ò¯à³B²zªº¼Æ­È¸ê®Æ§ÎºA¡A°£¤F¤CºØ°ò¥»§ÎºA ( ¦r²Õ¾ã¼Æ¡Bµu¾ã¼Æ¡Bªø¾ã¼Æ¡Bµu¹ê¼Æ¡Bªø¹ê¼Æ¡B¼È®É¹ê¼Æ¡B»E¶° BCD ¾ã¼Æ ) ¤§¥~¡AÁÙ«O¯d¤F¬Y¨Ç¯S®íªº½s½X¤è¦¡¨Óªí¥Ü¯S®íªº¸ê®Æ¡A³o¨Ç¯S®íªº¸ê®Æ¤@¯ëÀ³¥Î¤W¸û¤Ö¨Ï¥Î¡A¥i°Ñ¦Ò²Ä 22 ³¹µù¥|ªº»¡©ú¡C

5.¨Ò¥~«ü¼Ð

¨Ò¥~«ü¼Ð¥]§t¤T­Ó¼È¦s¾¹¡G«ü¥O«ü¼Ð¼È¦s¾¹ ( last instruction pointer )¡B¹Bºâ¤¸«ü¼Ð¼È¦s¾¹ ( last operand pointer¡A¤]¥s¸ê®Æ«ü¼Ð¼È¦s¾¹¡Alast data pointer )¡B«ü¥O½X¼È¦s¾¹ ( last instruction opcode )¡C³o¤T­Ó¼È¦s¾¹¥Î©ó¨Ò¥~µo¥Í®É¡AÅýµ{¦¡ª¾¹Dµo¥Í¨Ò¥~®É¡Ax87 ªº°õ¦æ±¡§Î¡C«ü¥O«ü¼Ð¼È¦s¾¹»P¹Bºâ¤¸«ü¼Ð¼È¦s¾¹³£¬O 48 ¦ì¤¸ªø¡A«ü¥O½X¼È¦s¾¹¬° 11 ¦ì¤¸ªø¡C


80386 ¼È¦s¾¹

¨ì¤F¥Á¹L 74 ¦~¤Q¤ë¡A­^¯Sº¸±À¥X¤F·s¤@¥Nªº CPU¡A80386¡C´N²Õ¦X»y¨¥ªºÆ[ÂI¨Ó¬Ý¡A³oÁû CPU »P¤§«eªº 8086/80286 ¦³«Ü¤jªº¤£¦P¡A¥¦¨ã¦³ 32 ¦ì¤¸¼È¦s¾¹¡A¥i¥H¤@¦¸°µ 32 ¦ì¤¸¹Bºâ¡A¤@ª½¨ì Pentium 4 ¬°¤î¡A³q¥Î¼È¦s¾¹¡B«ü¼Ð»P¯Á¤Þ¼È¦s¾¹¡B°Ï¬q¼È¦s¾¹¡BºX¼Ð¼È¦s¾¹³£¬Û¦P¡C

³q¥Î¼È¦s¾¹

80386 ªº³q¥Î¼È¦s¾¹¦@¦³ 4 ­Ó¡A¤À§O¬O EAX¡BEBX¡BECX¡BEDX¡A¥¦­Ìªº¦WºÙ©M 8086/80286 ³q¥Î¼È¦s¾¹¦WºÙ«Ü¬Û¦ü¡A«e­±ªº¡yE¡zªí¥Ü¡yextended¡z¡A©µ¦ù¤§·N¡C³o¥|­Ó 32 ¦ì¤¸ªº³q¥Î¼È¦s¾¹¡A¨C¤@­Ó¸û§C¦r²Õªº 16 ¦ì¤¸¤S¥i¿W¥ß¦¨¤@­Ó 16 ¦ì¤¸ªº¼È¦s¾¹¡A¦WºÙ»P 8086 ¬Û¦P¡C¦Ó³o§C¦r²Õªº 16 ¦ì¤¸¼È¦s¾¹¤S¥i¦A¤À¦¨°ª¦ì¤¸²Õªº 8 ¦ì¤¸»P§C¦ì¤¸²Õªº 8 ¦ì¤¸¨â­Ó¼È¦s¾¹¡C¨Ò¦p EAX ¸û§C¦r²Õªº 16 ¦ì¤¸¬° AX ¼È¦s¾¹¡AAX ¤S¥i¤À¦¨ AH »P AL ¨â­Ó¤K¦ì¤¸ªº¼È¦s¾¹¡A¦ý¬O EAX ¸û°ª¦r²Õªº 16 ¦ì¤¸µLªk³æ¿W¨Ï¥Î¤F¡A¤]¨S¯S®íªº¦WºÙ¡C¦Ü©ó EBX¡BECX¡BEDX ¤]©M EAX ¬Û¦P¡A¨£¤U¹Ï¡C

AX »P EAX

«ü¼Ð»P¯Á¤Þ¼È¦s¾¹

80386 ¦³ 4 ­Ó 32 ¦ì¤¸ªº«ü¼Ð»P¯Á¤Þ¼È¦s¾¹¡A¤À§O¬O ESP¡BEBP¡BEIP¡BESI¡BEDI¡A¦Ó¨C¤@­Ó¤S¥i¥H§â¸û§Cªº 16 ¦ì¤¸©î¥X¨Ó¨Ï¥Î¡A¤À§OºÙ¬° SP¡BBP¡BIP¡BSI¡BDI¡A¦P¼Ëªº¸û°ªªº¦r²ÕµLªk³æ¿W¨Ï¥Î¡A¤]¨S¯S®íªº¦WºÙ¡C³o¨Ç¼È¦s¾¹ªº¥Îªk»P 8086/80286 ¬Û¦P¡A¨Ò¦p¦b¨Ï¥Î

        rep     movsb

®É¡A´N¥²¶·§â¨Ó·½¦r¦ê¦ì§}¦s©ó ESI¡A¥Øªº¦r¦ê¦ì§}¦s©ó EDI¡A²¾°Êªº¦ì¤¸²Õ¼Æ¦s©ó ECX¡C

°Ï¬q¼È¦s¾¹

80386/80486/Pentium ¦³¤»­Ó 16 ¦ì¤¸ªº°Ï¬q¼È¦s¾¹¡A¤À§O¬O CS¡BDS¡BES¡BSS¡BFS ©M GS¡A¤ñ 8086/80286 ¦h¥X¨â­Ó¡AFS ©M GS¡C«e­±¥|­Óªº¥Îªk»P 8086/80286 ¬Û¦P¡A¨Ò¦p CS «ü¦Vµ{¦¡½X°Ï¬q¡BDS «ü¦V¸ê®Æ°Ï¬q¡C¦h¥X¨Óªº FS ©M GS ¥iµø¬°ÃB¥~°Ï¬q¡C¦ý¬O¦b«OÅ@¼Ò¦¡¤¤°Ï¬qªº·N¸q»P¯u¹ê¼Ò¦¡¤£¦P¡A½Ð°Ñ¦Ò«OÅ@¼Ò¦¡ªº¤åÄm¡C

©µ¦ùºX¼Ð¼È¦s¾¹ ( EFLAG )

»P 8086 ªº 16 ¦ì¤¸ºX¼Ð¼È¦s¾¹¤ñ¸û¡A80386/80486/Pentium ªº©µ¦ùºX¼Ð¼È¦s¾¹¦³ 32 ¦ì¤¸¼e¡AÁöµM¦h¤F¤@¨Ç¤j³¡¤À»P«OÅ@¼Ò¦¡¦³Ãö¨t²ÎºX¼Ð¡A¦ý¤´µM¦³³\¦h¦ì¤¸¥¼³Q¨Ï¥Î¡A¨Ã¥B±±¨îºX¼Ð»Pª¬ºAºX¼Ð³£¯à»P 8086 ¬Û®e¡C¤U¹Ï¬O©µ¦ùºX¼Ðªº¦U¦ì¤¸¦WºÙ¡G

¦WºÙ¦ì¤¸»¡©ú
I/O ¯SÅvµ¥¯Å
I/O privilege level
12¡B13

¦¹¨â¦ì¤¸¬O¥Î¨Ó¨M©wµ{¦¡¬O§_¤¹³\¦s¨ú I/O °ð©Î°õ¦æ»Ý­n¯SÅvµ¥¯Å«ü¥O ( ¦p lgdt¡Bmov cr0,ax µ¥µ¥ )¡A·íµ{¦¡ªº¯SÅvµ¥¯Å ( CPL ) ¤p©ó©Îµ¥©ó IOPL ®É¡A¤~¥i¥H¦s¨ú I/O °ð©Î°õ¦æ»Ý­n¯SÅvµ¥¯Å«ü¥O¡Cª`·N¡A¦b 386 ¤Î¨ä°ª¶¥ CPU ªº«OÅ@¼Ò¦¡¤¤¡A¦@¤À¬° RING0¡BRING1¡BRING2¡BRING3 ¥|ºØ¯SÅvµ¥¯Å¡ARING0 ¬O³Ì°ª¯Å¡A¤@¯ë§@·~¨t²Î¡BÅX°Êµ{¦¡³£¦b³oºØµ¥¯Å¤U°õ¦æ¡CRING3 ¬O³Ì§Cµ¥¯Å¡A¤@¯ëÀ³¥Îµ{¦¡¦b RING3 ¤¤°õ¦æ¡C

Task ¦ê±µºX¼Ð
nested task
NT
14

¦¹ºX¼Ð¥Î¨Óªí¥Ü¥Ø«e°õ¦æªºµ{¦¡ ( task ) ¤§«e¬O§_ÁÙ¦³¨ä¥Lµ{¦¡µ¥«Ý³Q°õ¦æ¡A­Y NT=1¡Aªí¥ÜÁÙ¦³µ{¦¡µ¥«Ý°õ¦æ¡F¤Ï¤§«h§_¡C

¦^´_ºX¼Ð
resume flag
RF
16

¦¹ºX¼Ð¥Î¨Ó¬O§_¼È®É§í¨î°»¿ù¨Ò¥~¡A­Y RF=1¡ACPU ·|¥h³B²z°»¿ù¨Ò¥~¡A¤Ï¤§¤£·|¡C

µêÀÀ 86 ¼Ò¦¡
virtual 86 mode
VM
17

µêÀÀ 86 ¼Ò¦¡ ( V86 mode ) ¥iµø¬°¤@ºØ¯S®íªº«OÅ@¼Ò¦¡¡ACPU ­n¥ý¶i¤J«OÅ@¼Ò¦¡¤§«á¡A¤~¥i¶i¤J V86 ¼Ò¦¡¡A©Ò¥H·í VM=1 ®É¬° V86 ¼Ò¦¡¡FVM=0 ®É¬°«OÅ@¼Ò¦¡¡C

¹ï»ôÀˬd
alignment check
AC
18

·í AC »P CR0 ¼È¦s¾¹¦P®É¬°¤@®É¡ACPU ·|Àˬd°O¾ÐÅé¦s¨ú¦ì§}¬O§_¹ï»ô¡A¨S¦³¹ï»ôªº¦s¨ú°Ê§@·|²£¥Í¡y¹ï»ôÀˬd¨Ò¥~¡z¡C©Ò¿×¡yÀˬd°O¾ÐÅé¦s¨ú¦ì§}¬O§_¹ï»ô¡zªº·N«ä¬O¡G¹ï©ó¦s¨ú¦r²Õ ( word ) ¸ê®Æ«¬ºAªº¸ê®Æ©Ò¦b¦ì§}¥²¶·¬O 2 ªº­¿¼Æ¡B¦s¨úÂù¦r²Õ ( dword ) ¸ê®Æ«¬ºAªº¸ê®Æ©Ò¦b¦ì§}¥²¶·¬O 4 ªº­¿¼Æ¡C

µêÀÀ¤¤Â_ºX¼Ð
virtual interrupt flag
VIF
19

¥Î©ó¦h¤uÀô¹Ò¤U¤ä´©¤¤Â_ºX¼Ð¡C

µêÀÀ¤¤Â_Äa¸mºX¼Ð
virtual interrupt pending flag
VIP
20

¥Î©ó¦h¤uÀô¹Ò¤U¤ä´©¤¤Â_ºX¼Ð¡C

ÃѧOºX¼Ð
identification flag
ID
21

¦pªGÀ³¥Îµ{¦¡¥i¥H²M°£©Î³]©wÃѧOºX¼Ð¡Aªí¥Ü CPU ¤ä´© CPUID «ü¥O¡C

°O¾ÐÅéºÞ²z¼È¦s¾¹

80386/80486/Pentium ¨Ï¥Î¥|­Ó°O¾ÐÅéºÞ²z¼È¦s¾¹¨Ó°O¿ý«OÅ@¼Ò¦¡©³¤U¡A°O¾ÐÅé´y­z¾¹ªí®æ¦ì§}©Ò¦b¡A¥¦­Ì¬O¡G

  1. GDTR ( global descriptor table register¡A¥þ°ì´y­z¾¹ªí®æ¼È¦s¾¹ )¡G¥Î¨Ó°O¿ý GDT ( ¥þ°ì´y­z¾¹ªí®æ ) ©Ò¦b¤§°_©l¦ì§}¡C
  2. LDTR ( local descriptor table register¡A°Ï°ì´y­z¾¹ªí®æ¼È¦s¾¹ )¡G¥Î¨Ó°O¿ý LDT ( °Ï°ì´y­z¾¹ªí®æ ) ©Ò¦b¤§°_©l¦ì§}¡C
  3. IDTR ( interrupt descriptor table register¡A¤¤Â_´y­z¾¹ªí®æ¼È¦s¾¹ )¡G¥Î¨Ó°O¿ý IDT ( ¤¤Â_´y­z¾¹ªí®æ ) ©Ò¦b¤§°_©l¦ì§}¡C
  4. TR ( task register¡ATASK ¼È¦s¾¹ )¡G¥Î¨Ó°O¿ý¥¿¦b°õ¦æªº¤u§@ ( task ) ©Ò¹ïÀ³ªº TSS ( task state segment ) ¿ï¾Ü¾¹¡C

±±¨î¼È¦s¾¹

80386/80486 ¦³¥|­Ó±±¨î¼È¦s¾¹¡A¤À§O¬O CR0¡BCR1¡BCR2¡BCR3¡APentium ÁÙ¦h¤F¤@­Ó CR4¡C

  1. CR0¡G¨äÄæ¦ì¦p¤U¡G
    CR0 ±±¨î¼È¦s¾¹


  2. CR1¡G³Q«O¯d¡A¤£¨Ï¥Î¡C

  3. CR2¡G·í¡y­¶¿ù»~¡z¨Ò¥~ ( page-fault ) µo¥Í®É¡A³y¦¨¿ù»~ªº½u©Ê¦ì§} ( linear address ) ·|Àx¦s¦b CR2¡C

  4. CR3¡G¦¹±±¨î¼È¦s¾¹³B²z¦³Ãö¤À­¶¥Ø¿ý ( page directory )¡A¨äÄæ¦ì¦p¤U¡G
    CR3 ±±¨î¼È¦s¾¹
  5. CR4¡GPentium ¤Î¨ä¥H¤Wµ¥¯Åªº CPU ¤~¦³ CR4 ¼È¦s¾¹¡A80386/80486 ¨S¦³³o­Ó¼È¦s¾¹¡CCR4 ªºÄæ¦ì¦p¤U¡G
    CR4 ±±¨î¼È¦s¾¹