Ch 36 ¤¤Â_


¤¤Â_

¤¤Â_²¤¶

²³©Ò¬Òª¾¡A¹q¸£¬O¥Î¨Ó³B²z¸ê®Æªº¡A§Ú­Ì±N³\¦h¸ê®Æ¿é¤J¹q¸£¡AµM«á¸g¥Ñ¹q¸£¤¤ CPU ªº±j¤j¹Bºâ¥\¯à¡AÀò±o§Ú­Ì©Ò­nªºµ²ªG¡CµM¦Ó¦b¹q¸£¤u§@®É¡A¦³®É¤´µM·|¦³³\¦h­«­nªº¸ê®Æ¥²¶·¥ß§Y±µ¦¬³B²z¡A§_«h·|³y¦¨¸ê®Æªº¿ò¥¢¡A¨Ò¦p¡A¹q¸£¥¿¤u§@®É¡A¨Ï¥ÎªÌ¬ðµM«ö¤UÁä½L¤Wªº«öÁä¡A³o®É¹q¸£±oÀu¥ý³B²z¨Ï¥ÎªÌªº«öÁä¡A§_«h¸ê®Æ´N¬y¥¢¤F¡C

¤@¯ë¹q¸£½u¸ô³]­p¤§ªì´N·|¦Ò¼{³o­Ó°ÝÃD¡A¤j­P¥i¥H¥Î¨âºØ¤è¦¡¸Ñ¨M³o­Ó°ÝÃD¡C²Ä¤@ºØ¬O§Þ¥©¬O±Ä¥Î½ü¸ß ( polling ) ªº¤è¦¡¡A¹q¸£¨C¹j¤@¬q®É¶¡¬d¸ß¦U­Ó©PÃä³]³Æ¬O§_¦³¸ê®Æ¡A°²¦p¨Ï¥Î³oºØ¤è¦¡ªº¸Ü¡A©PÃä³]³Æ¤]»Ý­n³]­p¤@­ÓÃB¥~ªº½w½Ä°Ï¡A§â¸ê®Æ¦s¦b¸Ó³B¡Aµ¥¹q¸£¬d¸ß®É¦A¥æ¥Ñ¹q¸£¨ú¥X³B²z¡C²Ä¤GºØ§Þ¥©¬O¤¤Â_¡A·í¹q¸£ªº©PÃä³]³Æ¦³¸ê®Æ²£¥Í®É¡A©PÃä³]³Æ·|³qª¾ CPU¡A¦Ó CPU ·|¥ýÀÁ¤U¥Ø«eªº¤u§@¨Ã§â·í®Éªºª¬ºA¦s°_¨Ó¡AµM«á³B²z³o¨Ç¸ê®Æ¡A«Ý³B²z§¹¦¨«á¡A¦AÄ~Äò³Q¥´Â_ªº¤u§@¡CIBM PC ¤Î¨ä¬Û®e¹q¸£±Ä¨ú¤¤Â_ªº¤è¦¡³B²z¬ð¦p¨ä¨Óªº¸ê®Æ¡C¨Æ¹ê¤W¡A¦b¤é±`¥Í¬¡¤¤¡A¤]¦³«Ü¦h³o¼Ëªº¨Ò¤l¡C¨Ò¦p¦b¦Y¶º®É¡A¬ðµM¹q¸Ü¹aÁnÅT°_¡A§Ú­Ì´N·|¥ý©ñ¤U¸_¤l¡A±µÅ¥¹q¸Ü¡Aµ¥³q¸Ü§¹²¦«á¡A¦AÄ~Äò¦Y¶º¡C±µÅ¥¹q¸Ü³o­Ó°Ê§@¡A«K¹³¬O¤¤Â_¤@¯ë¡C

¦b IBM PC ¤Î¨ä¬Û®e¹q¸£¯à³B²z 256 ­Ó¤¤Â_¡A±q²Ä¹s¸¹¨ì 0FFH¡C³o¨Ç¤¤Â_³B²z¨Ó¦Û¦UºØ¤£¦Pªº©PÃä³]³Æ©ÎªÌ¬O¨Ó¦Û³nÅ骺­n¨D¡A¦b IBM PC ¤Î¨ä¬Û®e¹q¸£ªº¤¤Â_¥i¤À¬°¨âºØ¡G

  1. ³nÅ餤Â_ ( software interrupt )¡G¥ÑÀ³¥Îµ{¦¡°õ¦æ¨ì INT «ü¥O©Ò²£¥Íªº¤¤Â_¡C³oÃþ¤¤Â_´X¥G³£¬O§@·~¨t²Î¡BBIOS µ¥´£¨ÑªºªA°Èµ{¦¡¡A¥Î¨Ó°õ¦æÀ³¥Îµ{¦¡©Ò­n¨Dªº¥\¯à¡A¨Ò¦p¦b¿Ã¹õ¤W¦L¥X¤å¦rµ¥µ¥¡C³oÃþ¤¤Â_³Ì¬°±`¥Îªº¬O MS¡ÐDOS ©Ò´£¨Ñªº INT 21H¡A¨ä¥LÁÙ¦³ BIOS ©Ò´£¨Ñªº INT 16H¡BINT 10H µ¥µ¥¡C
  2. µwÅ餤Â_ ( hardware interrupt )¡G¥Ñ¦UºØ©PÃä³]³ÆªºµwÅé©Ò²£¥Íªº¤¤Â_¡A¨Ò¦pÁä½L¡BºÏºÐ¾÷¡B­p®É¾¹¡K¡K¡A¬Æ¦Ü CPU ¦Û¤v¤]·|²£µwÅ餤Â_¡C( ¸Ô²Ó±¡§Î¡A½Ð°Ñ¦Òµù¤G )

