Ch 08¡@°ïÅ|

°ïÅ|¬O¹q¸£¤¤¤@¶ô«Ü¯S®íªº°O¾ÐÅé¡A¤]¦]¬°¥¦¯S®íªº¹B§@¤è¦¡¡A¨Ï±o°ïÅ|¥i¥H«Ü®e©ö¸Ñ¨M³\¦h«ÜÃø½s¼gªºµ{¦¡¡A¨Ò¦p¯à³B²z¥ý­¼°£«á¥[´îªº­pºâ¾÷µ{¦¡¡C°£¦¹¤§¥~¡A°ïÅ|¤]¸ò¤U¤@³¹­n´£¤Îªº°Æµ{¦¡¡B°Ï°ìÅܼơA¥H¤Î©I¥s¨ó©wµ¥µ¥¦³Ãö¡C¦ý¥»³¹¥ýÁ׶}³o³¡¤À¤£Á¿¡A¶È¥ý¤¶²Ð°ïÅ|¥H¤Î¥¦ªº¹B§@¤è¦¡¡C


°ïÅ| ( Stack )

°ïÅ|¬O¤@¶ô¥i¥H¥Î¨Ó¦s©ñ¸ê®Æªº°O¾ÐÅé¡A¦ý¬O°ïÅ|¤S»P¤@¯ë¦s©ñÅܼƩε{¦¡½Xªº°O¾ÐÅ餣¦P¡C­n¤F¸Ñ°ïÅ|¡A§Ú­Ì¥ý¬Ý¤@­Ó¤é±`¥Í¬¡¤W¨Ò¤l¡Ð¡ÐÀ\ÆUÃoÂdùتº½L¤l¡C¨C·í¼p®v¬~¦n½L¤l¡A«K±N¬~¦nªº½L¤lÅ|¦b¤wÂ\¦nªº½L¤l¤W­±¡A¤£·|§âÂ\¦nªº½L¤l·h¶}¡A±N­è¬~¦nªº½L¤l©ñ³Ì¤U­±¡A¦A§â­ì¥ýªº½L¤lÅ|¨ì­è¬~¦nªº½L¤l¤W¡F·í­n¨Ï¥Î½L¤l®É¡A¤]¬O¥Ñ³Ì¤W­±¶}©l¨Ï¥Î¡C¤]´N¬O»¡¡A¶V¥ý©ñ¶i¥hªº½L¤l¡A¶V«á¨Ï¥Î¡F¶V«á©ñ¶i¥hªº½L¤l¡A¶V¥ý¨Ï¥Î¡C³o¨Ç½L¤l¨ã¦³«á¶i¥ý¥X ( last in, first out¡A²¼g¬° LIFO ) ªº¯S©Ê¡C

°µ¬°°ïÅ|ªº°O¾ÐÅé¤]¨ã¦³³o¼Ë¡u«á¶i¥ý¥X¡vªº¯S©Ê¡A¥u¤£¹L¡A¦b°ïÅ|ùئs©ñªº¤£¬O½L¤l¦Ó¬O¸ê®Æ¡A©ÎªÌ¤]¥i¥H»¡¬O¼Æ­È¡C¬JµM°ïÅ|¤]¬O¤@¶ô°O¾ÐÅé¡A¨º»ò¡A³o¶ô°O¾ÐÅé¦b­þ¨à©O¡H¥¦¤£¬O¦b¸ê®Æ°Ï¬q¡A¤]¤£¦bµ{¦¡½X°Ï¬q¡A¦Ó¬O©ñ¦b°ïÅ|°Ï¬q¡C¦b IBM PC ¤Î¨ä¬Û®e¹q¸£ùØ¡A¯S§O¥Î°ïÅ|°Ï¬q¼È¦s¾¹ ( stack segment register ) ©Ò«ü¦Vªº°Ï¬q¨Ó¦s©ñ°ïÅ|¡A°ïÅ|°Ï¬q¼È¦s¾¹¦b DEBUG ©Î SYMDEB ¥H SS ªí¥Ü¡C¨Ò¦p DEBUG ¨ÓÆ[¹î¼È¦s¾¹¬Ý¬Ý¡G

C:\>debug [Enter]
-r [Enter]
AX=0000  BX=0000  CX=0000  DX=0000  SP=FFFE  BP=0000  SI=0000  DI=0000  
DS=11D1  ES=11D1  SS=11D1  CS=11D1  IP=0100   NV UP EI PL NZ NA PO NC 
11D1:0100 0F            DB  0F

¤W­±¥Îµµ¦â¦r¼Ð¥Üªº´N¬O°ïÅ|°Ï¬q¼È¦s¾¹¡A¥¦¸ò CS¡BDS ¤@¼Ë³£¬O°Ï¬q¼È¦s¾¹¡C¦n¤F¡A²{¤wª¾¹D°ïÅ|¬O©ñ¦b SS ©Ò«üªº°Ï¬qùØ¡A¦ý¬O¤@­Ó°Ï¬q¦³ 64KB ³o»ò¤j¡A¨º»ò½T¤Áªº¦ì§}¤S¦b­þ¨à©O¡Hµª®×¬O¦b°ïÅ|«ü¼Ð¼È¦s¾¹©Ò«üªº°¾²¾¦ì§}¤W¡A°ïÅ|«ü¼Ð¼È¦s¾¹­^¤å¦W¬° stack pointer register¡A²ºÙ SP¡A´N¬O¤W­±¥H²HÂŦâ¦rªí¥Üªº¼È¦s¾¹¡A¦¹®É SP ¬° FFFE¡C

­è¶}©l°õ¦æ DEBUG ®É¡A©Î¬O¥H DEBUG ¸ü¤J COM ¥i°õ¦æÀɮɡASP ³£·|«ü¦V°ïÅ|³Ì³»ºÝ¡A¤]´N¬O¦ì§} FFFE ªº¦a¤è¡C¨Æ¹ê¤W¡ASP ªº§@¥Î´N¬O«ü¦V°ïÅ|³»ºÝ¡C°ïÅ|¦s¨ú¤è¦V»P¤@¯ëµ{¦¡¤£¦P¡A¾÷±ñ½X¦b°õ¦æ®É¬O¥Ñµ{¦¡½X°Ï¬qªº§C¦ì§}³B³vº¥©¹°ª¦ì§}°õ¦æ¡A¦ý¬O°ïÅ|«o¬O¥Ñ°ª¦ì§}³B³vº¥©¹§C¦ì§}·s¼W¸ê®Æ¡F¦¹¥~ÁÙ¦³¤@ÂI¤£¦P¡A«eªÌ¥H CS:IP «ü¦V¥Ø«e°õ¦æªº¾÷±ñ½X¦ì§}¡A«áªÌ¥H SS:SP «ü¦V°ïÅ|³»ºÝªº¦ì§}¡C¤S¥Ñ©ó DOS ¬O¤Q¤»¦ì¤¸ªº¨t²Î¡A¦]¦¹¤j³¡¤Àªº±¡§Î¤U¡A¦s¤J°ïÅ|¤@µ§¸ê®Æ¤]¬O¤Q¤»¦ì¤¸ªº¼Æ­È¡A¤Q¤»¦ì¤¸¦û¨â­Ó¦ì¤¸²Õ¡A¬G¨C·í¦³¤@µ§¸ê®Æ¦s¤J°ïÅ|¡ASP ¤§­È¤]·|´î¤Ö¤G¡A¨Ï¨ä­«·s«ü¦V°ïÅ|³»ºÝ¡C

¥Ñ¥H¤Wªº»¡©ú¡A¥i¥H¾ã²z±o¨ì°ïÅ|¦³¤U­±´X¶µ¯S©Ê¡G

  1. LIFO¡C
  2. ¸ê®Æªº¦s¤J¥Ñ°ª¦ì§}©¹§C¦ì§}¦s¤J¡C
  3. ¸ê®Æ¦s¤J®É¤£¶·«ü©w¦ì§}¡A¥Ñ SS:SP ´N¯àª¾¹D¡C
  4. ¨C¦¸¦s¤Jªº¸ê®Æ¤j¤p¬O¤Q¤»¦ì¤¸¡C

­è­è´£¹L¡A°ïÅ|¨ã¦³ LIFO ªº¯S©Ê¡A¬°¤F¹F¦¨¦¹¥Øªº¡A¥²¶·¨Ï¥Î¯S®íªº¤èªk¦s¨ú°ïÅ|ªº¤º®e¡C¤j³¡¤Àªº±¡§Î¤U¡A¥i¥H¥Î¨â­Ó x86 «ü¥O¦s¨ú°ïÅ|¡GPUSH »P POP¡C


x86 «ü¥O¡GPUSH

PUSH «ü¥Oªº»yªk¬O

PUSH    ¹Bºâ¤¸

PUSH «ü¥O¬O§â±µ¦b«á­±ªº¹Bºâ¤¸¦s¤J°ïÅ|³»ºÝ¡A³o­Ó¹Lµ{¤]¥s§â¸ê®Æ±À¤J°ïÅ|¡CSP ©Ò«üªº¦ì§}¬O°ïÅ|³»ºÝ¡A³oùؤw¦s¦³¸ê®Æ¡A¦]¦¹ PUSH ·|¥ý§â SP ´î¥h¨â­Ó¦ì¤¸²Õ¡AµM«á¦A§â¹Bºâ¤¸ªº¤º®e¼g¤J SP ©Ò«üªº°ïÅ|¦ì§}¡C¦¹³Bªº¹Bºâ¤¸¥i¥H¬O¤Q¤»¦ì¤¸ªº¼È¦s¾¹¡BÅܼơA¤£¯à¬O±`¼Æ¡C¥u¦³ 80286 µ¥¯Å©Î¥H¤Wªº CPU ¤~¯à¨Ï¥Î±`¼Æ¡C


x86 «ü¥O¡GPOP

POP «ü¥O¬O¨ú±o°ïÅ|³»ºÝªº¸ê®Æ¡A»yªk¬O

POP     ¹Bºâ¤¸

POP ·|§â°ïÅ|³»ºÝ¤Q¤»¦ì¤¸ªº¼Æ­È½Æ»s¨ì¨ä«á©Ò±µªº¹Bºâ¤¸ùØ¡AµM«á¦A¨Ï SP ¥[¤G¡A³oùتº¹Bºâ¤¸¥i¥H¬O¤Q¤»¦ì¤¸ªº¼È¦s¾¹©ÎÅܼơC

°ïÅ|ªº¹B§@

¦b»¡©ú PUSH »P POP ¨â­Ó«ü¥O¤§«á¡A§Ú­Ì¨Ó¬Ý¬Ý¥¦­Ì¹ï°ïÅ|ªº¾Þ§@¡C­º¥ý¦b DEBUG ùØ­±¿é¤J¤U­±µ{¦¡¡G

-a [Enter]
11D1:0100 mov ax,cdef [Enter]
11D1:0103 mov bx,3355 [Enter]
11D1:0106 push ax [Enter]
11D1:0107 push bx [Enter]
11D1:0108 sub ax,ax [Enter]
11D1:010A xor bx,bx [Enter]
11D1:010C pop bx [Enter]
11D1:010D pop ax [Enter]
11D1:010E [Enter]

¤Ï²ÕĶ³o¬qµ{¦¡¡A³o¬qµ{¦¡¨ä¹ê¨S¤°»ò¥Î³B¥u¬OÅýªì¾ÇªÌÁA¸Ñ°ïÅ|ªº¹B§@¡C«e¥|±ø«ü¥O¬O³]©w AX¡BBX ¤§­È¡AµM«á±N¥L­Ì±À¤J°ïÅ|ùØ¡A¦A³]©w AX¡BBX ¤§­È¬°¹s¡A¦A¥Ñ°ïÅ|¨ú¦^­ì­È¡C

-u 100 10d [Enter]
11D1:0100 B8EFCD        MOV     AX,CDEF
11D1:0103 BB5533        MOV     BX,3355
11D1:0106 50            PUSH    AX
11D1:0107 53            PUSH    BX
11D1:0108 29C0          SUB     AX,AX
11D1:010A 31DB          XOR     BX,BX
11D1:010C 5B            POP     BX
11D1:010D 58            POP     AX

°õ¦æ¨â¦¸¡uT¡v«ü¥O¡AÆ[¹î­«ÂI¦b©ó AX¡BBX ¤§­Èªº§ïÅÜ¡G

-t [Enter]

AX=CDEF  BX=0000  CX=0000  DX=0000  SP=FFFE  BP=0000  SI=0000  DI=0000  
DS=11D1  ES=11D1  SS=11D1  CS=11D1  IP=0103   NV UP EI PL NZ NA PO NC 
11D1:0103 BB5533        MOV     BX,3355
-t [Enter]

AX=CDEF  BX=3355  CX=0000  DX=0000  SP=FFFE  BP=0000  SI=0000  DI=0000  
DS=11D1  ES=11D1  SS=11D1  CS=11D1  IP=0106   NV UP EI PL NZ NA PO NC 
11D1:0106 50            PUSH    AX

±µµÛ´N¬O­«¶bÀ¸¤W³õ¤F¡A­nÆ[¹î°ïÅ|ªº¹B§@¤F¡A¥ý¬Ý¬Ý°ïÅ|ªº±¡§Î¡A¦A°õ¦æ¡uPUSH AX¡v¡G

-d fff0 l10 [Enter]
11D1:FFF0  E6 7C 00 00 0B 01 D1 11-35 0C E6 7D E6 7E 00 00   .|......5..}.~..
-t [Enter]

AX=CDEF  BX=3355  CX=0000  DX=0000  SP=FFFC  BP=0000  SI=0000  DI=0000  
DS=11D1  ES=11D1  SS=11D1  CS=11D1  IP=0107   NV UP EI PL NZ NA PO NC 
11D1:0107 53            PUSH    BX
-d fff0 l10 [Enter]
11D1:FFF0  E6 7C 00 00 0B 01 D1 11-35 0C E6 7D EF CD 00 00   .|......5..}....

ª`·N¨ì¤W­±ªº¬õ¦r¡A¡uPUSH AX¡v·|¨Ï SP ·|´î¤Ö¤G¡A¦A§â AX ±À¤J°ïÅ|³»ºÝ¡A¥ç§Y SS:SP ©Ò«üªº¦ì§}¡A©Ò¥H 11D1:FFFC ¤§­ÈÅܦ¨ CDEF¡C±µ¤U¨Ó¦A°õ¦æ¡uPUSH BX¡v¡A¨Ï BX ±À¤J°ïÅ|ùØ¡G

-t [Enter]

AX=CDEF  BX=3355  CX=0000  DX=0000  SP=FFFA  BP=0000  SI=0000  DI=0000  
DS=11D1  ES=11D1  SS=11D1  CS=11D1  IP=0108   NV UP EI PL NZ NA PO NC 
11D1:0108 29C0          SUB     AX,AX
-d fff0 l10 [Enter]
11D1:FFF0  E6 7C 00 00 0B 01 D1 11-35 0C 55 33 EF CD 00 00   .|......5.U3....

°õ¦æ§¹¡uPUSH BX¡v«á¡AÆ[¹î°ïÅ|ªº±¡§Î¡A­«ÂI¤´µM¬O¤W­±¬õ¦r¡C±µ¤U¨Óªº¨â­Ó«ü¥O¡A¤À§O¬OÅý AX¡BBX Åܦ¨¹s¡A¦ý¨S¤°»ò¥iÆ[¹îªº¥iª½±µ¸õ¹L¡C¥»¨Ó¤]¥i¥H¥Î¡uMOV AX,0¡v¡B¡uMOV BX,0¡v¡A¦ý¬O³o¼Ëªº¾÷±ñ½X·|¨Ï¥Î¸û¦hªº¦ì¤¸²Õ¡C

-t [Enter]

AX=0000  BX=3355  CX=0000  DX=0000  SP=FFFA  BP=0000  SI=0000  DI=0000  
DS=11D1  ES=11D1  SS=11D1  CS=11D1  IP=010A   NV UP EI PL ZR NA PE NC 
11D1:010A 31DB          XOR     BX,BX
-t [Enter]

AX=0000  BX=0000  CX=0000  DX=0000  SP=FFFA  BP=0000  SI=0000  DI=0000  
DS=11D1  ES=11D1  SS=11D1  CS=11D1  IP=010C   NV UP EI PL ZR NA PE NC 
11D1:010C 5B            POP     BX

±µ¤U¨Óªº¨â­Ó«ü¥O¬O¨Ï AX¡BBX «ì´_­ì­È¡A­nª`·Nªº¬O°ïÅ|¨ã¦³«á¶i¥ý¥Xªº¯S©Ê¡C§Ú­Ì§â¼È¦s¾¹±À¤J°ïÅ|ªº¶¶§Ç¬O¥ý AX «á BX¡A­n¼u¥X°ïÅ|¨Ï«ì´_¼È¦s¾¹­ì­È®É­n¥ý BX «á AX¡C´N¬O­n¤Ï¹L¨Ó°õ¦æªº·N«ä¡C©³¤UªºÆ[¹î­«ÂI¬O¤U­±¬õ¦r³B¡GBX «ì´_¬° 3355¡ASP ­È·|¥[¤G¡C

-t [Enter]

AX=0000  BX=3355  CX=0000  DX=0000  SP=FFFC  BP=0000  SI=0000  DI=0000  
DS=11D1  ES=11D1  SS=11D1  CS=11D1  IP=010D   NV UP EI PL ZR NA PE NC 
11D1:010D 58            POP     AX                                 
-d fff0 l10 [Enter]
11D1:FFF0  E6 7C 00 00 0B 01 D1 11-35 0C 55 33 EF CD 00 00   .|......5.U3....

°õ¦æ§¹¡uPOP BX¡v«á¡A¤p¤ì°¸ÁÙÆ[¹î¤F°ïÅ|ªº±¡§Î¡A¦p¤W­±³Ì«á¤@¦æ¡C¬Ý°_¨Ó°O¾ÐÅ餺®e³£¨S¦³§ïÅÜ¡A¦ý¬O­nª¾¹D³o®É­Ô°ïÅ|³»¤w¸g¬O«ü¦V¦ì§} FFFC ªº¦a¤è¤F¡A¥ç§Y°ïÅ|³»ºÝ¬O CDEF¡A3355 ¨ä¹ê¤w¤£¦b°ïÅ|¤¤¡C¦pªGµ{¦¡¦A«×§â¼Æ­È¦s¤J°ïÅ|®É¡A3355 ´N·|®ø¥¢¡C©³¤U¦A°õ¦æ¡uPOP AX¡v¡G

-t [Enter]

AX=CDEF  BX=3355  CX=0000  DX=0000  SP=FFFE  BP=0000  SI=0000  DI=0000  
DS=11D1  ES=11D1  SS=11D1  CS=11D1  IP=010E   NV UP EI PL ZR NA PE NC 
11D1:010E 12B1048B      ADC    DH,[BX+DI+8B04]                     DS:BE59=18

¤W­±¨BÆJÆ[¹îªº­«ÂI¬O AX «ì´_­ì­È¡A»P SP ­È¥[¤G¡A¥H¬õ¦rªí¥Ü¡C¤W­±ªº¹Lµ{¥i¥H¥Î¤U¹Ïªí¥Ü¡G


°ïÅ|ªºÀ³¥Î

°ïÅ|¦³³\¦hÀ³¥Î¡A³Ì±`¨£ªº¬O¼È®É«O¦s¬Y­Ó¼È¦s¾¹ªº¼Æ­È¡C¨Ò¦p©I¥s DOS ªA°Èµ{¦¡®É¡A¦³®É·|¥Î¨ì³\¦h¼È¦s¾¹¡A³o®É¥i¥H¥ý§Q¥Î°ïÅ|«O¦s­«­nªº¼È¦s¾¹¡Aµ¥³B²z¦n¦A¥Ñ°ïÅ|¨ú¦^¡C

¦ý¦pªG¥u¬O³o¼Ëªº¸Ü¡A´N¤Ó¤p¬Ý°ïÅ|¤F¡A¥¦ÁÙ¥i¥H¶i¦æ¡u¥ý­¼°£«á¥[´î¡vªººtºâ¤è¦¡¡BÁÙ¥i¥H¥Î¦b°Æµ{¦¡¤¤¡C«eªÌ¤Ó¹L½ÆÂøªì¾ÇªÌ¤£¾A¥Î¡A«áªÌ¯d«Ý¤U¤@³¹¦A»¡¡C³oùؤp¤ì°¸´£¤@­Ó²³æªºÀ³¥Î¡G§â¦r¦ê¤Ï§Ç¦L¥X¨Ó¡A¨Ò¦p¹q¼v¡uÅK¹F¥§¸¹¡v¦³¥y¸g¨å»Oµü¡G¡uA woman's heart is a deep ocean of secrets.¡v¡A§â¥¦Åܦ¨¡u.sterces fo naeco peed a si traeh s'namow A¡v¡C

¤Ï§Ç¦L¥X­^¤å

©³¤Uªº REVERSE1.ASM ¯à§â¤@­Ó­^¤å¥y¤l¥H¬Û¤Ï¶¶§Ç¦L¦b¿Ã¥ú¹õ¤W¡C

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
;§Q¥Î°ïÅ|¡A¤Ï¦V±Æ¦C¤å¦r
.MODEL  TINY
.386
;*************************************************************
.CODE  
ORG     100h
;-------------------------------------------------------------
start:  jmp     begin
titanic db      "A woman's heart is a deep ocean of secrets. "
begin:  mov     bx,OFFSET titanic
        mov     cx,SIZEOF titanic/2
        push    "$"
.WHILE cx
        mov     ax,[bx]
        xchg    al,ah
        push    ax
        add     bx,2
        dec     cx
.ENDW
        mov     dx,sp
        mov     ah,9
        int     21h
        int     20h
;*************************************************************
END     start

©³¤U¬O REVERSE1 ²ÕĶ³sµ²¤Î°õ¦æªºµ²ªG¡G

§âÅK¹F¥§¸¹¹q¼vªº¥xµü¤Ï§Ç±Æ¦C

REVERSE1 «Ü²µu¤£Ãø²z¸Ñ¡A¦ý¦³´X­ÓÆ[©À´£¤@´£¡C¤@­Ó­^¤å¦r¥À¥Î¤@­Ó¦ì¤¸²Õªº ASCII ½Xªí¥Ü¡A¦ý¬O¨C¦¸¦s¤J°ïÅ|ªº¸ê®Æ¬O¤@­Ó¦r²Õ ( ¤@­Ó¦r²Õ¬O¨â­Ó¦ì¤¸²Õ )¡A¦]¦¹¤@¦¸±o¦s¤J¨â­Ó¦r¥À¡C©Ò¥H¦b²Ä¤Q¤@¦æªº¬O§â°j°é¦¸¼Æ¦s¤J CX ùخɡA¦¸¼Æµ¥©ó¥y¤lªºªø«×°£¥H¤G¡C

²Ä¤E¦æªº¥y¤l­ì¥»¬O¡uA woman's heart is a deep ocean of secrets.¡v( ¤k¤H¤ß®ü©³°w )¡A³Ì«á¥[¤W¤@­ÓªÅ¥Õ¡C³o¬O¦]¬°¦¹¥y¤lªºªø«×¬O©_¼Æ¡A¦]¦¹´ê¤W¤@­ÓªÅ¥Õ°t¦¨°¸¼Æ¡A§_«h¤Ï§Ç±Æ¦C«á·|¤Ö¤@­Ó¦r¡C

²Ä¤Q¤G¦æ¦b¶i¤J°j°é«e¥ý¦s¤J¤@­Ó¡u$¡v¦r¤¸¡A¬O¦]¬°³Ì«á­n¥Î¡uAH¡×9/INT 21H¡vDOS ªA°È¥\¯à¦L¥X¦r¦ê¨Ó¡A¥[¤W¡u$¡v§i¶D INT 21H ¦r¦ê¨ì¦¹µ²§ô¡C¡u$¡v¥²©w¬O¦b¦r¦êªºµ²§À¡A¬O¦r¦ê¤¤¦ì§}³Ì°ªªº¦a¤è¡C

¨C¦¸­n¦s¤J°ïÅ|ªº¦r¥À¦³¨â­Ó¡A¦]¦¹¦b¦s¤J«e¤]­n¥ý¥æ´«¡A³o®É´N­nÂǧU¤@­Ó©|¥¼¤¶²Ðªº x86 «ü¥O¡AXCHG¡A¨Ó¹F¦¨¦¹¥Øªº¤F¡C


x86 «ü¥O¡GXCHG

XCHG «ü¥Oªº»yªk¬O

XCHG    ¹Bºâ¤¸¤@,¹Bºâ¤¸¤G

XCHG ¬O¨Ï¹Bºâ¤¸¤@»P¹Bºâ¤¸¤G¤§­È¤¬´«¡C³o¨â­Ó¹Bºâ¤¸¥i¥H¬O¨â­Ó¼È¦s¾¹ ( ¦ý¤£¯à¬O°Ï¬q¼È¦s¾¹ )¡A©Î¬O¤@­Ó¼È¦s¾¹©M¤@­ÓÅܼơA¦ý¤£¯à¬O¨â­ÓÅܼơA¦Ó¥B¨â­Ó¹Bºâ¤¸ªºªø«×­n¬Û¦P¡CXCHG ¤£·|¼vÅT¥ô¦óºX¼Ð¡C¨Ò¦p©³¤Uªº¨Ò¤l³£¬O¦Xªkªº¡G

value   DB      25
        XCHG    AX,BX
        XCHG    CL,DL
        XCHG    value,DH

¦^¤åÅé

¨â¬Û«ä

§â¤@¥y­^¤å¥y¤lùتº¦r¥À¡AÄA­Ë¦L¦b¿Ã¥ú¹õ¤W¡A³q±`±o¨ì¤@¦êµL·N¸qªº¦r¥À¡C¤p¤ì°¸¤£ª¾¹D¬O§_¦³­^¤å¥y¤l¡A­ËµÛ°á¤]¬O¦³·N¸qªº¡F¦Ó¤¤¤å«o¬O¥i¥H¡AÁÙ¦³¤H±Mªù³Ð§@³oºØ¤åÅé¡A³oºØ¤åÅéÁÙ¦³­Ó¦W¦r¡AºÙ¬°¡u¦^¤åÅé¡v¡C©³¤U¬O§º´Â§õ¬ë ( ­µ¦P¡u¨|¡v) ¼gªº¤@­º¸Ö¡A¥¿µÛ°á¬O¡u«ä©d¡v¡A­ËµÛ°á¬O¡u«ä¤Ò¡v¡A¬GºÙ¡u¨â¬Û«ä¡v¡A«Ü¦³½ì¡C

©³¤Uªº REVERSE2.ASM µ{¦¡ªº¸ê®ÆùØ¡A¶È¶È¦³¤W¥b­º¡u«ä©d¡v¡A¦Ó§Q¥Î°ïÅ|«á¶i¥ý¥Xªº¯S©Ê¡A¹Bºâ¥X¤U¥b­º¡u«ä¤Ò¡v¡G

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
;§Q¥Î°ïÅ|¡AÅã²{¤¤¤å¦^¤åÅ骺¶ø§®
.MODEL  TINY
.386
;*************************************************************
.CODE  
ORG     100h
;-------------------------------------------------------------
start:  jmp     begin
author  DB      "¡m¨â¬Û«ä¡n¡@§º¡@§õ¬ë",0dh,0ah,
                "¥¿µÛŪ¬O¡u«ä©d¡v",0dh,0ah
peom    DB      "¬\²´»»±æ¤s¹j¤ô¡A©¹¨Ó´¿¨£´X¤ßª¾",0dh,0ah,
                "³ýªÅ©È°u¤@ªM°s¡Aµ§¤UÃø¦¨©MÃý¸Ö",0dh,0ah,
                "³~¸ôªý¤HÂ÷§O¤[¡A°T­µµL¶­±H¦^¿ð",0dh,0ah,
                "©t¿O©]¦uªø¹é±I¡A¤Ò¾Ð©d¤¼¤÷¾Ð¨à"
husband DB      13,10,13,10,"­ËµÛŪ¬O¡u«ä¤Ò¡v",13,10,"$"
begin:  mov     dx,OFFSET author
        mov     ah,9
        int     21h
        mov     bx,OFFSET peom
        mov     cx,SIZEOF peom/2
        push    "$"
next:   mov     ax,[bx]
        push    ax
        add     bx,2
        loop    next
        mov     dx,sp
        mov     ah,9
        int     21h
        int     20h
;*************************************************************
END     start

¦]¬°³o­Óµ{¦¡¦L¦b¿Ã¥ú¹õ¤Wªº¸ê®Æ§t¦³¤¤¤å¦r¡A©Ò¥H¥²¶·¦b¤¤¤å¨t²Î¤U°õ¦æ¤~¦æ¡A§_«h·|Åܦ¨¤@¹Î¶Ã½X¡C­n¶i¤J¤¤¤å¨t²Î¡A¥i¥H°Ñ¾\ªþ¿ý¤@ªº¡uMS-DOS 6.20 µêÀÀ¾÷¾¹¦w¸Ë­Ê¤Ñ¤¤¤å¨t²Î¡v¡C©³¤U¬õ¦â®Ø¦íªº³¡¤À´N¬O REVERSE2 µ{¦¡°õ¦æªºµe­±¡C

°²¦p§A¥J²ÓÆ[¹î REVERSE1.ASM »P REVERSE2.ASM¡A·|µo²{«eªÌ¦³­Ó XCHG «ü¥O¡A«áªÌ«o¨S¦³¡A³o¬O¤°»ò­ì¦]©O¡H

­Ê¤Ñ¤¤¤å¨t²Î©M­^¤å¤@¼Ë¡A¤]¬O¥Î¤@­Ó¼Æ¦r¥Nªí¤@­Ó¦r¡C¦ý¬O­^¤å¶È 26 ­Ó¦r¥À¡A¥[¤W¤j¤p¼g¡Bªü©Ô§B¼Æ¦r¡B¼ÐÂI²Å¸¹µ¥µ¥¡A¤£·|¶W¹L 256 ­Ó¦r¡A¦]¦¹¥Î¤@­Ó¦ì¤¸²Õ´N¯àªí¥Ü¤F¡A¦]¦¹¬ü°ê¨î©wªº ASCII ½X¶È¥Î 7 ­Ó¦ì¤¸¡A«á¨Ó IBM ¤~±N¨äÂX¥R¦¨¤K­Ó¦ì¤¸¡C¦ý±`¥Îªº¤¤¤å¦r¤Ö»¡¦³¤]¼Æ¤d¡A¦A¥[¤W¨u¥Î¦r¡A¥i¯à¼Æ¸U¡A¦]¦¹±o¥Î¨â­Ó¦ì¤¸²Õ¨Óªí¥Ü¤@­Ó¤¤¤å¦r¡C³o¤]´N¬O REVERSE2.ASM ùØ¡A¦b±À¤J°ïÅ|«e¡AAL¡BAH ¤£»Ý­n¥æ´«ªº­ì¦]¤F¡C

