¦b¼¶¼gµ{¦¡®É±`±`·|¹J¨ì¸ê®ÆÂಾ¡B¤ñ¸ûµ¥ª¬ªpµo¥Í¡Ax86 ®a±Úªº CPU ùئ³´XÓ«ü¥O¬O±Mªù³B²z¡u¦r¦ê¡vªº¡A¦b³oùةҿתº¦r¦ê¡A¬O«ü¦b°O¾ÐÅ餺³sÄòªº¦ì¤¸²Õ©Î¦r²Õ¡A¨Ã¤£¤@©w¬O ASCII ¦r¤¸¡A¤]¦³¥i¯à¬O¤@¬q¤G¶i¦ì¼Æ¡C³o¤@³¹ùØ¡A¤p¤ì°¸n½Í½Í x86 «ü¥Oùتº¦r¦ê³B²z«ü¥O¡A¥]§t·h²¾¡B¤ñ¸û¡B±½´y¡BÀx¦s¡B¸ü¤J¤ºØ«ü¥O¡C
°£¤F´£¨ì x86 ³B²z¦r¦êªº«ü¥O¤§¥~¡AµL¥iÁקKªº¡AÁÙ·|´£¨ì³Ì«á¤@ӰϬq¼È¦s¾¹¡AES ( extra segment register¡A¥i½¬°ÃB¥~°Ï¬q¼È¦s¾¹ )¡A¥H¤Î¨âÓ¯Á¤Þ¼È¦s¾¹¡ASI ( source index¡A¨Ó·½¯Á¤Þ¼È¦s¾¹ ) ©M DI ( destination index¡A¥Øªº¯Á¤Þ¼È¦s¾¹ )¡CSI »P DI ³o¨âӼȦs¾¹±`±`¥Î¨Ó·í°µ«ü¼Ð©Î¯Á¤Þ¨Ï¥Î¡A«ü¦V°O¾ÐÅ餤ªº¬YÓ¦ì§}¡A«Ý·|n´£¨ìªº MOVSB «ü¥O´N·|¥Î¨ì¡CSI »P DI ÁöµM¤]¥i¥H¥Î©ó¹Bºâ¡A¦ý¬O«Ü¤Ö°µ³o¼Ëªº¥Î³~¡C
°²¦pn§â°O¾ÐÅ餤ªº¦r¦ê·h²¾¨ì°O¾ÐÅ骺¥t¤@³B¡A¥i¥H¥Î MOVSB¡BMOVSW¡BMOVSD¡BMOVSQ¡A¬°¤F³æ¯Â¡A³oùØ¥u»¡ MOVSB¡BMOVSW¡A¨ä¾l«ü¥O¨£µù¤@¡CMOVSB ^¤åªº·N«ä¬O¡umove string byte¡v¡A·N«ä¬O·h²¾¤@Ӧ줸²Õªº·N«ä¡C»¡±o§ó²M·¡¤@ÂI¡A¬O§â°O¾ÐÅé¦ì§} DS:SI ©Ò«ü¦ì§}ªº¤@Ӧ줸²Õ·h²¾¨ì ES:DI ¦ì§}¤W¡AÁöµM»¡¬O·h²¾¡A¦ýì¨Ó¦b DS:SI ³Bªº¤º®e¤£ÅÜ¡A©Ò¥H¨ä¹ê¬O½Æ»s©Î«þ¨©¡C¤]¦]¬°¬O½Æ»s°O¾ÐÅ餺®e¡A¨Ã«D¹Bºâ¡A©Ò¥H MOVSB ¤£¼vÅTºX¼Ð¡C
MOVSB °£¤F·h²¾¥~¡AÁÙ·|¨Ï SI »P DI ÁÙ·|¦Û°ÊÅܦ¨¤U¤@Ӧ줸²Õªº¦ì§}¡C¤U¤@Ӧ줸²Õªº¦ì§}¡A¦³¥i¯à¬OÅý SI¡BDI ³£¼W¥[¤@¡A¤]¦³¥i¯à³£´î¤Ö¤@¡A³on¬Ý¤è¦VºX¼Ð ( direction flag ) ¨Ó¨M©w¡C°²¦p¤è¦VºX¼Ð¬°¹s¡A¨º»ò SI¡BDI ³£·|¼W¥[¤@¡F¤Ï¤§¡ASI¡BDI ³£´î¤Ö¤@¡C¦b·h²¾¤§«en¥ý³]©w©Î²M°£¤è¦VºX¼Ð¡A¥H¨M©w©¹°ª¦ì§}·h²¾ÁÙ¬O¦V§C¦ì§}·h²¾¡CDS:SI ©Ò«ü¦ì§}ªº¦r¦êºÙ¬°¨Ó·½¦r¦ê¡AES:DI «hºÙ¬°¥Øªº¦r¦ê¡C
CLD »P STD ³o¨âÓ x86 «ü¥Oªº»yªk¬O¡G
CLD STD
¥¦Ì¨S¦³¹Bºâ¤¸¡CCLD ¬O²M°£¤è¦VºX¼Ð ( clear direction flag ) ªº·N«ä¡A³oÓ«ü¥O·|Åý¤è¦VºX¼ÐÅܬ° 0¡A¥HP©ó¨C°õ¦æ¤@¦¸ MOVSB «ü¥O¡A¨Ï±o SI¡BDI ³£¼W¥[¤@¡A¤]´N¬O»¡¸ê®Æ©¹°ª¦ì§}³B·h²¾¡CSTD ¬O³]©w¤è¦VºX¼Ð ( set direction flag ) ªº·N«ä¡A³oÓ«ü¥O·|Åý¤è¦VºX¼ÐÅܬ° 1¡A¥HP©ó¨C°õ¦æ¤@¦¸ MOVSB «ü¥O¡A¨Ï±o SI¡BDI ³£´î¤Ö¤@¡A¤]´N¬O»¡¸ê®Æ©¹§C¦ì§}³B·h²¾¡C
©³¤U§Ų́Ӭݬݹê¨Ò¡G
C:\>c:\tools\symdeb [Enter] Microsoft (R) Symbolic Debug Utility Version 4.00 Copyright (C) Microsoft Corp 1984, 1985. All rights reserved. Processor is [80286] -a [Enter] 1530:0100 mov ax,f000 [Enter] 1530:0103 mov ds,ax [Enter] 1530:0105 mov si,fff5 [Enter] 1530:0108 movsb [Enter] 1530:0109 jmp 108 [Enter] 1530:010B [Enter] ¡÷µ²§ôµ{¦¡ -
¦b 1530:0100¡ã1530:0103 ¿é¤Jªºµ{¦¡¬O§â DS ³]¬° F000H¡A²Ä¤Q¤@³¹»¡¹L x86 CPU ¤£»{±o¡uMOV DS,F000¡v³o¼Ëªº«ü¥O¡A¦]¦¹¥u¯à¥ý§â F000 ¦s¤J AX ùØ¡A¦bÂǥѡuMOV DS,AX¡v«ü¥OÅý DS Åܦ¨ F000¡C±µ¤U¨Ó§â SI ³]¬° FFF5¡C¦]¦¹¥i¥H±oª¾¡A¨Ó·½¦r¦ê¬O¦b¦ì§} F000:FFF5 ³B¡A³oÓ¦ì§}©ÒÀx¦sªº¤KӦ줸²Õ¸ê®Æ¡A¨ä¹ê¬O BIOS ¥X¼t®Éªº¤é´Á¡C²{¦b°õ¦æ³o¤T±ø«ü¥O¡A¦p¤U¿é¤J¤TÓ¡ut¡v«ü¥O¡G
-t [Enter] AX=F000 BX=0000 CX=0000 DX=0000 SP=E9BF BP=0000 SI=0000 DI=0000 DS=1530 ES=1530 SS=1530 CS=1530 IP=0103 NV UP EI PL NZ NA PO NC 1530:0103 8ED8 MOV DS,AX -t [Enter] AX=F000 BX=0000 CX=0000 DX=0000 SP=E9BF BP=0000 SI=0000 DI=0000 DS=F000 ES=1530 SS=1530 CS=1530 IP=0105 NV UP EI PL NZ NA PO NC 1530:0105 BEF5FF MOV SI,FFF5 -t [Enter] AX=F000 BX=0000 CX=0000 DX=0000 SP=E9BF BP=0000 SI=FFF5 DI=0000 DS=F000 ES=1530 SS=1530 CS=1530 IP=0108 NV UP EI PL NZ NA PO NC 1530:0108 A4 MOVSB -
±µ¤U¨Ó´Nn°õ¦æ MOVSB ¤F¡A¦ý¬O¦A³o¤§«e¡A¥ý¨Ó¬Ý¤@¬Ý¨â¥óȱoª`·Nªº¨Æ¡C²Ä¤@¥ó¨Æ¬O¤W±¼Ð¥Ü¤ÑÂŦ⪺¡uUP¡v¡A³o¬O DEBUG/SYMDEB µ¥°£¿ù¾¹ªí¥ÜºX¼Ð¼È¦s¾¹¬°¹s®Éªº¼Ë¤l¡AY¬°¡uDN¡v«hªí¥ÜºX¼Ð¼È¦s¾¹¬°¤@¡C³oùؤè¦VºX¼Ð³]¬°¡uUP¡v¡Aªí¥Ü MOVSB ·|§â¦r¦ê©¹°ª¦ì§}·h²¾¡C²Ä¤G¥ó¨Æ¬OÀˬd DS:SI »P ES:DI ©Ò«ü¦ì§}ªºì¥ý¤º®e¡A¿é¤J¤U±¨â±ø«ü¥O¡G
-d ds:fff0 l10 [Enter] F000:FFF0 EA 5B E0 00 F0 30 32 2F-32 32 2F 30 36 00 FC 00 j[`.p02/22/06.|. -d es:di l10 [Enter] 1530:0000 CD 20 C0 9F 00 9A BF E8-80 F1 8E 09 35 0C 2B 0A M @...?h.q..5.+. -
¤W±¥Î¬õ¦r¼Ð¥Ü°_¨Óªº¬O¨Ó·½¦r¦ê¡A¥Î¥Õ¦â¼Ð°_¨Óªº¬O¥Øªº¦r¦ê¡C¥i¥H²q´ú¡A¦pªG°õ¦æ§¹¤K¦¸ MOVSB «á¡A¥H¥Õ¦â¦rªí¥Üªº¥Øªº¦r¦ê¤º®e·|Åܦ¨¸ò¨Ó·½¦r¦ê¤@¼Ë¡C²{¦b¿é¤J¡ut¡v«ü¥O¡ASYMDEB ´N·|Åý CPU °õ¦æ²Ä¤@¦¸ªº MOVSB «ü¥O¡G
-t [Enter] AX=F000 BX=0000 CX=0000 DX=0000 SP=E9BF BP=0000 SI=FFF6 DI=0001 DS=F000 ES=1530 SS=1530 CS=1530 IP=0109 NV UP EI PL NZ NA PO NC 1530:0109 EBFD JMP 0108 -
¬Ý¨ì¤W±ªº SI »P DI¡A¦b°õ¦æ§¹ MOVSB «ü¥O«á¡A¥¦ÌǦ۰ʳ£¼W¥[¤@¤F ( ¨£¤W±¤ÑÂŦ⪺¦r )¡C¦A¨Ó¬Ý¬Ý³o¨âÓ¦r¦ê¡A¿é¤J©³¤U¨â±ø SYMDEB «ü¥O¡G
-d ds:fff0 l10 [Enter] F000:FFF0 EA 5B E0 00 F0 30 32 2F-32 32 2F 30 36 00 FC 00 j[`.p02/22/06.|. -d es:di l10 [Enter] 1530:0000 30 20 C0 9F 00 9A BF E8-80 F1 8E 09 35 0C 2B 0A 0 @...?h.q..5.+. -
¦p¤W±©ÒÅã¥Üªº¡ACPU ªº MOVSB «ü¥OÅý 30 ( ¬õ¦r ) ·h²¾¨ì 1530:0000 ¦ì§}³Bªº¤ÑÂŦâ¦r¡A¦Óì¥ýªº¤º®e ( CD ) «h³QÂмg«á®ø¥¢¤£¨£¡C±µ¤U¨Ó°õ¦æ¨â¦¸¡ut¡v«ü¥O¡A¦p¤U±¡G
-t [Enter] AX=F000 BX=0000 CX=0000 DX=0000 SP=E9BF BP=0000 SI=FFF6 DI=0001 DS=F000 ES=1530 SS=1530 CS=1530 IP=0108 NV UP EI PL NZ NA PO NC 1530:0108 A4 MOVSB -t [Enter] AX=F000 BX=0000 CX=0000 DX=0000 SP=E9BF BP=0000 SI=FFF7 DI=0002 DS=F000 ES=1530 SS=1530 CS=1530 IP=0109 NV UP EI PL NZ NA PO NC 1530:0109 EBFD JMP 0108 -d es:0 l10 [Enter] 1530:0000 30 32 C0 9F 00 9A BF E8-80 F1 8E 09 35 0C 2B 0A 02@...?h.q..5.+. -d ds:fff0 l10 [Enter] F000:FFF0 EA 5B E0 00 F0 30 32 2F-32 32 2F 30 36 00 FC 00 j[`.p02/22/06.|. -
±q¥Î a «ü¥O¿é¤Jµ{¦¡¨ì¦¹¬°¤î¡AÁ`¦@°õ¦æ¤F¨â¦¸ MOVSB «ü¥O¡A¦]¦¹¤]·|·h²¾¨âӦ줸²Õªº¸ê®Æ¨ì ES:DI ©Ò«ü¦ì§} ( ¥Õ¦â¦r )¡A¦P®É SI¡BDI ³£¼W¥[ 2 ( ¤ÑÂŦ⪺¦r )¡A«ü¦V¤U¤@Ón³B²zªº¦ì§}¡C¦pªGn§â¾ãÓ¤é´Á¦r¦ê·h¹L¥h¡A¤£¯à¹³¤W±µ{¦¡¨Ï¥Î JMP «ü¥O¡A³o¼Ë·|³y¦¨²{´`Àôªº°j°é¡AÅý¹q¸£·í±¼¡AÀ³·í°t¦X REP «ü¥O¡C
³æ¿Wªº MOVSB «ü¥O¤@¦¸¥u¯à·h°Ê¤@Ӧ줸²Õªº¸ê®Æ¡AµM¦Ó¤@Ó¦r¦ê³q±`¦³¼ÆӦ줸²Õ¡A¦pªGn³sÄò·h²¾³\¦h¦ì¤¸²Õ¡A´N¥²¶·»P REP «ü¥O·f°t¡CREP ¬OӫܯS§Oªº«ü¥O¡A¥¦¥i¥H¸ò»P³B²z¦r¦ê¬ÛÃöªº«ü¥O·f°t¤@°_¨Ï¥Î¡A³o¼Ë´N·|¨Ï«á±ªº«ü¥O«½Æ°õ¦æ¡C«½Æªº¦¸¼Æ¥²¶·¥ý¦bp¼Æ¼È¦s¾¹ ( p¼Æ¼È¦s¾¹´N¬O CX )¤¤³]©w¦n¡C¨Ò¦p¡G
mov cx,8 rep movsb
°õ¦æ¡uREP MOVSB¡v®É¡A·|¥ý§â CX »P¹s¶i¦æ¤ñ¸û¡F¦pªG CX µ¥©ó¹s¡A«h¤£·h²¾¸ê®Æ¦Ó°õ¦æ¡uREP MOVSB¡vªº¤U¤@±ø«ü¥O¡C§_«h¡ACX ´î¤@¡AµM«á°õ¦æ MOVSB ¦r¦ê«ü¥O¡F±µ¤U¨Ó·|¤@ª½«½Æ¤W±¨BÆJ¡Aª½¨ì CX Åܬ°¹s¤~°±¤î¡AµM«á°õ¦æ¤U¤@±ø«ü¥O¡C
µ²½×¡Gn·h²¾¤@Ó¦r¦ê ( ©Î»¡½Æ»s¤@Ó¦r¦ê )¡An¨Æ¥ý©ó DS:SI ³]©w¦n¨Ó·½¦r¦êªº¦ì§}¡A©ó ES:DI ³]©w¦n¥Øªº¦r¦êªº¦ì§}¡A¦b CX ³]©w¦nn·h²¾´XӦ줸²Õ¡A³Ì«á°õ¦æ¡uREP MOVSB¡v¡C¬Ý°_¨Ó«Ü¦h¨BÆJ¡A¦ý³]©w¦n¤§«á¡A¯à·h²¾«Üªøªº¦r¦ê¡A¦Ó¥B°õ¦æ³t«×«Ü§Ö¡C³Ì«á¡AMOVSB »P REP MOVSB ³£¤£¼vÅTºX¼Ð¡C
MOVSW «ü¥Oªº¥Îªk´X¥G©M MOVSB ¤@¼Ë¡A®t§O¦b©ó¨C·h²¾¤@¦¸¬O·h²¾¤@Ó¦r²Õ¡A¦Ó¥B¨Ï SI¡BDI ¼W´î¤G¡A¥ç§Y¼W´î¨âӦ줸²Õªº¦ì§}¡A¥H«ü¦V¤U¤@Ó¦ì§}¡C
¤p¤ì°¸n¤¶²Ðªº²Ä¤GÓ¦r¦ê³B²z«ü¥O¬O¤ñ¸û«ü¥O¡ACMPSB »P CMPSW ( ¨ä¹ê¤]¦³ CMPSD¡BCMPSQ¡A½Ð°Ñ¦Òµù¤@ )¡CCMPSB ¬O compare string byte ªºÁY¼g¡A·N«ä¬O¤@¦¸¤ñ¸û¤@Ӧ줸²Õ¡F¦Ó CMPSW «h¬O compare string word ªºÁY¼g¡A·N«ä¬O¤@¦¸¤ñ¸û¤@Ó¦r²Õ¡C¶È³æ³æ¥Î CMPSB ©Î CMPSW ªº±¡ªp¸û¤Ö¡A³q±`·|¦b CMPSB ©Î CMPSW ªº«e¥[¤W REPE¡A³o¼Ë¥i¥H¤ñ¸û¦hӦ줸²Õ©Î¦r²Õ¡CREPE ¬O repeat while equal ªº·N«ä¡A¥ç§Y¦pªG¬Ûµ¥´NÄ~Äò¤ñ¸û¡AREPE ©M REPZ ( ªí¥Ü repeat while zero¡A¦pªG¹sȺX¼Ð¬° ZR¡A«hÄ~Äò ) ¬O¬Û¦Pªº·N«äªº¡C
¥Î REPE CMPSB ©Î REPE CMPSW «ü¥O¤ñ¸ûªº¨âÓ¦r¦ê®É¡A³o¨âÓ¦r¦ê¤À§O©ñ¦b DS:SI »P ES:DI ©Ò«üªº¦ì§}¡A¤ñ¸û¦¸¼Æ«h©ñ¦b CX¡C¦pªG CX ¬°¹s¡A¨º»ò´N¤£·|¶i¦æ¤ñ¸û¦Ó°õ¦æ¤U¤@¹D«ü¥O¡F¦pªG CX ¤£¬°¹s¡A¨º»ò¨C¤ñ¸û¤@¦¸ CX ´î¤@¡A¦P®É SI »P DI ·|¦Û°Ê«ü¦V¤U¤@Ón¤ñ¸ûªº¦ì§}¡C¦pªG¬O REPE CMPSB ªí¥Ü¤@Ӧ줸²Õ¤@Ӧ줸²Õ¤ñ¸û¡A¬G SI¡BDI ·|¦Û°Ê¼W¥[¤@©Î´î¤Ö¤@¡F¦pªG¬O REPE CMPSW¡A«h¨C¦¸¤ñ¸û¤@Ó¦r²Õ¡ASI¡BDI ·|¼W¥[¤G©Î´î¤Ö¤G¡C
SI¡BDI ¬O¼W¥[ÁÙ¬O´î¤Ö¡Aµø¤è¦VºX¼Ð¨M©w¡C¦pªG¤è¦VºX¼Ð¬°¹sªí¥Ü¦V°ª¦ì§}¤ñ¸û¡ASI¡BDI ·|³v¨B¼W¥[¡F¤Ï¤§«h¦V§C¦ì§}¤ñ¸û¡ASI¡BDI ·|³v¨B´î¤Ö¡C¨ì³oùج°¤î¡AREPE CMPSB/REPE CMPSW ªº¥Îªk©M REP MOVSB/REP MOVSW ´X¥G¬Û¦P¡C
¨º»ò¡An¦p¦ó¤~ª¾¹D¨âÓ¦r¦ê¬Ûµ¥¡H¨ä¹ê«Ü²³æ¡A¥unÀˬd¹sȺX¼Ð§Y¥i¡C¦pªG¹sȺX¼Ð³Q²M°£ ( ¦b DEBUG/SYMDEB ¤¤Åã¥Ü NZ )¡Aªí¥Ü¨â¦r¦ê¤£¦P¡F¦pªG¹sȺX¼Ð³Q³]©w ( ¦b DEBUG/SYMDEB ¤¤Åã¥Ü ZR )¡Aªí¥Ü¨â¦r¦ê¬Û¦P¡C±µ¤U¨Ó´N¥i¥H»P JE ©Î JNE °t¦X¡A¤À§O¸õ¦Ü¦r¦ê¬Ûµ¥©Î¦r¦ê¤£¬Ûµ¥ªº¦a¤è°õ¦æ¡C¦p¤U¡G
repe cmpsb ;¤ñ¸û¦r¦ê je identical ;Y¨â¦r¦ê¬Û¦P¡A¸õ¦Üidentical³B
¦^·Q¡uREPE CMPSB/REPE CMPSW¡vªº·N¸q¬O¡AY¬Ûµ¥´NÄ~Äò¤ñ¸û¤UӦ줸²Õ©Î¤UÓ¦r²Õ¡F¨º»ò¡A¤Ï¹L¨Ó»¡¡AY¤£¬Ûµ¥´N·|°±¤î¤ñ¸û¡C¤]´N¬O»¡¡uREPE CMPSB/REPE CMPSW¡v¦b¤ñ¸û¹Lµ{¤¤¡A¥un¨â¦r¦ê¬YÓ¦a¤è¤£¦P¡A´N°±¤î¤ñ¸û¡A¦P®É²M°£¹sȺX¼Ð ( §Y NZ )¡C³o¸ò²Ä¤T³¹ªº CMP ¤@¼Ë¡C
¥k¹Ïªº¨Ò¤l¬O¤ñ¸û¨âÓ¦r¦ê¤£¦P®É¡ASI¡BDI¡BCX ©Ò¥Nªíªº·N¸q¡C¦pªG¤@¶}©l¡A¨Ó·½¦r¦ê¦b DS:0200 ³B ( ¥H¥Õ¦â¤p¦r¼Ð¥Ü )¡A¥Øªº¦r¦ê¦b ES:0210 ³B¡A¦@n¤ñ¸û 0EH ¦¸ ( ¥ç§Y 14 Ӧ줸²Õ )¡A¦¹¼ÆȦs©ó CX¡C°õ¦æ REPE CMPSB¡A·í¤ñ¸û¨ì¦ì§} 205H »P 215H ®É¡Aµo²{¤£¦P¡ACPU ·|§â¹sȺX¼Ð³]¬°¡uNZ¡v¡A¦ýnª`·Nªº¬O CMPSB ·|Åý SI¡BDI «ü¦V¤U¤@Ó¦ì§}¡A¦]¦¹¡A¦¹®É SI¡BDI ¤w¸g¤£¬O²Ä¤@Ó¤£¦Pªº¦ì¤¸²Õ©Ò¦b¦ì§}¡A¦Ó¬O¤U¤@Ó¦ì§}¤F¡C·í¤ñ¸û¨ì 205H »P 215H ®É¡AREPE ³£·|Åý CX ´î¤@¡A¬G CX ÁٳѤU¤K¦¸¥¼¤ñ¸û¡C
Á`µ²¤@¤U¡GREPE CMPSB ©Î REPE CMPSW ¤ñ¸û¦b DS:SI »P ES:DI ªº¨âÓ¦r¦ê¬O§_¬Û¦P¡ACX ¥Nªín¤ñ¸ûªº¦¸¼Æ¡AY CX ¬°¹s«h¸õ¹L¤ñ¸û¦Ó°õ¦æ¤U¤@¹D«ü¥O¡C¨C¤ñ¸û¤@¦¸¡ASI »P DI ·|¦Û°Ê¼W´î¡A¥H«ü¦V¤U¤@Ó¤ñ¸ûªº¦ì§}¡A¦P®É CX ´î¤@¡C·í CX Åܬ°¹s©Î¤ñ¸û¨ì¨â¦r¦ê¤£¦P¤§³B´N°±¤î REPE CMPSB ©Î REPE CMPSW¡C¦pªGµ{¦¡n±oª¾¦bþÓ¦ì§}¶}©l¡A¨â¦r¦ê¤£¬Û¦P¡A¥i¥H¥Ñ SI¡BDI ¨Ó§PÂ_¡A¦ý¬On½Õ¾ã¡C¦P¼Ë¤]¥i¥H¥Ñ CX ¨Ó§PÂ_¡A¦ý¤]¶·½Õ¾ã¡C
¤ñ¸û¦r¦ê³Ì±`¨£ªº¥Î³~¬O·j´M¡C©³¤U¤p¤ì°¸¥Ü½d¤@Ó¨Ò¤l¡ASEARCH.EXE¡A³oÓµ{¦¡¥i¥HÅý¨Ï¥ÎªÌ¿é¤J³Ì¦h¤CÓ¤¤¤å¦rªº¥y¤l¡Aµ{¦¡¥H³o¥y¤l·j´Mð´Â¸Ö¤H¥Õ©~©öªº¡mµ\µ]¦æ¡n¤¤¡A¬O§_¦³¦¹¥y¤l¡C
°õ¦æ SEARCH.EXE ¥²¶·¦bʤѤ¤¤å¤U¤~¯à¬Ý¨£¤¤¤å¦r¡A§_«h¬O¶Ã½X¡C±ý¿é¤J¤¤¤å¡An¥ý±¾¤Wª`µ¿é¤Jªkªº¸ê®Æ¡A°õ¦æ¡uC:\ET3\ETINMD /PN=C:\ET3\PHONETIC.TAB¡v¡AµM«á¥i¥H«ö¡uCtrl¡ÐShift¡v¤Á´«^¼Æ»Pª`µ¿é¤J¡C°õ¦æµ²ªG¦p¤U¹Ï¡G
SEARCH.ASM §¹¾ãªºµ{¦¡½X¦p¤U¡A±Nµ{¦¡½X¦s¦¨ SEARCH.ASM ¯Â¤å¦rÀÉ¡A¨Ì¤W¹Ï²Ä¤@¦æ¡uml search.asm¡v²ÕĶ§Y¥i±o SEARCH.EXE¡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 26 27 28
29 30 31 32
33 34 35 36
37 38 39 40
41 42 43 44
45 46 47 48
49 50 51 52
53 54 55 56
57 58 59 60
61 62 63 64
65 66 67 68
69 70 71 72
73 74 75 76
77 78 79 80
81 82 83 84
85 86 87 88
89 90 91 92
93 94 95 96
97 98 |
.MODEL SMALL,C
.386
;*******************************************************************************
mystack SEGMENT STACK
DB 256 DUP (?)
mystack ENDS
;*******************************************************************************
mydata SEGMENT
article DB "¼ñ¶§¦¿ÀY©]°e«È·¬¸²ýªá¬î·æ·æ¥D¤H¤U°¨«È¦b²îÁ|°s±ý¶¼µLºÞ©¶"
DB "¾K¤£¦¨ÅwºG±N§O§O®É¯í¯í¦¿®û¤ë©¿»D¤ô¤Wµ\µ]Án¥D¤H§ÑÂk«È¤£µo"
DB "´MÁnîî°Ý¼uªÌ½Öµ\µ]Án°±±ý»y¿ð²¾²î¬ÛªñÁܬۨ£²K°s°j¿O«¶}®b"
DB "¤d©I¸U³ê©l¥X¨ÓµS©êµ\µ]¥b¾B±Âà¶b¼·©¶¤T¨âÁn¥¼¦¨¦±½Õ¥ý¦³±¡"
DB "©¶©¶±»§íÁnÁn«ä¦ü¶D¥Í¥¤£±o§Ó§C¬Ü«H¤âÄòÄò¼u»¡ºÉ¤ß¤¤µL¨Æ"
DB "»´ÃlºC¼¿©Ù´_¬Dªì¬°ÀO»n«áºñ¸y¤j©¶¹Ë¹Ë¦p«æ«B¤p©¶¤Á¤Á¦p¨p»y"
DB "¹Ë¹Ë¤Á¤Á¿ùÂø¼u¤j¯]¤p¯]¸¨¥É½L¶¡ÃöÅa»yªá©³·Æ«Õ«|¬u¬y¤ô¤UÅy"
DB "¤ô¬u§NÀß©¶¾®µ´¾®µ´¤£³qÁn¼È·²§O¦³«Õ·Tîî«ë¥Í¦¹®ÉµLÁn³Ó¦³Án"
DB "»È²~¥E¯}¤ô¼ß°nÅKÃM¬ð¥X¤MÂò»ï¦±²×¦¬¼··í¤ßµe¥|©¶¤@Án¦pµõ©"
DB "ªF²î¦è¯é®¨µL¨¥±©¨£¦¿¤ß¬î¤ë¥Õ¨H§u©ñ¼·´¡©¶¤¤¾ã¹y¦ç»n°_ÀÄ®e"
DB "¦Û¨¥¥»¬O¨Ê«°¤k®a¦b½¼Á°³®¤U¦í¤Q¤T¾Ç±oµ\µ]¦¨¦WÄݱЧ{²Ä¤@³¡"
DB "¦±½}´¿±Ðµ½¤~ªA§©¦¨¨C³Q¬î®Q§ª¤³®¦~¤Öª§ÄñÀY¤@¦±¬õß`¤£ª¾¼Æ"
DB "¹fÀY¶³¿{À»¸`¸H¦å¦âù¸È½°s¦Ã¤µ¦~Åw¯º´_©ú¦~¬î¤ë¬K·µ¥¶¢«×"
DB "§Ì¨«±qxªü«¼¦º¼Ç¥h´Â¨ÓÃC¦â¬Gªù«e§N¸¨¨®°¨µ}¦Ñ¤j¶ù§@°Ó¤H°ü"
DB "°Ó¤H«§Q»´§OÂ÷«e¤ë¯B±ç¶R¯ù¥h¥h¨Ó¦¿¤f¦uªÅ²îëвî©ú¤ë¦¿¤ô´H"
DB "©]²`©¿¹Ú¤Ö¦~¨Æ¹Ú³Ú§©²\¬õÁñ¤z§Ú»Dµ\µ]¤w¼Û®§¤S»D¦¹»y«®A®A"
DB "¦P¬O¤Ñ²P²_¸¨¤H¬Û³{¦ó¥²´¿¬ÛÃѧڱq¥h¦~Ãã«Ò¨ÊÂÖ©~ª×¯f¼ñ¶§«°"
DB "¼ñ¶§¦a»÷µLµ¼Ö²×·³¤£»Dµ·¦ËÁn¦íªñÚK¦¿¦a©³·Ã¶ÀĪW¦Ë¶¦v¥Í"
DB "¨ä¶¡¥¹¼Ç»D¦óª«§ùÃY³Ú¦å·á«s»ï¬K¦¿ªá´Â¬î¤ë©]©¹©¹¨ú°sÁÙ¿W¶É"
DB "°ZµL¤sºq»P§ø²Ã¹Ã°×¼JÐõÃø¬°Å¥¤µ©]»D§gµ\µ]»y¦pÅ¥¥P¼Ö¦Õ¼È©ú"
DB "²öÃã§ó§¤¼u¤@¦±¬°§g½§@µ\µ]¦æ·P§Ú¦¹¨¥¨}¤[¥ß«o§¤«P©¶©¶Âà«æ"
DB "²Y²Y¤£¦ü¦V«eÁnº¡®y«»D¬Ò±»ª_®y¤¤ª_¤U½Ö³Ì¦h¦¿¦{¥q°¨«Cm·Ã"
msg1 DB "¦¹µ{¦¡·|·j´M¥Õ©~©öµ\µ]¦æ¬O§_¦³¬Y¥y¤å¦r¡A",
0dh,0ah,"¿é¤J§An·j´Mªº¤å¦r(³Ì¦h¤CÓ¦r)¡G$"
msg2 DB 0dh,0ah,"¨S§äµÛ¡C$"
msg3 DB 0dh,0ah,"§äµÛ¤F¡I$"
msg4 DB 0dh,0ah,"¨S¿é¤J¤å¦r¡C$"
buffer DB 15
input DB ? ;n·j´M¦r¦êªºªø«×(³æ¦ì¬O¦ì¤¸²Õ)
sch_str DB 15 DUP (?) ;n·j´Mªº¦r¦ê
exit_c DB ? ;°h¥X½X¡C0¡G¨S§ä¨ì¡C1¡G¦³§ä¨ì¡C2¡G¨Ï¥ÎªÌ¨S¿é¤J¦r
mydata ENDS
;*******************************************************************************
program SEGMENT
ASSUME cs:program,ds:mydata,es:mydata
;-------------------------------------------------------------------------------
main PROC
mov ax,mydata ;AX¡×¸ê®Æ¬qªº°Ï¬q¦ì§}
mov ds,ax ;§âDS³]¬°¸ê®Æ°Ï¬q
mov es,ax ;§âES³]¬°©MDS¦P¤@°Ï¬q
;¦L¥X´£¥Ü¡u§A¿é¤Jªº¤å¦r(³Ì¦h¤CÓ¦r)¡G¡v¡A¨ÃÅý¨Ï¥ÎªÌ¿é¤J¤@¦r¦ê
mov ah,9
mov dx,OFFSET msg1
int 21h ;¦L¥X´£¥Ü¤å¦r
mov ah,0ah
mov dx,OFFSET buffer
int 21h ;Åý¨Ï¥ÎªÌ¿é¤Jn·j´Mªº¦r¦ê
;³]©w¤è¦VºX¼Ð¡Bn·j´Mªº¦r¦êªø«×¡B·j´M¦¸¼Æ
cld ;©¹°ª¦ì§}¤è¦V¤ñ¸û
mov dx,OFFSET msg1-OFFSET article
movzx cx,input ;CX¡×n·j´Mªº¦r¦êªø«×(³æ¦ì¬O¦ì¤¸²Õ)
sub dx,cx
inc dx ;DX¡×·j´M¦¸¼Æ¡×¤å³¹ªø«×¡Ðn·j´M±o¦r¦êªø«×¡Ï1
lea bx,article ;BX¡×articleªº¦ì§}
or cx,cx ;ÀˬdCX¬O§_¬°¹s
jnz search
mov dx,OFFSET msg4 ;YCX¡×0¡Aªí¥Ü¨Ï¥ÎªÌ¥¼¿é¤J¦r¦ê
mov exit_c,2
jmp short print
;¶}©l·j´M
;BX¡G«ü¦Vµ\µ]¦æ¤º®e¦ì§}¡A¨C¦¸·j´M®É·|©¹°ª¦ì§}»¼¼W
;DI¡G¨C¦¸·j´M®É¡A«ü¦Vµ\µ]¦æ¤¤·í«en·j´Mªº¦ì§}¡A¥ÑBX¨ú±o¦¹¦ì§}
;SI¡G¨C¦¸·j´M®É¡A«ü¦V¨Ï¥ÎªÌ¿é¤Jn·j´Mªº¦r¦ê¦ì§}
;CX¡G¨C¦¸·j´M®Én¤ñ¸û¦h¤ÖӦ줸²Õ
;DX¡G·j´M¦¸¼Æ
search: mov di,bx ;¨C¦¸·j´M¶}©l³B¡A³]©wDI¬°µ\µ]¦æ¤¤¡A¦¹¦¸·j´Mªº¦ì§}
mov si,OFFSET sch_str
movzx cx,input ;¨Ï¥ÎªÌ¿é¤J¦r¦êªºªø«×(³æ¦ì¬O¦ì¤¸²Õ)
repe cmpsb ;¶}©l¦¹¦¸·j´Mªº¤ñ¸û
jz match ;YZR¡Aªí¥Ü§äµÛ¤F¡A¸õ¦Ümatch
inc bx ;¨ÏBX¼W¥[¤@¡A«ü¦V¤U¦¸·j´Mµ\µ]¦æ¤º®eªº¦ì§}
dec dx ;·j´M¦¸¼Æ´î¤@
jnz search ;YDX¤£¬°¹s¡A¶i¦æ¤U¦¸·j´M¡A¸õ¦Üsearch
mov exit_c,0 ;YDX¬°¹s¡Aªí¥Ü¤w±Nµ\µ]¦æ³£·j´M¹L¤F¡A¤´§ä¤£µÛ
mov dx,OFFSET msg2
jmp print
match: mov exit_c,1
mov dx,OFFSET msg3
print: mov ah,9
int 21h ;¦L¥X·j´Mµ²ªG
.EXIT exit_c
main ENDP
;-------------------------------------------------------------------------------
program ENDS
;*******************************************************************************
END main
|
¤p¤ì°¸§â SEARCH.EXE ªº¸ê®Æ°Ï¬q»PÃB¥~°Ï¬q³]¦b¦P¤@°Ï¬q¡A³o¼Ëªº¦n³B¬O©Ò¦³ªºÅܼơB¤ñ¸û®Éªº¨Ó·½¦r¦ê»P¥Øªº¦r¦ê¡A¥þ³£¦b¦P¤@ӰϬq¤º¡A´N¤£¥²¾á¤ßnÂà´«°Ï¬qªº°ÝÃD¡CnÅý¸ê®Æ°Ï¬q»PÃB¥~°Ï¬q³£¦b¦P¤@°Ï¬q¡Aº¥ýn¥Î ASSUME °²«ü¥O§i¶D²ÕĶ¾¹¡A¨£µ{¦¡²Ä 43 ¦æ¡CµM«áÁÙn¨Ï DS¡BES ³]¬° mydata °Ï¬q¡A¨£µ{¦¡²Ä 46¡ã48 ¦æ¡C
¤p¤ì°¸¥Î AH¡×0AH/INT 21H Áä½L½w½Ä°Ï¨Ó¿é¤Jn·j´Mªº¦r¦ê¡A°Ñ¨£²Ä¤T³¹¡C½w½Ä°Ï³]¦b buffer ¶}©lªº 17 Ӧ줸²Õ¡A¨º»ò¡A²Ä¤@Ӧ줸²Õn³]¬°¦h¤Ö©O¡H¦]¬°µ\µ]¦æ¬O¤@º¤C¨¥¥j¸Ö¡A¤@¥y¤C¦r¡A¦]¦¹¤p¤ì°¸¤]³]©w¨Ï¥ÎªÌ©Ò·j´Mªº¦r¦ê¤£¥i¶W¹L¤CÓ¤¤¤å¦r¡C¤@Ó¤¤¤å¦r»Ý¥Î¨âӦ줸²Õªí¥Ü¡A¦A¥]§t¿é¤J§¹²¦ªº Enter Áä©Ò¥Nªíªº 0DH¡A¦@ 15 Ӧ줸²Õ¡C¥Ñ¥H¤W¨Ó¬Ý¡A½w½Ä°Ïªº²Ä¤@Ӧ줸²ÕÀ³¬° 15¡C²Ä¤GӦ줸²Õ¬O¨Ï¥ÎªÌ©Ò¿é¤Jªº¦r¦êªø«×¡A¦ý¤£¥]§t Enter Áä¡A¥H input ¬°¨äÅܼƦW¡Ainput ¦b¨Ï¥ÎªÌ¿é¤J§¹²¦«á¡A¥Ñ DOS ¶ñ¤J¦Ó²{¦b¤£ª¾¼ÆȬ°¦ó¡A¬G¥H¡u?¡vªí¥Ü¡C±µ¤U¨Ó¬°¦r¦ê¦s©ñ³B¡A¦ýn¥[¤W Enter Áä¡A¥B¤W¤£ª¾¨Ï¥ÎªÌ·|¿é¤J¤°»ò¸ê®Æ¡A¬G¦³ 15 Ó¥¼ªì©lªº¦ì¤¸²Õ¡C¦]¦¹µ{¦¡²Ä 36¡ã38 ¦æªºµ{¦¡¬°¡G
buffer DB 15 input DB ? ;n·j´M¦r¦êªºªø«×(³æ¦ì¬O¦ì¤¸²Õ) sch_str DB 15 DUP (?) ;n·j´Mªº¦r¦ê
¤p¤ì°¸·|³o¼Ë³]©w½w½Ä°Ï¡A¥þ¬O¦]¬° AH¡×0AH/INT 21H ªA°Èµ{¦¡´N³o¼Ë³W©w¦Ó¥B«á±³£n¥Î¨ì³o¨ÇÅܼơC°²¦p¨Ï¥ÎªÌ¿é¤J¡u¤»®c¯»ÂLµLÃC¦â¡v§@¬°·j´Mªº¥y¤l¡A¨º»ò input ·|Åܦ¨ 0EH¡Asch_str ¦r¦ê·|Åܦ¨¡uA4 BB AE 63 AF BB C2 4C B5 4C C3 43 A6 E2 0D¡v¡A¡uA4BB¡v¬O¡u¤»¡v¡B¡uAE63¡v¬O¡u®c¡v¡K¡K¡A³Ì«áªº¡u0D¡v¬O Enter Áä¡C
¿é¤Jn·j´Mªº¦r¦ê«á¡A´N¶i¤Jµ{¦¡®Ö¤ß³¡¥÷¤F¡C³o®ÉÔ¡ABX «ü¦Vµ\µ]¦æªº²Ä¤@Ӧ줸²Õ¡ABX ·|±qµ\µ]¦æªº²Ä¤@Ӧ줸²Õ³v¨B¼W¤@¡ABX ¨C¼W¥[¤@´N¬O¤@¦¸·j´M¡A¨C¦¸·j´M³£·|°µ¦r¦êªº¤ñ¸û¡A¨C¦¸¤ñ¸û«e¡A³£n³]©w¦n¤U±¼È¦s¾¹¡G
¡@¡@①§â SI «ü¦V¨Ï¥ÎªÌ¿é¤Jªº¦r¦ê¡A§Y sch_str ( ²Ä 78 ¦æ )¡B
¡@¡@②§â DI ³]¦¨¬° BX ( ²Ä 79 ¦æ )¡B
¡@¡@③CX ¬°¨Ï¥ÎªÌ¿é¤Jªº¦ì¤¸²ÕӼơA§Y input ÅÜ¼Æ ( ²Ä 80 ¦æ )¡A
²Ä¤@¦¸·j´M¡A¤ñ¸û¡u¤»®c¯»ÂLµLÃC¦â¡v©M¡u¼ñ¶§±NÀY©]°e«È¡v¡A«Ü©úÅã³o¨â¥y§¹¥þ¤£¦P¡A¬G³o¦¸·j´M CMPSB ¥u·|¤ñ¸û¤@Ӧ줸²Õ´N°±¤î¡A¦b³o¹Lµ{¤¤¡ASI ·|¥Ñ¡u¤»¡vªº²Ä¤@Ӧ줸²Õ¼W¦Ü¡u¤»¡vªº²Ä¤GӦ줸²Õ¡ADI ¤]·|¦P¨B¥Ñ¡u¼ñ¡vªº²Ä¤@Ӧ줸²Õ¨ì¡u¼ñ¡vªº²Ä¤GӦ줸²Õ¡A¦ý BX ¤´¤£ÅÜ¡A¨£¤U¹Ï
CMPSB °õ¦æ§¹¤§«á¡AÀˬd¹sȺX¼Ð¡AY³]©w¡A´N¸õ¨ì match ³B ( µ{¦¡²Ä 82 ¦æªº jz match¡v)¡Aªí¥Ü§ä¨ì¨Ï¥ÎªÌ¿é¤Jªº¦r¦ê¤F¡C¦ý¦¹³B¨Ã¤£·|µo¥Í¸õÅD¡A¦]¬°¨â¦r¦ê¨Ã¤£¬Ûµ¥¡A¹sȺX¼Ð·|³Q²M°£¡A³o®ÉÀ³¸Ó¦A°µ²Ä¤G¦¸·j´M¡A´N¬O±q²Ä¤GӦ줸²Õ¶}©l¡A¥un§â BX ¥[¤@ ( ²Ä 83 ¦æ )¡A´N«ü¦Vµ\µ]¦æªº²Ä¤GӦ줸²Õ¤F¡AµM«á¶}©l²Ä¤G¦¸·j´Mªº¤ñ¸û¡A¦p¤U¹Ï¡C¨Æ¹ê¤W¡C¨C¦¸¤ñ¸û³£n³]©w¤W±①¡ã③¤TӼȦs¾¹¶i¦æ¤ñ¸û¡C
SEARCH.EXE ´N¨Ì·Ó³o¤èªk¡A³v¨B¼W¥[ BX¡A¨Ì¦¸³]¦n SI¡BDI¡BCX ¤TӼȦs¾¹¶}©l¤ñ¸û¡A¦pªG¨S§äµÛ¡A´NÅý BX ¦A¥[¤@¡A«½Æ¤Wz¨BÆJ¡A¨º»òµ{¦¡¦p¦óª¾¹D¤°»ò®ÉÔ¸Ó°±¤î©O¡H§Ú̪¾¹D¡Aµ\µ]¦æ¦@¦³ 616 Ó¦r ( µ\µ]¦æªº§Ç¨¥ùØ´N¦³»¡©ú¤F )¡A¦]¦¹À³¸Ón·j´M 1232 ¦¸§a¡Hµª®×¨Ã¤£¹ï¡C°²³]¨Ï¥ÎªÌ¿é¤Jn´M§äªº¦r¦ê¬O¡u¤»®c¯»ÂLµLÃC¦â¡v¡A¦@ 14 Ӧ줸²Õ¡A¨º»ò³Ì«á 13 Ӧ줸²Õ¨ä¹ê¬O¤£¶··j´Mªº¡A¦]¬°ªø«×¤£¦P¡A¦r¦ê¥²©w¤£¦P¡C¤U¹Ï¬O³Ì«á¤@¦¸·j´M¡A¦pªG¨S§ä¨ì¨Ï¥ÎªÌ¿é¤Jªº¦r¦ê¡A¤]¤£¥²¦A¦¸·j´M¤F¡C
©Ò¥H³Ì¦h·j´Mªº¦¸¼Æ¬° 1232¡Ð13¡A¼g¦¨ºâ¦¡¡A³Ì¦h·j´Mªº¦¸¼Æ¡×µ\µ]¦æªº¦ì¤¸²ÕӼơШϥΪ̿é¤Jªº¦ì¤¸²ÕӼơÏ1¡C³oӺ⦡´N¬Oµ{¦¡ªº²Ä 60¡ã63 ¦æ¡C
¦pªG¨Ï¥ÎªÌ¿é¤Jªº¬Oµ\µ]¦æ¤¤ªº¸Ö¥y¡u·¬¸²ýªá¬î·æ·æ¡v¡A·|µo¥Í¤°»ò¨Æ©O¡H¦p¤U¹Ï©Ò¥Ü¡A·í BX «ü¨ì¡u·¬¡vªº²Ä¤@Ӧ줸²Õ®É¡A¤]·|·Ó«e±①¡ã③¡C³o¦¸·j´Mªº¨â¥y¤l¬Û¦P¡A¬G SI¡BDI ³£·|¥Ñ¡u·¬¡vªº²Ä¤@Ӧ줸²Õ¼W¦Ü¡u·æ¡vªº³Ì«á¤@Ӧ줸²Õ¡C
·í¤ñ¸û§¹³o¤Q¥|Ӧ줸²Õ¡A³£¬Û¦P¡ACPU ·|§â¹sȺX¼Ð³]¬°¤@¡A°õ¦æ¨ì²Ä 82 ¦æ¡uje match¡v·|µo¥Í¸õÅD¡A¨ì match ¼Ð°O³B¡A¦L¥X¡u§äµÛ¤F¡I¡vªº°T®§¡A³]©w°h¥X½X¬°¤@¡Aµ²§ôµ{¦¡¡C
³oÓ«ü¥O·|Åý¤K¦ì¤¸ªº¨Ó·½¹Bºâ¤¸²¾¨ì 16¡B32 ¦ì¤¸ªº¥Øªº¹Bºâ¤¸¤¤¡A©ÎÅý¤Q¤»¦ì¤¸ªº¨Ó·½¹Bºâ¤¸²¾¨ì¤T¤Q¤G¦ì¤¸ªº¥Øªº¹Bºâ¤¸¤¤¡A¥BÅý¥Øªº¹Bºâ¤¸¤¤ªº¨ä¥L°ª¦ì¤¸³£Åܦ¨ 0¡C¨ä»yªk¬O¡G
MOVZX r16,r/m8 MOVZX r32,r/m8 MOVZX r32,r/m16
¨ä¤¤ r16¡Br32 ¥Nªí¤Q¤»¦ì¤¸©Î¤T¤Q¤G¦ì¤¸ªº¼È¦s¾¹¡Ar/m8¡Br/m16 ¥Nªí¤K¦ì¤¸©Î¤Q¤»¦ì¤¸ªº¼È¦s¾¹©Î°O¾ÐÅéÅܼơC¦pªG¥Î MOV «ü¥O¡A¨Ó·½¹Bºâ¤¸»P¥Øªº¹Bºâ¤¸ªº¸ê®ÆÃþ«¬¥²¶·¬Û¦P¡F¦ý¬O MOVZX ¯à§â¨Ó·½¹Bºâ¤¸ÂX¥R¦Ü¥Øªº¹Bºâ¤¸¡C¦b¸ê®ÆÂà´«®É¡A¨Ï¥Î MOVZX ¬O¤@ºØ²«K¦Ó§Ö³tªº¤èªk¡C©³¤UÁ|¤TÓ¨Ò¤l»¡©ú¡G
²Ä¤@Ó¨Ò¤l
day db 31 mov ax,0FFFFh movzx ax,day
°õ¦æ§¹«á¡AAX ¬° 31¡A§Y AX¡×001FH¡C¦]¬° day ¬O¤K¦ì¤¸ªº°O¾ÐÅéÅܼơA¬G±N¨ä¥H MOVZX ²¾¤J AX ®É¡A³Ì§Cªº¤K¦ì¤¸Åܦ¨ day ¤§È¡A¨ä¥L°ª¦ì¤¸³£Åܦ¨¹s¡C
²Ä¤GÓ¨Ò¤l¡C¦b SEARCH.EXE µ{¦¡ùØ¡A¨Ï¥ÎªÌ¬O¥H AH¡×0AH/INT 21H ¨Ó¿é¤Jªº¦r¦êªº¡A©Ò¿é¤Jªº¦r¦êªø«×°O¿ý¦b½w½Ä°Ïªº²Ä¤GӦ줸²Õ ( µ{¦¡²Ä 37 ¦æªº input ÅÜ¼Æ )¡A·ín¥H REPE CMPSB ¤ñ¸û¦r¦ê®É¡A¦r¦êªø«×«on©ñ¦b CX ùØ¡F«eªÌ¬O¦ì¤¸²Õ¡A«áªÌ¬O¦r²Õ¡A¦]¦¹¥Î movzx cx,input ¸Ñ¨M³oÓ°ÝÃD ( µ{¦¡²Ä 61 ¦æ )¡C
²Ä¤TÓ¨Ò¤l¡C¦bµ{¦¡²Ä 60¡ã63 ¦æ¡Anpºâ·j´M¦¸¼Æ¡An¥Î¤å³¹ªø«×´î¥h¨Ï¥ÎªÌ¿é¤J¦r¦êªºªø«×¦A¥[¤@¡A¤å³¹ªø«×¬O¦r²Õ¡A¨Ï¥ÎªÌ¿é¤J¦r¦êªºªø«×¬O¦ì¤¸²Õ¡A¦]¦¹¦b²Ä 61 ¦æ®É¥Î MOVZX ±N¦ì¤¸²ÕÂX¥R¦¨¦r²Õ¡A¦s©ó CX ùØ¡C
MOVZX ¬O 80386 ¤Î¨ä¥H«áªº CPU ·s¼Wªº«ü¥O¡A¦]¦¹¦bµ{¦¡ªº«e±¥²¶·n¥[¤W¡u.386¡v©Î¡u.486¡v°²«ü¥O¡A¥H«KÅý²ÕĶ¾¹¯à¨Ï¥Î¸û°ª¶¥ªº CPU «ü¥O¡C¦P®ÉÁÙnª`·N¡A.MODEL ¦b«e¡A.386 ¦b«á¡A¤~·|¨Ï¥Î¤Q¤»¦ì¤¸ªº©w§}¤è¦¡¡C
LEA ¬O load effective address¡A½¦¨¤¤¤å¬O¸ü¤J¦³®Ä¦ì§}¡A¨ä»yªk¦p¤U¡G
LEA r16,m LEA r32,m
¤W±ªº m ¥Nªí°O¾ÐÅéÅܼƩάO¬YӼаO ( Label )¡Ar16¡Br32 ¤À§O¥Nªí¤Q¤»¦ì¤¸©Î¤T¤Q¤G¦ì¤¸ªº¼È¦s¾¹¡CLEA «ü¥O¬O§â°O¾ÐÅéÅܼƩμаOªº¦ì§}¦s¨ì«e±ªº¼È¦s¾¹¤¤¡C¦pªG¬O DOS µ{¦¡¡A©Ò±o¦ì§}¬°¤Q¤»¦ì¤¸¡An¥Î r16¡F¦pªG¬O Win32 µ{¦¡¡A©Ò±o¦ì§}¬°¤T¤Q¤G¦ì¤¸¡A»Ý¥Î r32¡CSEARCH.ASM ªº²Ä 65 ¦æ¡A¡ulea bx,article¡v¡A´N¬O§â article Åܼƪº¦ì§}©ñ¤J BX ¼È¦s¾¹ùØ¡A¨ä¹ê¤]¥i¥H¥Î¡umov bx,OFFSET article¡v¥N´À¡C
LEA ³q±`¬O¥Î¨Ó¨ú±o°Ï°ìÅܼƪº¦ì§}¡C²ÕĶ¾¹¦b²ÕĶ®É¡AµLªk±oª¾°Ï°ìÅܼƪº¦ì§}¡A¦pªGn¨ú±o¨ä¦ì§}¡A¥²¶·¦bµ{¦¡°õ¦æ®É¡A¥H LEA ¨ú±o¨ä¦ì§}¡C
MOVSW¡BMOVSD¡BMOVSQ ³o¤TÓ«ü¥O»P MOVSB «ÜÃþ¦ü¡A«Ü©úÅ㪺¡A³o¤TÓ«ü¥O³Ì«á¤@Ó^¤å¦r¥À¡GW¡BD¡BQ¡A¤À§O¬O Word¡BDoubleword¡BQuadword ªº·N«ä¡A¥ç§Y¦r²Õ¡BÂù¦r²Õ¡B¥|¦r²Õ¡C
³o¤TÓ«ü¥O³£¬O¨Ì¾Ú¤è¦VºX¼Ð¬O¹sÁÙ¬O¤@¡A§â¨Ó·½¦r¦ê·h²¾¨ì¥Øªº¦r¦ê¡A¦ý¨Ã«D·h²¾¤@Ӧ줸²Õ¡CMOVSW ¬O¤@¦¸·h²¾¤@Ó¦r²Õ¡A¨Ã¨Ï SI¡BDI ¼W´î¤G¡FMOVSD ¬O¤@¦¸·h²¾¤@ÓÂù¦r²Õ¡A¨Ã¨Ï SI¡BDI ¼W´î¥|¡FMOVSQ ¥u¯à¥Î©ó 64 ¦ì¤¸ªº§@·~¨t²Î¤¤¡A¨C¦¸·h²¾¤@Ó¥|¦r²Õ¡A¨Ã¨Ï RSI¡BRDI ¼W´î¤K¡C
¦Ü©ó¬O¼WÁÙ¬O´î¡A«h¥Ñ¤è¦V¼È¦s¾¹¨M©w¡C¥Î¡uCLD¡v«ü¥O¡A²M°£¤è¦V¼È¦s¾¹¡A¨º»ò·|©¹°ª¦ì§}¤è¦V·h²¾¡ASI¡BDI ·|¼W¥[¡F¤Ï¤§¡A¥Î¡uSTD¡v«ü¥O¡A³]©w¤è¦VºX¼Ð¡A´N·|©¹§C¦ì§}¤è¦V·h²¾¡ASI¡BDI ·|´î¤Ö¡C
¦¹¥~³o¨Ç«ü¥O¤]¯à¦b¤T¤Q¤G¦ì¤¸©Î¤»¤Q¥|¦ì¤¸ªº§@·~¨t²Î¤¤¨Ï¥Î¡CMOVSB¡BMOVSW¡BMOVSD ¤TÓ«ü¥O¡A³£¯à¦b¤Q¤»¦ì¤¸¡B¤T¤Q¤G¦ì¤¸©Î¤»¤Q¥|¦ì¤¸ªº¨t²Î¤¤¨Ï¥Î¡A¦ý¬Onª`·N¨Ó·½¦r¦ê»P¥Øªº¦r¦êªº¦ì§}¡A¥²¶·©M´X¦ì¤¸ªº¨t²Î°t¦X¡C¤]´N¬O»¡¤Q¤»¦ì¤¸¨t²Î¤¤¡A¨Ó·½¦r¦ê¦ì§}¬O DS:SI¡A¥Øªº¦r¦ê¦ì§}¬O ES:DI ( SI¡BDI ³£¬O¤Q¤»¦ì¤¸ªº¼È¦s¾¹ )¡F¤T¤Q¤G¦ì¤¸¨t²Î¤¤¡A¨Ó·½¦r¦ê¦ì§}¬O ESI¡A¥Øªº¦r¦ê¦ì§}¬O EDI ( ESI¡BEDI ³£¬O¤T¤Q¤G¦ì¤¸ªº¼È¦s¾¹ )¡F¤»¤Q¥|¦ì¤¸¨t²Î¤¤¡A¨Ó·½¦r¦ê¦ì§}¬O RSI¡A¥Øªº¦r¦ê¦ì§}¬O RDI ( RSI¡BRDI ³£¬O¤»¤Q¥|¦ì¤¸ªº¼È¦s¾¹ )¡C
¦pªGn·h²¾ªº¸ê®Æ«Ü¦h¡A¤£½×¬O MOVSB/MOVSW/MOVSD/MOVSQ ³£¥i¥H¦b«e¥[¤W REP «ü¥O¡A¦Ó·h²¾ªº¦¸¼Æ©ñ¦bp¼Æ¼È¦s¾¹ùØ¡C³Ì«á¾ã²z¦p¤Uªí¡G
«ü¥O | »¡©ú | ¨Ó·½¦ì§} | ¥Øªº¦ì§} | ·h²¾¦¸¼Æ | ¤è¦VºX¼Ð | ¨C¦¸·h²¾«á ½Õ¾ã SI¡BDI |
¤Q¤»¦ì¤¸ªº DOS §@·~¨t²Î | ||||||
REP MOVSB | ¤@¦¸·h²¾¤@Ӧ줸²Õ¡A«½Æ·h²¾ | DS:SI | ES:DI | CX | 0¡AUP¡A©¹°ª¦ì§}·h²¾ | ¥[¤@ |
1¡ADN¡A©¹§C¦ì§}·h²¾ | ´î¤@ | |||||
REP MOVSW | ¤@¦¸·h²¾¤@Ó¦r²Õ¡A«½Æ·h²¾ | DS:SI | ES:DI | CX | 0¡AUP¡A©¹°ª¦ì§}·h²¾ | ¥[¤G |
1¡ADN¡A©¹§C¦ì§}·h²¾ | ´î¤G | |||||
REP MOVSD | ¤@¦¸·h²¾¤@ÓÂù¦r²Õ¡A«½Æ·h²¾ | DS:SI | ES:DI | CX | 0¡AUP¡A©¹°ª¦ì§}·h²¾ | ¥[¥| |
1¡ADN¡A©¹§C¦ì§}·h²¾ | ´î¥| | |||||
¤T¤Q¤G¦ì¤¸ªº Windows §@·~¨t²Î | ||||||
REP MOVSB | ¤@¦¸·h²¾¤@Ӧ줸²Õ¡A«½Æ·h²¾ | ESI | EDI | ECX | 0¡AUP¡A©¹°ª¦ì§}·h²¾ | ¥[¤@ |
1¡ADN¡A©¹§C¦ì§}·h²¾ | ´î¤@ | |||||
REP MOVSW | ¤@¦¸·h²¾¤@Ó¦r²Õ¡A«½Æ·h²¾ | ESI | EDI | ECX | 0¡AUP¡A©¹°ª¦ì§}·h²¾ | ¥[¤G |
1¡ADN¡A©¹§C¦ì§}·h²¾ | ´î¤G | |||||
REP MOVSD | ¤@¦¸·h²¾¤@ÓÂù¦r²Õ¡A«½Æ·h²¾ | ESI | EDI | ECX | 0¡AUP¡A©¹°ª¦ì§}·h²¾ | ¥[¥| |
1¡ADN¡A©¹§C¦ì§}·h²¾ | ´î¥| | |||||
¤»¤Q¥|¦ì¤¸ªº Windows §@·~¨t²Î | ||||||
REP MOVSB | ¤@¦¸·h²¾¤@Ӧ줸²Õ¡A«½Æ·h²¾ | RSI | RDI | RCX | 0¡AUP¡A©¹°ª¦ì§}·h²¾ | ¥[¤@ |
1¡ADN¡A©¹§C¦ì§}·h²¾ | ´î¤@ | |||||
REP MOVSW | ¤@¦¸·h²¾¤@Ó¦r²Õ¡A«½Æ·h²¾ | RSI | RDI | RCX | 0¡AUP¡A©¹°ª¦ì§}·h²¾ | ¥[¤G |
1¡ADN¡A©¹§C¦ì§}·h²¾ | ´î¤G | |||||
REP MOVSD | ¤@¦¸·h²¾¤@ÓÂù¦r²Õ¡A«½Æ·h²¾ | RSI | RDI | RCX | 0¡AUP¡A©¹°ª¦ì§}·h²¾ | ¥[¥| |
1¡ADN¡A©¹§C¦ì§}·h²¾ | ´î¥| | |||||
REP MOVSQ | ¤@¦¸·h²¾¤@Ó¥|¦r²Õ¡A«½Æ·h²¾ | RSI | RDI | RCX | 0¡AUP¡A©¹°ª¦ì§}·h²¾ | ¥[¤K |
1¡ADN¡A©¹§C¦ì§}·h²¾ | ´î¤K |
³o¥|Ó«ü¥O¤§¶¡ªºÃö«Y¡A©M MOVSB/MOVSW/MOVSD/MOVSQ ¥|Ó«ü¥OªºÃö«YÃþ¦ü¡A¥u¤£¹L CMPSB/CMPSW/CMPSD/CMPSQ ¬O¤ñ¸û¨âÓ¦r¦ê¬O§_¬Û¦P¡C±z¥i¥H°Ñ¦Ò¤W±ªºªí®æ¡A§âªí®æùتº REP §ï¦¨ REPE ©Î REPNE¡A¨ä¾l¥Îªk´X¥G¤@¼Ë¡F®t§O¦b©ó CMPSB/CMPSW/CMPSD/CMPSQ ·f°t REPE ©Î REPNE ®É¡A¤£¤@©w·|°õ¦æ¨ìp¼Æ¼È¦s¾¹¬°¹s®É¤~°±¤î¡C¨Ï¥Î REPE ®É¡Aªí¥Ü¦pªG¤ñ¸ûµ²ªG¬Û¦P«hÄ~Äò¡A¤]¥i¥H»¡¤ñ¸ûµ²ªG¤£¦P®É´N°±¤î¡F¨Ï¥Î REPNE ®É¡Aªí¥Ü¦pªG¤ñ¸ûµ²ªG¤£¦P«hÄ~Äò¡C