¤£ºÞ¬O³nÅ餤Â_©ÎµwÅ餤Â_¡A¥¦­Ì¥»¨­¨ä¹ê³£¬O¤@­Ó­Óªºµ{¦¡¡AºÙ¬°¤¤Â_ªA°Èµ{¦¡ ( interrupt service routine¡AISR )¡A¥Î¨Ó³B²z¯S©wªº¥\¥Î¡A¨º»ò CPU ¬O¦p¦ó±oª¾¦U­Ó¤¤Â_ªA°Èµ{¦¡¦b¨º¤@­Ó¦ì§}¡A¦nÅý CPU ¦b³B²z¤¤Â_®É¸õÅD¦Ü¸Ó¦ì§}©O¡H­ì¨Ó¨C¦¸¤@¶}¾÷®É¡ABIOS¡BDOS ©Î¨ä¥LÅX°Êµ{¦¡µ¥¡A·|¦b°O¾ÐÅé¦ì§} 0000:0000 ¨ì 0000:03FF ( ¥H 16 ¶i¦ìªí¥Ü ) ¤§¶¡ªº 1KB ùØ¡A³]©w¤¤Â_¦V¶qªí ( interrupt vector table )¡A©³¤U¬O¤p¤ì°¸¹q¸£¥H MS¡ÐDOS ¶}¾÷«á¡A¥Î SYMDEB Æ[¹î 0000:0000 ³Bªº°O¾ÐÅ餺®e¡G

-d 0:0 L30
0000:0000  57 92 19 00 F4 06 70 00-16 00 E7 0D F4 06 70 00  W...t.p...g.t.p.
0000:0010  F4 06 70 00 54 FF 00 F0-BF 00 00 F0 67 00 00 F0  t.p.T..p?..pg..p
0000:0020  3C 00 E7 0D 45 00 E7 0D-57 00 E7 0D 6F 00 E7 0D  <.g.E.g.W.g.o.g.
-

¤£¦Pªº¹q¸£¡A¦] BIOS¡BDOS ª©¥»©M¸ü¤JÅX°Êµ{¦¡¤£¦P¡A¦b³o 1KB ªº¤¤Â_¦V¶qªíùتº¤º®e¤£ºÉ¬Û¦P¡A¤£¹L¥u­n¬O IBM PC ¤Î¨ä¬Û®e¹q¸£ªº¤¤Â_¦V¶qªí¥²¦s©ó 0000:03FF ³B¦Ó¥B¨C­Ó¤¤Â_³£¬O¥Î¤@­ÓÂù¦r²Õ ( §Y¨â­Ó¦r²Õ©Î¥|­Ó¦ì¤¸²Õ ) ¨Óªí¥Ü¡G
¡@¡@²Ä¹s¸¹¤¤Â_§Y¥Ñ 0000:0000 ¨ì 0000:0003¡A¨ä¤º®e¬° 0019:9257¡A
¡@¡@INT 1 ¥Ñ 0000:0004 ¨ì 0000:0007¡A¨ä¤º®e¬° 0070:06F4¡A
¡@¡@INT 2 ¥Ñ 0000:0008 ¨ì 0000:000C¡A¨ä¤º®e¬° 0DE7:0016¡A
¡@¡@¡K¡K¡A
¦b¤¤Â_¦V¶qªí¤¤¡A¦]¬°¨C¤@­Ó¤¤Â_³£»Ý­n¥|­Ó¦ì¤¸²ÕªºªÅ¶¡¡A¦]¦¹§Ú­Ì«Ü®e©ö§ä¨ì²Ä n ¸¹¤¤Â_ ( INT n ) ¬O¦b°O¾ÐÅ餤ªº¨º¤@­Ó¦ì§}¡G

INT n ¦b¦ì§} 0000:(4n) ³B