¥H SYMDEB °lÂÜ REVERSE2.COM

¦b²ÕĶ®É¡A½Ð¿é¤J¡u/Zf /Fm¡v°Ñ¼Æ¡A¥H»s§@ REVERSE2.MAP¡A¦A¥H REVERSE2.MAP »s§@ REVERSE2.SYM¡AµM«á¦b¤¤¤å¨t²Î¤U¡A¥H SYMDEB ¸ü¤J²Å¸¹ÀɤΠCOM ÀÉ¡A¦p¤W¹Ï³Ì«á¤@­Ó«ü¥O¡A³o¼Ë´N¯à°lÂܤF¡C©³¤U¬O°lÂܸg¹L¡A¶i¤J SYMDEB «á¥ý¤Ï²ÕĶ¡G

  E:\DOS\REVERSE>c:\tools\symdeb reverse2.sym reverse2.con [Enter]
  Microsoft (R) Symbolic Debug Utility  Version 4.00
  Copyright (C) Microsoft Corp 1984, 1985.  All rights reserved.
  
  Processor is [80286]
  -u begin 1dd [Enter]
  DGROUP:begin:
  3ACB:01C0 BA0301         MOV	DX,0103
  3ACB:01C3 B409           MOV	AH,09
  3ACB:01C5 CD21           INT	21
  3ACB:01C7 BB2B01         MOV	BX,012B
  3ACB:01CA B93F00         MOV	CX,003F
  3ACB:01CD 6A24           PUSH	24                            ;'$'
┌─DGROUP:next:
│ 3ACB:01CF 8B07           MOV	AX,[BX]
│ 3ACB:01D1 50             PUSH	AX
│ 3ACB:01D2 83C302         ADD	BX,+02
└─3ACB:01D5 E2F8           LOOP	next
  3ACB:01D7 8BD4           MOV	DX,SP
  3ACB:01D9 B409           MOV	AH,09
  3ACB:01DB CD21           INT	21
  3ACB:01DD CD20           INT	20

¦b 01CF¡ã01D5 ¤§¶¡ªºµ{¦¡¬O­Ó°j°é¡A¦b°j°é°õ¦æ§¹«áªº¦ì§} 01D7 ³]²Ä¹s¸¹¤¤Â_ÂI¡C¦¹¥~¤p¤ì°¸Æ[¹î­«ÂI¬O°ïÅ|¡A¦]¦¹°õ¦æ¨ì 01CD ¬°¤î¡A¦p¤U¡G

  -bp 1d7 [Enter]
  -g 1cd [Enter]
  ¡m¨â¬Û«ä¡n¡@§º¡@§õ¬ë
  ¥¿µÛŪ¬O¡u«ä©d¡v
  ¬\²´»»±æ¤s¹j¤ô¡A©¹¨Ó´¿¨£´X¤ßª¾
  ³ýªÅ©È°u¤@ªM°s¡Aµ§¤UÃø¦¨©MÃý¸Ö
  ³~¸ôªý¤HÂ÷§O¤[¡A°T­µµL¶­±H¦^¿ð
  ©t¿O©]¦uªø¹é±I¡A¤Ò¾Ð©d¤¼¤÷¾Ð¨à

  ­ËµÛŪ¬O¡u«ä¤Ò¡v
  AX=0924  BX=012B  CX=003F  DX=0103  SP=FFFE  BP=0000  SI=0000  DI=0000
  DS=3ACB  ES=3ACB  SS=3ACB  CS=3ACB  IP=01CD   NV UP EI PL NZ NA PO NC
  3ACB:01CD 6A24           PUSH   24                            ;'$'