INT »P IRET «ü¥Oªº¹Lµ{

¨C¤@¤¤Â_ªºÂù¦r²Õ¤¤¡A¸û°ª¦ì§}ªº¦r²Õ¬Oªí¥Ü¸Ó¤¤Â_ªº°Ï¬q¦ì§}¡A§C¦ì§}ªí¥Ü°¾²¾¦ì§}¡A³o¨Ç¦ì§}¬Oµo¥Í¤¤Â_«á¡ACPU ·|¸g¥Ñ¤@­Óªøµ{©I¥s¦Ó¨ì¸Ó¦ì§}Ä~Äò°õ¦æ¡C°²¦p­n¦AÁ¿±o§ó¸Ô²Ó¨Ç¡A·íµo¥Í²Ä n ¸¹¤¤Â_®É¡AINT n «ü¥O·|¨Ï CPU ¨Ì§Ç°õ¦æ¤U­±°Ê§@¡G

  1. §âºX¼Ð¼È¦s¾¹±À¤J°ïÅ|
  2. ¸T¤î¨ä¥L¤¤Â_µo¥Í
  3. ²M°£³´¨ÀºX¼Ð
  4. §â CS ¼È¦s¾¹±À¤J°ïÅ|
  5. §â INT n ªº¤U¤@«ü¥O¦ì§}±À¤J°ïÅ|
  6. ¥Ñ 0000:(4n) ¦ì§}¨ú¥X¤¤Â_ªA°Èµ{¦¡©Ò¦b¦ì§}¡A¨Ã°õ¦æªøµ{¸õÅD«ü¥O¡A¦Ü¸Ó³BÄ~Äò°õ¦æ

¥Ñ¤W­±¬Ý¨Ó¡A¨ä¹ê INT «ü¥O¸ò CALL «ü¥O«Ü¬Û¹³¡A©Ò¤£¦Pªº¬O INT «ü¥O·|§âºX¼Ð¼È¦s¾¹±À¤J°ïÅ|¡A¨Ã¥B·|²M°£¤¤Â_ºX¼Ð¤Î³´¨ÀºX¼Ð ( ¸T¤î¨ä¥L¤¤Â_µo¥Í¤]¸T¤î³æ¨B°lÂÜ )¡A¦ý¬O CALL ¤£·|§âºX¼Ð¼È¦s¾¹±À¤J°ïÅ|¡A¤]¤£·|²M°£¤¤Â_ºX¼Ð¤Î³´¨ÀºX¼Ð¡C¦b¤¤Â_ªA°Èµ{¦¡¤§¤¤¡A¸Ó°µ¨º¨Ç¥²­nªº¨Æ©O¡H­º¥ý¬O­n«ì´_¤¹³\¨ä¥L¤¤Â_µo¥Í¡A­ì¦]¬O¨t²Î­p®É¾¹·|©I¥s INT 8H¡A¦]¦¹¤£»°ºò«ì´_¥i¥H¶}±Ò¤¤Â_·|³y¦¨­p®É¤£·Ç½T¡A¬Æ¦Ü¤Þ°_·í¾÷¡C²Ä¤G¬O¥Î PUSHA «ü¥O¦b°ïÅ|¤¤«O¦s¦U¼È¦s¾¹¤§¼Æ­È¡A¥H«K¤¤Â_ªA°Èµ{¦¡µ²§ôªð¦^­ìµ{¦¡®É¡A¤´«O¦³­ì¨Óªºª¬ºA¡A·íµM¤F¡A¦pªG¬Y¨Ç¼È¦s¾¹¬O¥²¶··í§@ªð¦^­È¨Ñ­ìµ{¦¡°Ñ¦Òªº¼È¦s¾¹¤S¥t·í§O½×¤F¡C²Ä¤T¬O§Y±Nªð¦^­ìµ{¦¡®É¡A¥Î POPA «ü¥O¦Û°ïÅ|¨ú¦^¦U¼È¦s¾¹¤§­È¡A¦P®É­nª`·N¡A¤¤Â_ªA°Èµ{¦¡µLªk§âºX¼Ð·í¦¨ªð¦^­È¶Ç¦^µ¹­ì¨Óªºµ{¦¡¡C

¦Ó¦Û¤¤Â_ªð¦^­ìµ{¦¡®É¡A´N¥²¶·¦Û°ïÅ|¨ú¦^­ìµ{¦¡ªº¤U¤@«ü¥O¦ì§}¡A¦P®ÉÁÙ­n¦b°ïÅ|¨ú¦^ºX¼Ð¼È¦s¾¹¡A¦]¦¹¤¤Â_µ²§ô®É¤£¥Î RET «ü¥O¦Ó§ï¥Î IRET «ü¥O¡CIRET «ü¥O¨Ï CPU °õ¦æ¤U­±¨â¥ó¨Æ¡G

  1. ¥Ñ°ïÅ|¤¤¼u¥X¤@Âù¦r²Õ¡A¨Ã§â±±¨îÅv¥æ¨ì¸ÓÂù¦r²Õ©Ò«ü¦ì§}
  2. ¥Ñ°ïÅ|¼u¥XºX¼Ð¼È¦s¾¹

©³¤U¤p¤ì°¸Á|¤@­Ó¥i¯à¬O¨t²Î¤¤³Ì²³æªº¤¤Â_¡AINT 1CH¡A¨Ó»¡©ú INT¡BIRET ªº¹Lµ{¡CINT 1CH ¨ä¹ê¬O¤@­ÓªÅªº¤¤Â_¡A¥¦´N¥u¦³¤@­Ó«ü¥O IRET¡A¥ç§Yµo¥Í¦¹¤¤Â_«á¡A¥ß§Yªð¦^¡CINT 1CH ¨ä¹ê¬O³Q INT 8H ©Ò©I¥sªº¤@­Ó¤¤Â_¡A¥¦¬O¹w¯dµ¹±`¾nµ{¦¡¨Ï¥Î¡CINT 1CH ªºµ{¦¡¦ì§}¥i¦b¤¤Â_¦V¶qªí 0000:0070 ³B§ä¨ì ( 1CH*4=70H )¡A§Ú­Ì¥Î SYMDEB Æ[¹î¨Ã°µ¹êÅç¡A©³¤U¶À¦âªº¤å¦r¬O¤p¤ì°¸¿é¤Jªº«ü¥O¡A¥Õ¦âªºÂù¦r²Õ´N¬O INT 1CH µ{¦¡ªº¦ì§}¡G

-d 0:70 L10 [Enter]  ¡÷Àˬd INT 1CH ¦ì§}
0000:0070  53 FF 00 F0 A4 F0 00 F0-22 05 00 00 E6 2F 00 C0  S..p$p.p"...f/.@
-u f000:ff53 [Enter]¡@¡@¡@¡@¡@¡@¡@¡@¡@¡@¡@¡÷¬Ý¬Ý INT 1CH ªºµ{¦¡½X
F000:FF53 CF             IRET¡@¡@¡@¡@¡@¡÷INT 1CH ªºµ{¦¡½X´N¥u¦³¤@±ø¡AIRET
F000:FF54 E933EA         JMP    E98A
F000:FF57 0000           ADD    [BX+SI],AL
F000:FF59 284329         SUB    [BP+DI+29],AL
F000:FF5C 3230           XOR    DH,[BX+SI]
F000:FF5E 3030           XOR    [BX+SI],DH
F000:FF60 41             INC    CX
F000:FF61 4D             DEC    BP
-a [Enter]¡@¡@¡@¡@¡@¡÷½s¼g¤@µ{¦¡¡A¶È°õ¦æ INT 1CH
1F4C:0100 int 1c [Enter]
1F4C:0102 [Enter]
-rip 100 [Enter]¡@¡÷³]©w IP ¼È¦s¾¹¤§­È
-r [Enter]¡@¡@¡@¡@¡@¡÷¥ýÆ[¹î¦U¼È¦s¾¹¤§­È
AX=0000  BX=0000  CX=0000  DX=0000  SP=DFA3  BP=0000  SI=0000  DI=0000
DS=1F4C  ES=1F4C  SS=1F4C  CS=1F4C  IP=0100   NV UP EI PL NZ NA PO NC
1F4C:0100 CD1C           INT    1C
-t [Enter]¡@¡@¡@¡@¡@¡÷°lÂܸӵ{¦¡¡A¤w¶i¤J INT 1CH ùØ­±¤F
AX=0000  BX=0000  CX=0000  DX=0000  SP=DF9D  BP=0000  SI=0000  DI=0000
DS=1F4C  ES=1F4C  SS=1F4C  CS=F000  IP=FF53   NV UP DI PL NZ NA PO NC
F000:FF53 CF             IRET
-d ss:df9d L20 [Enter]¡@¡÷Æ[¹î°ïÅ|
1F4C:DF90  00 00 00 00 00 00 00 00-00 00 00 00 00 02 01 4C  ...............L
1F4C:DFA0  1F 02 F2 00 00 00 00 00-00 00 00 00 00 00 00 00  ..r.............
-t [Enter]
AX=0000  BX=0000  CX=0000  DX=0000  SP=DFA3  BP=0000  SI=0000  DI=0000
DS=1F4C  ES=1F4C  SS=1F4C  CS=1F4C  IP=0100   NV UP EI PL NZ NA PO NC
1F4C:0102 8ED8           MOV    DS,AX
-

¦b¤W­±ªº¹êÅçùØ¡A·í°õ¦æ INT 1C «á¡AºX¼Ð¼È¦s¾¹¡BINT 1C ¤U¤@¦ì§} ( ªð¦^¦ì§}¤§ CS:IP ) ³£·|³Q±À¤J°ïÅ|¡A³o¤@ÂI¥i¥H¸g¥ÑÆ[¹î°ïÅ|ùتº±¡§Î±oª¾ ( ÂŦâ¬OºX¼Ð¼È¦s¾¹¡A¾¥ºñ¦â³¡¥÷¬Oªð¦^¦ì§}¡AºX¼Ð¼È¦s¾¹ªº­È¬O F202H¡A½Ð°Ñ¦Ò µù¤@ )¡A°£¦¹¤§¥~¡AINT «ü¥O¤]·|§âºX¼Ð¼È¦s¾¹ªº¤¤Â_ºX¼Ð³]¬° DI ( ¬õ¦â³¡¥÷ )¡C¤@¶i¤J INT 1C «á¡Aµ{¦¡¦ì§}Åܦ¨¦s©ó¤¤Â_¦V¶qªíªº¦ì§}¤F ( ¥Õ¦â³¡¥÷ )¡AINT 1C ¤°»ò¨Æ¤]¨S°µ´Nµ²§ô¤¤Â_¡A©Ò¥H¥u¦³¤@±ø«ü¥O IRET¡A¦A«×°lÂÜ¡Aµo²{ªGµM¤S¦^¨ì 1F4C:0102 ³B¡A¦P®É«ì´_ºX¼Ð¼È¦s¾¹¦¨¬°¶i¤J¤¤Â_«eªºª¬ªp¡C

­×§ï¤¤Â_¦V¶qªí

¬°¤°»ò­n­×§ï¤¤Â_¦V¶qªí©O¡H¦]¬° IBM ¤Î·L³n¨Ã¨S¦³¨Ï¥Î©Ò¦³ªº¤¤Â_¡A´«¥y¸Ü»¡¡A¤´¦³³\¦h¤¤Â_¬O¥¼¨Ï¥Îªº¡A¥i¥H¨Ñ¨Ï¥ÎªÌ©Î¨ä¥L¼t°Ó¨Ï¥Î¡A¨Ò¦p INT 33H ²{¦b³Q¤½»{¬O¨Ï¥Î·Æ¹«ªºªA°Èµ{¦¡¡C°£¦¹¤§¥~¡AÁÙ¦³¨â­Ó²z¥Ñ¡A¤@­Ó¬O IBM ©Î·L³n´£¨Ñªº¤¤Â_¤£¦n¥Î¡A·Q­×§ï¥¦¡F©Î¬O¬°¤F¼¶¼g±`¾nµ{¦¡ ( TSR¡Aterminate and stay resident )¡C·Q­×§ï¤¤Â_¦V¶qªí¡A¦³¨âºØ¤èªk¡A²Ä¤@ºØ¬O¨Ï¥Î DOS ´£¨Ñªº¤¤Â_ªA°Èµ{¦¡¡F²Ä¤GºØ¤èªk¬Oª½±µ­×§ï 0000:0000 ¨ì 0000:03FF ³Bªº°O¾ÐÅé¡C

¨ú±o¤¤Â_¦ì§} ( AH=35H/INT 21H ) »P³]©w¤¤Â_¦ì§} ( AH=25H/INT 21H )

¥ý»¡²Ä¤@ºØ¤èªk¡AMS¡ÐDOS ªº¤¤Â_ªA°Èµ{¦¡ INT 21H ´£¨Ñ¤F¨â­Ó¥\¯à¡A¤@­Ó¥Î¨Ó¨ú±o¬Y¤¤Â_¦ì§} ( ¥Î AH=35H/INT 21H )¡A¤@­Ó¥Î¨Ó³]©w¬Y¤¤Â_¦ì§} ( ¥Î AH=25H/INT 21H )¡C¤p¤ì°¸¾ã²z¦p¤Uªí¡G

¨ú±o¤¤Â_¦ì§}³]©w¤¤Â_¦ì§}
AL=±ý¨ú±o¦ì§}ªº¤¤Â_½s¸¹
AH=35H
°õ¦æ INT 21H
ªð¦^«á¡G
ES:BX=¤¤Â_¦ì§}
AL=±ý³]©w¦ì§}ªº¤¤Â_½s¸¹
AH=25H
DS:DX=·sªº¤¤Â_µ{¦¡¦ì§}
°õ¦æ INT 21H
ªð¦^«á¡GµL

ª½±µ­×§ï¤¤Â_¦V¶qªí

«e­±¤w¸g´£¹L¡A¨C¤@­Ó¤¤Â_µ{¦¡ªº¦ì§}³£°O¿ý¦b°O¾ÐÅé 0000:03FF ¦ì§}³B¡A¦Ó¨C¤@­Ó¤¤Â_µ{¦¡ªº¦ì§}³£¦û¾Ú¤@­ÓÂù¦r²Õ¡A¦]¦¹«Ü®e©ö´N¯à­pºâ¥X¸Ó¤¤Â_¦ì§}¡A¶i¦Ó­×§ï¥¦¡A¤èªkÁöµM²³æ¡A¦ý¬O«o±o¤p¤ß¡C°²¦p±z­n­×§ï INT 9H ¤¤Â_¦ì§}¡A¥i¤£¯à³o¼Ë°µ¡G

        mov     es,0                                ;¹w¥ý¨Ï¥Î .386 ¤~¥iª½±µ§ó§ï ES
        mov     word ptr es:[24h],offset new_int9h  ;³]©w·sªº INT 9H °¾²¾¦ì§}
        mov     word ptr es:[26h],seg new_int9h     ;³]©w·sªº INT 9H °Ï¬q¦ì§}

­ì¦]¬O¡A¨Æ¹ê¤W¡A¦³¨Ç¤¤Â_¬OµwÅé¦Û¦æ²£¥Í¡A¦pªG·í¤W­±­×§ï¤¤Â_¦ì§}ªºµ{¦¡¤w°õ¦æ§¹²Ä¤G­Ó mov «ü¥O¡A¦ý²Ä¤T­Ó mov «ü¥O©|¥¼°õ¦æ®É¡A¨Ï¥ÎªÌ­è¦n«ö¤U¬Y¤@Áä¡A³o®É«K·|µo¥Í INT 9H¡A¦ý¬O³o®Éªº¤¤Â_¦V¶qªíªº INT 9H ªº¦ì§}¨ä¹ê¬O¿ùªº¡A¨t²Î«K·|·í¾÷¡C¦]¦¹§ï¦¨¤U­±ªº¼Ë¤l¡G

        mov     es,0
        cli                                         ;¸T¤î¤¤Â_
        mov     word ptr es:[24h],offset new_int9h
        mov     word ptr es:[26h],seg new_int9h
        sti                                         ;¥i¥Hµo¥Í¤¤Â_

¤W­±ªº°µªk¥i¥H¾A¥Î¦b¤j³¡¤Àªº±¡§Î¤U¡A¦ý¬O CLI «ü¥OµLªk¸T¤î NMI ªºµo¥Í¡A¦]¦¹¥i¯àÁÙ¬O·|²£¥Í·í¾÷ªº¦MÀI¡A¥¿½Tªºµ{¦¡À³¸Ó¬O¹³¤U­±ªºµ{¦¡¡G

new_key dw      offset new_int9h,seg new_int9h
        ¡K¡K
        mov     es,0
        mov     di,24h
        mov     si,offset new_key
        cld
        cli
        movsd
        sti

¤W­±ªºµ{¦¡§â·sªº INT 9H ªº°¾²¾¦ì§}©M°Ï¬q¦ì§}³]©w¦¨¤@­Ó¨â¦r²Õªº°}¦C¡AµM«á¥H MOVSD «ü¥O°µ·h²¾¡AMOVSD ¶È¬°¤@­Ó«ü¥O¡A§Y¨Ï¬O NMI ¤]µLªk¦b«ü¥O¥¿°õ¦æ©|¥¼§¹¦¨®Éµo¥Í¡A³o¼Ë´N¥iÁקK¤¤Â_ªº¤zÂZ¤F¡C¤£¹L¬°¤F¬Ù«o­pºâ¤¤Â_ªA°Èµ{¦¡¦b¤¤Â_¦V¶qªíªº¦ì§}¡A¤j³¡¤Àªº±¡§ÎÁÙ¬O¥Î AH=25H/INT 21H ¨Ó­×§ï¤¤Â_¦V¶qªí¡C


§ïµ½ INT 0

«e¤@³¹´¿´£¨ì·í CPU °µ°£ªk¹Bºâ¡A¦pªGµo¥Í°£¥H¹s©Î¬O°Ó¼Æ¤Ó¤j¡A·|²£¥ÍµL·N¸q©Î·¸¦ì¿ù»~¡ACPU ·|¦Û°Ê¤Þµo INT 0¡A¦b¿Ã¹õ¤W¦L¥X¡yDivide overflow¡z¡AµM«á²×¤îµ{¦¡¡C³oºØ³B²z¿ù»~ªº¤èªk¨Ã¤£§¹µ½¡A§A·Q°²¨Ï¯µ®Ñ¤p©j¤w¿é¤J³\¦h¸ê®Æ¡A¨Ã°µ¹Bºâ¡A¸U¤@¦³¤@µ§¸ê®Æµo¥Í°£¥H¹sªº¿ù»~¡A¦Ó¦o¨S¦³¨Æ¥ýÀx¦s¡Aµ²ªGµ{¦¡´Nµ²§ô¤F¡A¦o©Ò¿é¤Jªº¸ê®Æ¤£´Nªw´ö¤F¶Ü¡H¦pªG¦³³o¼Ë¤£³B²z INT 0 ªº°Ó·~³nÅé¡A·Q¥²¨S¤H·|¥h¶R¡C¥»³¹«e­±¤w¸g¤¶²Ð¤F¤@¨Ç¤¤Â_ªº·§©À¡A¦pªG¹ï INT 0 ¤F¸Ñ ( °Ñ¦Òµù¤G )¡A´N¥i¥H°µÂ²³æªº­×§ï¡C

©³¤Uªºµ{¦¡¡ANEW_INT0.ASM¡A¬O¹ï INT 0 °µÂ²³æªº­×§ï¡C³o­Óµ{¦¡°µ¤T­Ó 8 ¦ì¤¸ªº°£ªk¹Bºâ¡G4096¡Ò0¡B4096¡Ò10¡B4096¡Ò32¡A«Ü©úÅ㪺²Ä¤@­Ó¬O°£¥H¹s¡Aµ²ªG¬°µL·N¸q¡A²Ä¤G­Ó°£ªkªº°Ó¼Æ¶W¹L 255¡AÅãµM·|³y¦¨·¸¦ì¡C°²¦p INT 0 ¤£´¿­×§ï¡A¨º°µ§¹²Ä¤@­Ó°£ªk«á¡ANEW_INT0 «K·|²×¤î¨Ãªð¦^ DOS¡C¦ý¬O¦b NEW_INT0.ASM ¤¤¡A¤p¤ì°¸­×§ï¤F INT 0¡A¦]¦¹°£¥H¹s¶È·|¦L¥X¡yDivide by Zero!¡z¦r¦ê¡Aµ{¦¡ÁÙ¯àÄ~Äò°õ¦æ¤U¥h¡A¦Ó¥B·¸¦ì¤]¤£¬O°ÝÃD¡ANEW_INT0.ASM ¤´¯àºâ¥X¥¿½Tªº°Ó¼Æ©M¾l¼Æ¡A¨Ã¥B¦L¥X¨Ó¡C½Ð¬Ý°õ¦æªºµ²ªG¡G

E:\HomePage\SOURCE>new_int0 [Enter]
4096/0=Divide by Zero!
4096/10=409...6
4096/32=128

E:\HomePage\SOURCE>

§¹¾ãªº NEW_INT0.ASM ­ì©l½X¦p¤U¡A§â¥¦¦s¦¨ NEW_INT0.ASM¡A¸g²ÕĶ¡B³sµ²¨ÃÂà´«¦¨ NEW_INT0.COM ¥i°õ¦æÀÉ¡C

;·sªº INT 0¡Ð¦¹µ{¦¡¥i¥HÀˬd°£¥H¹sªº¿ù»~¡A¦Ó¤£·|²×¤îµ{¦¡
        page    ,132
;***********************************************************
        .386
code    segment use16
        assume  cs:code,ds:code
        org     100h
;-----------------------------------------------------------
start:  jmp     begin
old_int0        dw      ?,?
message         db      'Divide by Zero!'
n               dw      1000h           ;1000h=4096d
d1              db      0
d2              db      10
d3              db      20h
buffer          db      30h dup (' ')
message_len     equ     offset n-offset message
;-----------------------------------------------------------
new_int0        proc    near
        sti
        mov     bx,sp
        add     word ptr ss:[bx],div_len
        mov     bx,0ffffh
        iret
new_int0        endp
;-----------------------------------------------------------
hex2dec proc    near
;§âEDX¤º©Ò¦sªº¤Q¤»¶i¦ì¦³¸¹¼ÆÅܦ¨¤Q¶i¦ì¦³¸¹¼Æ¡A¦s©óDI©Ò«üªº¦ì§}
        jmp     short h2d0
tmp     db      10 dup (' ')
h2d0:   test    edx,80000000h   ;Àˬd¬O§_¬°­t¼Æ
        jz      h2d1
        mov     al,'-'          ;­Y¬°­t¼Æ¡A«h¨ú¨ä2ªº¸É¼Æ¡A¨Ã
        neg     edx             ;©óDI©Ò«ü¦ì§}¦s¤J­t¸¹
        stosb
h2d1:   push    di
        mov     ebx,10          ;¨ÏEDX¨C¦¸°£¥H10¡A©Ò±oªº¾l¼Æ
        mov     eax,edx         ;¤À§O¬°¤Q¶i¦ìªº­Ó¦ì¼Æ¡B¤Q¦ì¼Æ¡B
        mov     di,offset tmp+9 ;¦Ê¦ì¼Æ¡K¡K¡A§â³o¨Ç¾l¼Æ¼È®É¦s©ó
        mov     cx,bx           ;tmp¦r¦ê¤¤(¥Ñ°ª¦ì§}¶}©l¦s)
h2d2:   sub     edx,edx
        div     ebx
        add     dl,'0'
        mov     [di],dl
        or      eax,eax
        jz      h2d3
        dec     di
        loop    h2d2
h2d3:   mov     si,di           ;§âtmp¦r¦ê¤¤ªº¨C¤@¦ì¼Æ¡A¦s¤J
        pop     di              ;DI©Ò«ü¦ì§}
        sub     bx,cx
        mov     cx,bx
        inc     cx
        rep     movsb
        ret
hex2dec endp
;-----------------------------------------------------------
division        proc    near
        sub     bh,bh           ;¨ÏBX°ª¦ì¤¸²Õ¬°¹s¡A¦]¬°°£¼Æ¶È¥Î BL
        push    ax              ;©I¥shex2dec®É¡AAX¡BBX§¡·|³Q¯}Ãa¡A
        push    bx              ;¬G¥ýÀx¦s©ó°ïÅ|ùØ
        sub     edx,edx
        mov     dx,ax
        call    hex2dec         ;­pºâ³Q°£¼Æ¤§¤Q¶i¦ìASCII¦r¤¸
        mov     al,'/'
        stosb
        pop     dx
        push    dx
        call    hex2dec         ;­pºâ°£¼Æ¤§¤Q¶i¦ìASCII¦r¤¸
        mov     al,'='
        stosb
        pop     bx
        pop     ax
        or      bl,bl
        jz      divi2           ;Àˬd¬O§_°£¥H¹s¡A­Y¬O«h¸õ¦Üdivsi2
        push    bx
addr_d: div     bl
addr_n: cmp     bx,0ffffh       ;Àˬd¬O§_°Ó¼Æ¤Ó¤j¡AµLªk©ñ¨ìAL¼È¦s¾¹
        pop     bx              ;¡A­Y¤Ó¤j«h°£ªk·¸¦ì¡A¸õÅD¦Üdivi3³B²z
        je      divi3
div_len equ     offset addr_n-offset addr_d
        mov     dl,al
divi0:  push    ax
        call    hex2dec         ;­pºâ°Ó¼Æªº¤Q¶i¦ìASCII¦r¤¸
        pop     ax
        or      ah,ah
        jz      divi1
        mov     dl,ah
        mov     ax,2e2eh
        stosw
        stosb
        call    hex2dec         ;­pºâ¾l¼Æªº¤Q¶i¦ìASCII¦r¤¸
divi1:  mov     ax,0a0dh
        stosw
        mov     al,'$'
        stosb
        mov     dx,offset buffer
        mov     ah,9
        int     21h
        ret

divi2:  mov     si,offset message
        mov     cx,message_len  ;°£¥H¹s¡A«h¦L¥X¡yDivide by Zero!¡z
        rep     movsb
        jmp     divi1

divi3:  sub     cx,cx           ;°£ªk·¸¦ì¡A«h§ï¥Î³sÄò´îªk¥N´À°£ªk
        mov     bh,0            ;BX=°£¼Æ¡AAX=³Q°£¼Æ
divi4:  cmp     ax,bx           ;­pºâ§¹«á¡ACX=°Ó¼Æ¡AAL=¾l¼Æ
        jbe     divi5           ;­Y³sÄò´îªk´î¦ÜAX¤ñ°£¼Æ¤p¡Aªí¥Ü°£ªk¤w§¹¦¨
        sub     ax,bx           ;¡A°£ªk§¹¦¨«á¸õÅD¦Üdivi5¡A§_«hÄ~Äò´î¥h°£¼Æ
        inc     cx
        jmp     divi4
divi5:  mov     dx,cx
        mov     ah,al           ;¦]8¦ì¤¸ªºDIV«ü¥O¡A©Ò±o¾l¼Æ¦bAH¡A¬G§â
        jmp     divi0           ;AH³]¬°AL¡A¦A¸õÅD¦Üdivi0
division        endp
;-----------------------------------------------------------
begin:  push    es
        mov     ax,3500h        ;Àx¦sªº INT 0 ¦ì§}
        int     21h
        mov     old_int0,bx
        mov     [old_int0+2],es
        mov     dx,offset new_int0
        mov     ax,2500h
        int     21h
        pop     es

        mov     ax,n
        mov     bl,d1
        mov     di,offset buffer
        call    division        ;­pºâ 100h/0

        mov     ax,n
        mov     bl,d2
        mov     di,offset buffer
        call    division        ;­pºâ 1000h/10=409d...6

        mov     ax,n
        mov     bl,d3
        mov     di,offset buffer
        call    division        ;­pºâ 1000h/20h=128d

        push    ds
        mov     dx,word ptr old_int0
        mov     ds,word ptr [old_int0+2]
        mov     ax,2500h        ;«ì´_­ì¨Óªº INT 0
        int     21h
        pop     ds

        mov     ax,4c00h        ;µ²§ôµ{¦¡
        int     21h
;-----------------------------------------------------------
code    ends
;***********************************************************
        end     start

NEW_INT0.ASM ³Ì¥D­nªº¦a¤è¦b©ó new_int0 °Æµ{¦¡¡AÁöµM³o­Ó°Æµ{¦¡¶È¶È¤­¦æ¡A¥¦«o§ïÅܤF°£ªk¿ù»~´N²×¤îµ{¦¡ªº¤£§¹¬ü¤§³B¡C³o¤­¦æ«ü¥O°µ¤T¥ó¨Æ¡A²Ä¤@¬O¥i­«·s¤¹³\¤¤Â_µo¥Í¡C²Ä¤G¥ó¨Æ¬O§ïÅܦb°ïÅ|ùØ¡Aªð¦^­ìµ{¦¡ªº¦ì§}¡C«e­±´£¹L¡A·í°õ¦æ INT «ü¥O®É¡A·|¨Ì§Ç§âºX¼Ð¼È¦s¾¹¡Bµo¥Í¤¤Â_®É¤U¤@­Ó«ü¥Oªº¦ì§}¦s¤J°ïÅ|¡A¥H«OÃÒ±q¤¤Â_µ{¦¡ªð¦^®É¡A¯à§ä¨ì­ìµ{¦¡µo¥Í¤¤Â_®Éªº¦a¤èÄ~Äò°õ¦æ¡C¦ý¬O¡A¹ï©ó INT 0 ³o­Ó¤¤Â_«Ü©_©Ç¡A³o­Ó¤¤Â_¬Oµo¥Í¦b°£¥H¹s©Î°£ªk·¸¦ì®É¡A¦pªG DIV «ü¥O°£¥H¹s©Î°Ó¼Æ¤Ó¤j¦Ó·¸¦ì¡ACPU ¨Ã¤£¬O§â DIV ¤U¤@«ü¥Oªº¦ì§}±À¤J°ïÅ|¡A¤Ï¦Ó¬O§â DIV «ü¥O©Ò¦b¦ì§}±À¤J°ïÅ|¡C¬°¤°»ò·|³o¼Ë¡H³o¤@ÂI¤p¤ì°¸¤]¤£²M·¡¡A¦p¦³«e½ú°ª¤H¡A¯à´£¨Ñ·N¨£«h·P¿E¤£ºÉ¡C

DIV «ü¥Oªº¦ì§}¬O¥Ñ CS:IP ©Ò²Õ¦¨¡ACPU ¥ý§âºX¼Ð¼È¦s¾¹¤Î CS ¼È¦s¾¹¨Ì§Ç±À¤J°ïÅ|¡A¦A§â IP ±À¤J°ïÅ|¡CSP ¼È¦s¾¹¥ý¬O«ü¦V°ïÅ|³»ºÝ¡A¨C±À¤J¤@µ§¦r²Õªø«×ªº¸ê®Æ¨ì°ïÅ|¡ASP ¼È¦s¾¹«K´î¤Ö 2¡A¦]¦¹§Ú­Ì­n­×§ïªº´N¬O SP ©Ò«üªº¦ì§}¡A¦Ü©ó­n§ï¦¨¦h¤Ö©O¡H³o©M DIV ªº°£¼Æ¦³Ãö¡A°£¼Æ¥i¥H¬O¼È¦s¾¹©Î¬O°O¾ÐÅéÅܼơA¦ý¬O¥¦­Ì©Ò²Õ¦¨ªº¾÷±ñ½Xªø«×¤£¦P¡A¦]¦¹¤p¤ì°¸¥Î div_len ¨Óªí¥Ü DIV «ü¥O©Ò¦û¾÷±ñ½Xªø«×¡A¥u­n§â SS:SP ©Ò«ü¦ì§}¤º¤§¼Æ­È¥[¤W div_len ¤§­È¡A´N¬O DIV «ü¥O¤U¤@¦ì§}¡C¦Ü©ó div_len ¥i¥H¥Ñ DIV ¤U¤@«ü¥O¦ì§}´î¥h DIV «ü¥O¦ì§}¦Ó±o¨ì¡A¨£ division °Æµ{¦¡¤¤ªºµ{¦¡¤ù¬q¡G

        or      bl,bl
        jz      divi2           ;Àˬd¬O§_°£¥H¹s¡A­Y¬O«h¸õ¦Üdivsi2
        push    bx
addr_d: div     bl
addr_n: cmp     bx,0ffffh       ;Àˬd¬O§_°Ó¼Æ¤Ó¤j¡AµLªk©ñ¨ìAL¼È¦s¾¹
        pop     bx              ;¡A­Y¤Ó¤j«h°£ªk·¸¦ì¡A¸õÅD¦Üdivi3³B²z
        je      divi3
div_len equ     offset addr_n-offset addr_d

¦b·sªº INT 0H ¤¤Â_¤¤©Ò§@ªº²Ä¤T¥ó¨Æ±¡¬O¦pªGµo¥Í·¸¦ì®É¡A§â BX ³]¬° 0FFFFH °µ¬°ªð¦^­È¡A­ìµ{¦¡¥u­nÀˬd BX ¬O§_¬° 0FFFFH ´Nª¾¹D¬O§_µo¥Í·¸¦ì¡C·íµM¤F¡A¦pªG·|¶i¤J INT 0 ªºµ{¦¡¡AÅãµM´N·|²£¥Í·¸¦ì¡A©Ò¥H¦b INT 0 µ{¦¡ùØ¡A¤£»Ý­nÀˬd¡C¦Ü©ó°£¥H¹sªº±¡§Î«h¦b addr_d: ¼Ð°O¤W¤T¦æªº«ü¥O¡A¡yOR BL,BL¡z¡A¥hÀˬd°£¼Æ¬O§_¬°¹s¡C¾ã²z¤@¤U§a¡INEW_INT0.ASM ¹ï©ó°£¥H¹sªº¿ù»~¡A¬O¨Æ¥ýÀˬd°£¼Æ¬O§_¬°¹s¡F¦Ó¹ï©ó°£ªk·¸¦ìªº±¡§Î¡A¬O­×§ï INT 0 ¤¤Â_¡A¨Ï¥¦¯à¹Bºâ¡CŪªÌÀ³¸Ó­nª¾¹D¡A¦b¼Æ¾Ç¬O¤W¨S¦³¤°»ò·¸¦ìªº¨Æµo¥Í¡A¦]¦¹¤°»ò°£ªk·¸¦ì¨ä¹ê¬O¥i¥Hºâ¥Xµª®×¨Óªº¡C


µù¤@¡G¦b¶i¤J INT 1CH ¤§«e¡A¥Ñ SYMDEB Æ[¹î¦UºX¼Ð¬O NV UP EI PL NZ NA PO NC¡A·¸¦ìºX¼Ð¬° NV ¬G NF=0¡B¤è¦VºX¼Ð¬° UP ¬G DF=0¡B¤¤Â_ºX¼Ð¬° EI ¬G IF=1¡B²Å¸¹ºX¼Ð¬° PL ¬G SF=0¡B¹sºX¼Ð¬° NZ ¬G ZF=0¡B»²§U¶i¦ìºX¼Ð¬° NA ¬G AF=0¡B¦P¦ìºX¼Ð¬° PO ¬G PF=0¡B¶i¦ìºX¼Ð¬° NC ¬G CF=0¡A¹ï·ÓºX¼Ð¼È¦s¾¹ªº¦UÄæ¦ì¡A½Ð¬Ý¤U¹Ï¡G

¦]¦¹±o¨ì ____ 0010 00_0 _0_0¡C

µù¤G¡G¨Æ¹ê¤W¡AµwÅ餤Â_¥i¤À¬°¨âºØ¡A¤@ºØ¬O¤º³¡¤¤Â_¡A¥t¤@ºØ¬O¥~³¡¤¤Â_¡C¤º³¡¤¤Â_¬O«ü¥Ñ CPU ¦Û¦æ²£¥Íªº¤¤Â_¡A¨Ò¦p°£¥H¹s©Î°£ªk·¸¦ì¡B°£¿ùµ{¦¡¤¤ªº³æ¨B°lÂܩΰõ¦æ¨ì¤¤Â_ÂI¡C¥~³¡¤¤Â_«h¬O¨ä¥Lªº©PÃä³]³Æ²£¥Íªº°T¸¹¡A³qª¾ CPU µo¥Íªº¤¤Â_¡A¥~³¡¤¤Â_¤S¥i¦A²Ó¤À¬°¥i¾B¸n¤¤Â_ ( maskable interrupt ) ©M¤£¥i¾B¸n¤¤Â_ ( non-maskable interrupt¡ANMI ) ¨âºØ¡C¥i¾B¸n¤¤Â_¬O«ü¥i¥H³Q CPU «ü¥O¸T¤î©Î¤¹³\ªº¤¤Â_¡A·íµo¥Í¥i¾B¸n¤¤Â_®É¡ACPU ·|¥ýÀˬdºX¼Ð¼È¦s¾¹¤¤ªº¤¤Â_ºX¼Ð ( IF )¡A·í¤¤Â_ºX¼Ð¬° 1 ®É¡ACPU ¥i±µ¨ü¥~¨Óªº¤¤Â_°T¸¹¡F¤Ï¤§¡A­Y¤¤Â_ºX¼Ð¬° 0 ®É«h¤£±µ¨ü¤¤Â_­n¨D¡C8086 «ü¥O¶°ùØ­±¦³­Ó«ü¥O STI ¥i¥H³]©w¤¤Â_ºX¼ÐÅܬ° 1¡A¤¹³\¥i¾B¸n¤¤Â_°õ¦æ¤¤Â_ªA°Èµ{¦¡¡F¥t¤@­Ó«ü¥O¡ACLI ¥i¥H²M°£¤¤Â_ºX¼ÐÅܬ° 0¡A¤£¤¹³\¥i¾B¸n¤¤Â_°õ¦æ¤¤Â_ªA°Èµ{¦¡¡C

¤£¥i¾B¸n¤¤Â_ ( NMI ) «h¬OµLªk³Q CPU «ü¥O¸T¤î©Î¤¹³\ªº¤¤Â_¡A¥ç§Y¥u­nµo¥Í¤F NMI¡A¤£ºÞ¤¤Â_ºX¼Ð¬O§_³]©w©Î²M°£¡A¤¤Â_³£·|³Q CPU °õ¦æ¡C¥u¦³ÄY­«ªº¿ù»~µo¥Í®É¤~·|²£¥Í NMI¡A¨Ò¦p 8087 ¿ù»~¡B°O¾ÐÅ骺¦P¦ì¤¸¿ù»~ ( parity error )¡BI/O ³q¹D¿ù»~¡A³o¨Ç¿ù»~µo¥Í®É¡A­Y¤£³B²z ( ¨ä¹ê¤j³¡¤Àªº³B²z¤è¦¡¤]¥u¯à°e­×¤F )¡A©Ò±oªº¸ê®Æ¤]¬O¿ù»~ªº¡A§Y¨Ï CPU ¯à³B¨Ò³o¨Ç¸ê®Æ¡A©Ò±oµ²ªG¤]¬OµL·N¸qªº¡C

©³¤U¤p¤ì°¸¹ïµwÅ餤Â_°µ¤@²³æ´y­z¡C


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