±µ¤U¨Ó´N¬O­«¶bÀ¸¤F¡C¥ýÆ[¹î°ïÅ|¤ºªº±¡§Î¡A¦p¤U­±¡A°ïÅ|³»¦b FFFE ³B¡A°ïÅ|ùØ¥u¦³¤@µ§¸ê®Æ¡A´N¬O 0000¡C©³¤U°ïÅ|³£¥H¥Õ¦âªº¦rªí¥Ü¡A¬õ¦r¬O SP ¤§­È¡C

  -d fff0 l10 [Enter]
  3ACB:FFF0  00 00 00 00 24 09 00 00-CD 01 CB 3A B4 31 00 00  ....$...M.K:41..
  -t [Enter] ¡÷°õ¦æ PUSH 24
  AX=0924  BX=012B  CX=003F  DX=0103  SP=FFFC  BP=0000  SI=0000  DI=0000
  DS=3ACB  ES=3ACB  SS=3ACB  CS=3ACB  IP=01CF   NV UP EI PL NZ NA PO NC
  DGROUP:next:
  3ACB:01CF 8B07           MOV    AX,[BX]                            DS:012B=5CAC
  -d fff0 l10 [Enter]
  3ACB:FFF0  00 00 00 00 24 09 00 00-CD 01 CB 3A 24 00 00 00  ..$...O.K:41$...

°õ¦æ¡uPUSH 24¡v«á¡A¦AÆ[¹î°ïÅ|«K¥iµo²{°ïÅ|³»¤wÅܦ¨ FFFC¡A¦P®É°ïÅ|¤º·s¼W¤@µ§¸ê®Æ 0024¡C³oµ§¸ê®Æ¨ä¹ê¬O ASCII ¦r¤¸ªº¡u$¡v¡A¥¦¬O¬°¤F¦b©I¥s AH¡×9/INT 21H ®É¡A©Ò¦L¥X¦r¦êªº²×¤î¦r¤¸¡C

±µ¤U¨Óªº«ü¥O¬O§â BX ©Ò«ü¦ì§}ªº¼Æ­È¡A5CAC¡A²¾¤J AX ùØ¡A³o­Ó¼Æ­È¬O¤¤¤å¦rªº¡u¬\¡v( µù¤@ )¡C¦p¤U­±Åã¥Üªº±¡§Î¡A§â¥Nªí¡u¬\¡v¦rªº¼Æ­È²¾¤J AX¡A±µ¤U¨Ó±N¥¦±À¤J°ïÅ|ùØ¡A¦AÆ[¹î SP »P°ïÅ|¡G

  -t [Enter]
  AX=5CAC  BX=012B  CX=003F  DX=0103  SP=FFFC  BP=0000  SI=0000  DI=0000
  DS=3ACB  ES=3ACB  SS=3ACB  CS=3ACB  IP=01D1   NV UP EI PL NZ NA PO NC
  3ACB:01D1 50             PUSH   AX
  -t [Enter]
  AX=5CAC  BX=012B  CX=003F  DX=0103  SP=FFFA  BP=0000  SI=0000  DI=0000
  DS=3ACB  ES=3ACB  SS=3ACB  CS=3ACB  IP=01D2   NV UP EI PL NZ NA PO NC
  3ACB:01D2 83C302         ADD    BX,+02
  -d fff0 l10 [Enter]
  3ACB:FFF0  00 00 00 00 24 09 00 00-CD 01 AC 5C 24 00 00 00  ,\..R.K:41,\$...
  -bp 1d2 [Enter]

¦p¤W­±©Ò¥Ü¡ASP ¦A´î¤Ö¤G¡A¦P®É°ïÅ|³»ºÝÅܦ¨¡u5CAC¡v¤F¡C¦]¬°¦b°j°é¤¤¡A§Ú­ÌÆ[¹îªº­«ÂI¬O°ïÅ|ªº¾Þ§@¡A¨ä¥L«ü¥O´Nª½±µ¸õ¹L¡A©Ò¥H¤W­±³Ì«á¤@­Ó«ü¥O¬O¦b¦ì§} 01D2 ³]¸m¤@¸¹¤¤Â_ÂI¡AµM«á¤U¹F¡uG¡v«ü¥O¡G

  -g [Enter]
  AX=B4B2  BX=012D  CX=003E  DX=0103  SP=FFF8  BP=0000  SI=0000  DI=0000
  DS=3ACB  ES=3ACB  SS=3ACB  CS=3ACB  IP=01D2   NV UP EI PL NZ NA PE NC
  3ACB:01D2 83C302         ADD    BX,+02                        ;BR1
  -d fff0 l10 [Enter]
  3ACB:FFF0  00 00 00 00 24 09 00 00-B2 B4 AC 5C 24 00 00 00  ..R.K:4124,\$...

G «ü¥O°õ¦æ¨ì¤@¸¹¤¤Â_ÂIªº¦ì§}´N°±¤î¤U¨Ó¡A¦p¤W­±¾í¦â¦r©Ò¥Ü¡AÅã¥Ü¼È¦s¾¹ª¬ªp¡A§Ú­Ì¦A¤U¹F¡ud fff0 l10¡vÆ[¹î°ïÅ|¡A¤@¦p¹w´Á¡ASP ´î¤G¡B°ïÅ|³»¦A¦¸¦s¤J¡uB4B2¡v¡CB4B2 ¥Nªí¡u²´¡v³o­Ó¦r¡C±µ¤U¨Ó¦A°õ¦æ¡uG¡v»P¡uD FFF0 L10¡v«ü¥O¡G

  -g [Enter]
  AX=BBBB  BX=012F  CX=003D  DX=0103  SP=FFF6  BP=0000  SI=0000  DI=0000
  DS=3ACB  ES=3ACB  SS=3ACB  CS=3ACB  IP=01D2   NV UP EI PL NZ NA PO NC
  3ACB:01D2 83C302         ADD    BX,+02                        ;BR1
  -d fff0 l10 [Enter]
  3ACB:FFF0  00 00 00 00 24 09 BB BB-B2 B4 AC 5C 24 00 00 00  R.K:41;;24,\$...

¸ò¤W¦¸¤@¼Ë¡AÆ[¹î¤W­±ªº SP »P°ïÅ|¡A»P«e¦¸ªº®t§O¬O SP ¤§­È¤S¤Ö¤G¡A°ïÅ|¤º¤S·s¼W¤@µ§¸ê®Æ¡ABBBB¡A³o¼Æ­È¥Nªí¡u»»¡v¡C¨ì¦¹¡A¤p¤ì°¸·Q©³¤U¥i¥H¤£¥²¦A°lÂܤF¡Aª½±µ¸õ¥X°j°é¤F§a¡H©Ò¥H¿é¤J¡uBC 1¡v²M°£²Ä¤@¸¹¤¤Â_ÂI¡AµM«á¿é¤J¡uG¡v«ü¥O¡A¦p¤U¡G

  -bc 1 [Enter]
  -g [Enter]
  AX=E0A8  BX=01A9  CX=0000  DX=0103  SP=FF7E  BP=0000  SI=0000  DI=0000
  DS=3ACB  ES=3ACB  SS=3ACB  CS=3ACB  IP=01D7   NV UP EI PL NZ NA PE NC
  3ACB:01D7 8BD4           MOV    DX,SP                         ;BR0

³o®É·|°õ¦æ¨ì²Ä¹s¸¹¤¤Â_ÂI°±¤U¨Ó¡AÅã¥Ü¼È¦s¾¹ªº¤º®e¡A¦p¤W­±¬õ¦r¡ASP ¤w¸gÅܦ¨ FF7E¡A¦A¹î¬Ý°ïÅ|¡G

  -d ff70 l90 [Enter]
  3ACB:FF70  00 00 00 00 CB 3A 00 00-D7 01 CB 3A B4 31 A8 E0  ....K:..W.K:41(`
  3ACB:FF80  BE D0 A4 F7 A4 BC A9 64-BE D0 A4 D2 A1 41 B1 49  >P$w$<)d>P$R!A1I
  3ACB:FF90  B9 E9 AA F8 A6 75 A9 5D-BF 4F A9 74 0D 0A BF F0  9i*x&u)]?O)t..?p
  3ACB:FFA0  A6 5E B1 48 B6 AD B5 4C-AD B5 B0 54 A1 41 A4 5B  &^1H6-5L-50T!A$[
  3ACB:FFB0  A7 4F C2 F7 A4 48 AA FD-B8 F4 B3 7E 0D 0A B8 D6  'OBw$H*}8t3~..8V
  3ACB:FFC0  C3 FD A9 4D A6 A8 C3 F8-A4 55 B5 A7 A1 41 B0 73  C})M&(Cx$U5'!A0s
  3ACB:FFD0  AA 4D A4 40 B0 75 A9 C8-AA C5 B3 FD 0D 0A AA BE  *M$@0u)H*E3}..*>
  3ACB:FFE0  A4 DF B4 58 A8 A3 B4 BF-A8 D3 A9 B9 A1 41 A4 F4  $_4X(#4?(S)9!A$t
  3ACB:FFF0  B9 6A A4 73 B1 E6 BB BB-B2 B4 AC 5C 24 00 00 00  9j$s1f;;24,\$...

¤W¤è¥Õ¦âªº³¡¤À´N¬O°ïÅ|ªº¤º®e¡C±µ¤U¨Óªºµ{¦¡´N¬O§â³o¨Ç¤º®e¦L¦b¿Ã¥ú¹õ¤W¡A§Ú­Ì¥i¥H§â³o¨Ç¤º®e·í¦¨¦r¦ê¡A©Ò¥H¥i¥H¥Î AH¡×9/INT 21H ªA°Èµ{¦¡±N¨ä¦L¥X¨Ó¡C¨Ï¥Î¦¹ªA°Èµ{¦¡®É¡ADX ¬°­n¦L¥Xªº¦r¦ê¦ì§}¡A¦¹¦ì§}¨ä¹ê´N¬O°ïÅ|³»¡A¦]¦¹¦b¦ì§} 01D7 ³B¡Aª½±µ±N DX ³]¬° SP ¤§­È§Y¥i¡A¦p¥k¹Ï©Ò¥Ü¡C

  -t [Enter]
  AX=E0A8  BX=01A9  CX=0000  DX=FF7E  SP=FF7E  BP=0000  SI=0000  DI=0000
  DS=3ACB  ES=3ACB  SS=3ACB  CS=3ACB  IP=01D9   NV UP EI PL NZ NA PE NC
  3ACB:01D9 B409           MOV    AH,09
  -t [Enter]
  AX=09A8  BX=01A9  CX=0000  DX=FF7E  SP=FF7E  BP=0000  SI=0000  DI=0000
  DS=3ACB  ES=3ACB  SS=3ACB  CS=3ACB  IP=01DB   NV UP EI PL NZ NA PE NC
  3ACB:01DB CD21           INT    21  ;Display String
  -t [Enter]
  ¨à¾Ð¤÷¤¼©d¾Ð¤Ò¡A±I¹éªø¦u©]¿O©t
  ¿ð¦^±H¶­µL­µ°T¡A¤[§OÂ÷¤Hªý¸ô³~
  ¸ÖÃý©M¦¨Ãø¤Uµ§¡A°sªM¤@°u©ÈªÅ³ý
  ª¾¤ß´X¨£´¿¨Ó©¹¡A¤ô¹j¤s±æ»»²´¬\AX=0924  BX=01A9  CX=0000  DX=FF7E  SP=FF7E  BP=0000  SI=0000  DI=0000
  DS=3ACB  ES=3ACB  SS=3ACB  CS=3ACB  IP=01DD   NV UP EI PL NZ NA PE NC
  3ACB:01DD CD20           INT    20
  -g [Enter]

  Program terminated normally (0)

³Ì«á¬O°õ¦æ INT 20H¡Aµ²§ôµ{¦¡¡C


µù¸Ñ

­Ê¤Ñ¤¤¤å¨t²Î

­Ê¤Ñ¤¤¤åªº¤º½X¬O±Ä¥Î BIG¡Ð5 ªº½s½X¤è¦¡¡A¨C­Ó¤¤¤å¦r¥Ñ¨â­Ó¦ì¤¸²Õ©Òºc¦¨¡A²Ä¤@­Ó¦ì¤¸²ÕºÙ¬°¡u°ª¦ì¤¸²Õ¡v¡A¦b 81H¡ã0FEH ªº½d³ò¤º¡A¦s©ñ¦b°O¾ÐÅéùØ«o¬O©ñ¦b§C¦ì§}³B¡F²Ä¤G­Ó¦ì¤¸²ÕºÙ¬°¡u§C¦ì¦ì¤¸²Õ¡v¡C¨ä½d³ò¦b 40H¡ã7EH ¤Î 0A1H¡ã0FEH¡A¦s©ñ¦b°O¾ÐÅéùØ«o¬O©ñ¦b°ª¦ì§}³B¡C

­Ê¤Ñ¤¤¤å¨t²Î³oºØ¦w±Æ¤è¦¡ºÙ¬°¤j§ÇºÝ ( big-endian )¡A©M IBM PC ¬Û®e¾÷ºØªº¦w±Æ¤è¦¡¤£¦P¡A³o¤@ÂI«D±`©_©Ç¡A¦ý«o¬O¨Æ¹ê¡C¨Ò¦p¦b MS-DOS 6.20 ­Ê¤Ñ¤¤¤å¨t²Î¤U¡A«ö¤U Ctrl¡ÐShift ¤Á´«¨ì¤º½X¿é¤J¡A¿é¤J¡uAC5C¡v´N·|¥X²{¡u¬\¡v¦r¡A¦p¤U¹Ï¡G

¤p¤ì°¸²q·Q¡A­Ê¤Ñ¤¤¤å·|¦w±Æ³o¼Ëªº±Æ¦C¤è¦¡¡AÀ³¸Ó¬O¦]¬°¥u­n§PÂ_²Ä¤@­Ó¦ì¤¸²Õ¤£¦b 81H¡ã0FEH ¤§¶¡¡A´N¬O­^¤å¦r¡C¹ï©ó­Ê¤Ñ¤¤¤å¨t²Î¦b§PÂ_¤@¦r¦ê¤¤ªº¦r¤¸¬O­^¤å¡AÁÙ¬O¤¤¤å¡A¸û¬°®e©ö¡C