Ch 31 MASM 6.x ·s¼W«ü¥O

ÁöµM MASM 6.0 ¤w¸g¥X¼t³c°â«Ü¤[¤F¡A¦ý¬O¤p¤ì°¸¤@ª½¨Ï¥Î MASM 5.0 ª©¡A¥D­n­ì¦]¬O MASM 5.0 ¦³¸û¦hªº¦Û¥Ñ ( ¤]¦³¥i¯à¬O§Ú¤~²¨¾Ç²L¡A¤£ª¾¦p¦ó¨Ï¥Î )¡A¦ý¬O«o¤]¤£¥i©¿²¤ MASM 6.x ©Ò±a¨Óªº¦n³B¡C

³o¤@³¹±N¤¶²Ð MASM 6.0 ¥H«áªºª©¥»©Ò·s¼Wªº°²«ü¥O¡A³o¨Ç°²«ü¥O¹ï²Õ¦X»y¨¥ªº¡y°ª¶¥¤Æ¡z( ´N¬O¯à§â§PÂ_¡B°j°é¡B°Æµ{¦¡µ¥°µ§ó¦³®Äªº¦w±Æ ) ¤p¦³À°§U¡C³o¤@³¹ªº¤º®e¬O°Ñ¦Ò·L³nªº MASM 6.1 ¤â¥U¤Î Glow Glove ¤j¤j¦h¦~«e¦b¤E¡³ºô©Òµo§Gªº¡yMASM 6.x ·s¼W«ü¥O¦Cªí¡z¡A¯S§O·PÁ Glow Glove ¤j¤j¡C


©I¥s°Æµ{¦¡

¦b²Õ¦X»y¨¥¤¤¡A¤@¯ë©I¥s°Æµ{¦¡¬O¥Î¼È¦s¾¹¶Ç»¼°Ñ¼Æ¡A¦ý¬O¼È¦s¾¹´N¨º»ò´X­Ó¦Ó¥B¤S­n­t³d­pºâ¡A±`±`¤£°÷¥Î¡A¹ê¦b«Ü¤£¤è«K¡C©ó¬O MASM 6.0 ¥H«á¥[¤J¤F´X­Ó¯S®íªº°²«ü¥O¡A¨Ï±oµ{¦¡¥i¥H¨Ï¥Î°ïÅ|¶Ç»¼°Ñ¼Æ¡C¨ä¹ê¦b°ª¶¥»y¨¥©Î¦­´Áªº MASM ª©¥»¡A´N¤w¸g¥i¥H§Q¥Î°ïÅ|¶Ç»¼°Ñ¼Æ¡A¥u¬O¨ì¤F MASM 6.0 ¥H«á¡A¤S§ó¥[«K§Q¡C§Ú­Ì¥ý¨Ó¬Ý¬Ý¦­´Á§Q¥Î°ïÅ|¶Ç»¼°Ñ¼Æµ¹°Æµ{¦¡ªº¤èªk¡C

¥Î BP ¼È¦s¾¹¦s¨ú°Ñ¼Æ»P RET n «ü¥Oªð¦^

­nª¾¹D°ïÅ|¦p¦ó¶Ç»¼°Ñ¼Æ¡A·íµM±o¥ý¤F¸Ñ°ïÅ|¡A¦³Ãö°ïÅ|ªº­ì²z½Ð°Ñ¦Ò²Ä¤­³¹¡A¦¹³B¤£²Ó»¡¡Aª½±µ¶i¤J¥DÃD¡C

·í§Ú­Ì·Q§Q¥Î°ïÅ|¶Ç»¼°Ñ¼Æ®É¡A¤@¯ë¬O¥ý§â°Ñ¼Æ±À¤J°ïÅ|¡A°Æµ{¦¡­n¥Î´X­Ó°Ñ¼Æ´N±À¤J´X­Ó°Ñ¼Æ¨ì°ïÅ|ùØ¡AµM«á¦A¥Î CALL «ü¥O©I¥s°Æµ{¦¡¡C¦¹®É°ïÅ|ùتº³Ì§C¦ì§}¡A«K¦s¦³¥Dµ{¦¡ªºªð¦^¦ì§}¡A¦Ó SP ¼È¦s¾¹«ü¦V¦¹ªð¦^¦ì§}¡A¶Ç¤J°Æµ{¦¡ªº°Ñ¼Æ«K¦b¦¹ªð¦^¦ì§}¸û°ªªº´X­Ó¦r²Õ³B¡C

¦n¤F¡A¶i¤J°Æµ{¦¡«á¡A°Æµ{¦¡¦p¦ó¨ú±o³o¨Ç°Ñ¼Æ©O¡H¤@¯ë¬O§Q¥Î BP ¼È¦s¾¹·í¦¨°ò©³ ( ©ÎªÌ·Q¦¨°Ñ¦ÒÂI )¡A¤£¹L¬°¤F¤£¯}Ãa BP ­ì¥ýªº¤º®e¡A©Ò¥H¤@¯ë·|¥ý§â BP «O¦s¦b°ïÅ|ùØ¡A¦A¨Ï BP «ü¦V°ïÅ|³Ì§C¦ì§}¡A¤]´N¬O©M SP «ü¨ì¤@¼Ëªº¦a¤è¡A¦]¦¹°Æµ{¦¡¤@¶}©l³£¬O¤U­±³o¨â­Ó«ü¥O¡G

        PUSH    BP
        MOV     BP,SP

³o¼Ë¦pªG­n¦s¨ú°Ñ¼Æ®É¡A´N§Q¥Î BP¡Ïn ©Ò«üªº¦ì§}¦s¨ú°Ñ¼Æ¡A¨Ò¦p³Ì«á±À¤J°ïÅ|ªº°Ñ¼Æ«K¦b BP¡Ï4 ªº¦ì§}³B¡A­Ë¼Æ²Ä¤G±À¤J°ïÅ|ªº°Ñ¼Æ¡A«K¦b BP¡Ï6 ªº¦ì§}³B¡C

Á|¤@­Ó¨Ò¤l»¡©ú§a¡I°²³]¦³¤@­Ó°Æµ{¦¡ºÙ¬° day_of_week¡A¥¦¬O­pºâ¦è¤¸¬Y¦~¬Y¤ë¬Y¤é¬O¬P´Á´Xªº°Æµ{¦¡¡A¨º»òÅãµM¥¦»Ý­n¤T­Ó°Ñ¼Æ¡A¦~¡B¤ë¡B¤é¡A¦Ó­pºâ«á¡AAX ¼È¦s¾¹¶Ç¦^¸Ó¤é¬O¬P´Á´X¡C³¡¥÷µ{¦¡½X»P¨C¨B°õ¦æ«á¡A°ïÅ|ÅܤƦp¤U¡G

;-------------------------------------------------
;day_of_week °Æµ{¦¡¥Ñ¦¹¶}©l
day_of_week     proc
        push    bp          ;«O¦s BP
        mov     bp,sp       ;¨Ï BP ·í¦¨°Ñ¦ÒÂI¡A¦U°Ñ¼ÆÅܦ¨ BP¡Ïn
        ¡K¡K    ¡K¡K
        mov     ax,[bp+4]   ;AX=¦~
        ¡K¡K    ¡K¡K
        mov     bx,[bp+6]   ;BX=¤ë
        ¡K¡K    ¡K¡K
        pop     bp
        ret     6
day_of_week     endp
;-------------------------------------------------
;¥Dµ{¦¡¥Ñ¦¹¶i¤J
        ¡K¡K    ¡K¡K
        push    day         ;§â¡y¤é¡z±À¤J°ïÅ|
        push    month       ;§â¡y¤ë¡z±À¤J°ïÅ|
        push    year        ;§â¡y¦~¡z±À¤J°ïÅ|
        call    day_of_week
        ¡K¡K    ¡K¡K

°ïÅ|¶Ç»¼°Ñ¼Æ
¤W¹Ï¤@¬O°Ñ¼Æ©|¥¼±À¤J°ïÅ|®Éªº±¡§Î¡A¥ç§Y push day ÁÙ¨S¦³³Q CPU °õ¦æ¡A¦¹®É SP «ü¦V¤w¨Ï¥Î°ïÅ|ªº³Ì§C¦ì§} ( SP ©Ò«üªº¦ì§}¬O¤w¸g³Q¨Ï¥Î¹Lªº¤F¡A¤U¤@¸û§C¦r²Õªº¦ì§} SP¡Ð2 «K¬OªÅªº°ïÅ| )¡C·í­n°õ¦æ¡ypush day¡z«ü¥O®É¡ASP ·|´î¤G¥H«ü¦V©|¥¼¨Ï¥Î³Ì°ª°ïÅ|¦ì§}¡A¦¹®É SP¡Ð2 «K¬OªÅªº°ïÅ|¡AµM«á¦A§â day ±À¤J³o­Ó¦ì§}¡A¦p¹Ï¤G¡C¦b³sÄò±À¤J month¡Byear «á¡A°ïÅ|¤ºªº±¡§Î¦p¹Ï¥|¡C¦Ó«á¤U¤@«ü¥O¬O call day_of_week ¶i¤J°Æµ{¦¡¡A¦¹®É CPU ·|§â call day_of_week ªº¤U¤@±ø«ü¥O¦ì§}¡A¤]´N¬Oªð¦^¦ì§}±À¤J°ïÅ|¡A¦p¹Ï¤­¡C¶i¤J°Æµ{¦¡«áªº²Ä¤@±ø«ü¥O¬O«O¦s­ì¨Óªº BP¡A°µªk´N¬O§â BP ±À¤J°ïÅ|¡A¦p¹Ï¤»¡C±µ¤U¨Ó¬O¨Ï BP µ¥©ó SP¡A©Ò¥H°õ¦æ§¹³o±ø«ü¥O«á¡ABP ´N«ü¦V¦s©ñ­ì BP ªº°ïÅ|¦ì§}¡A¹Ï¤»¥kÃä²HÂŦ⪺¦ì§}¡ABP¡BBP¡Ï2¡BBP¡Ï3¡K¡K«K¬O¡A´«¥y¸Ü»¡¡A´N¬O¥H BP °Ñ¦ÒÂI¡C

¥i¯à¦³¤H·|°Ý¬°¦óÁÙ­n¥t¿ï BP ·í°µ°Ñ¦ÒÂI¡Aª½±µ¨Ï¥Î SP ¤£¬O§ó²«K¶Ü¡H¨ä¹ê³o¼Ë¤lªº°µªk¨Ã¤£«ê·í¡A¦]¬° SP ¤@¯ë³£¬O«ü¦V¤w¨Ï¥Îªº°ïÅ|³Ì§C¦ì§}¡AÀH®É¥i¯à§ïÅÜ¡A¨Ò¦pµwÅ餤Â_®É¤]¥i¯à§ïÅÜ SP¡A©Ò¥H±o¥t¿ï BP °µ¬°°Ñ¦ÒÂI¡C°ò©ó¤W­z²z¥Ñ¡A¨Ï BP µ¥©ó SP ¥H«á¡ABP ´N·í°µ°Ñ¦ÒÂI¡A§Ú­Ì¥i¥H¥Î³o­Ó°Ñ¦ÒÂI¬°°ò·Ç¥h¦s¨ú¦U­Ó°Ñ¼Æ¡C¨Ò¦p­n¨ú±o day¡A´N¥i¥Î [BP¡Ï8] ¨ú±o¡A­n¨ú±o year ´N¥i¥Î [BP¡Ï4] ¨ú±o¡C

·íµ²§ô°Æµ{¦¡®É¡A²Ä¤@¨B«K¬O¥Ñ°ïÅ|¨ú¦^­ì¨Óªº BP ­È¡A¦]¦¹¦b°Æµ{¦¡§ÀºÝ±o¥[¤W¤@¦æ pop bp¡C±µ¤U¨Ó´N­n°õ¦æ RET «ü¥Oªð¦^­ì¨Óªº¥Dµ{¦¡¡A³o­Ó«ü¥O·|¦Û SP ©Ò«üªº°ïÅ|¦ì§}³B¨ú¦^¥Dµ{¦¡¦ì§}¡AµM«á§â°õ¦æÅv¥æÁÙ¥Dµ{¦¡¡F¦ý¬O¶È¶È³o¼ËÁÙ¤£°÷¡AÁÙ±o§â­ì¥ý±À¤J°ïÅ|ùتº°Ñ¼Æ±Ë±ó¡A³o®É¥i¥H¥Î ret n «ü¥O¡C

RET ³o­Ó«ü¥Oªº§¹¾ã®æ¦¡¬O RET n¡An ¥i¦³¥iµL¡A¦pªG¨S¦³ n ªº¸Ü¡ACPU ´N¥u±q°ïÅ|¨ú¥Xªð¦^¦ì§}¡A¥BÅý SP ¦A¥[ 2¡A«ì´_©I¥s°Æµ{¦¡¤§«eªº¼Æ­È¡F¦pªG n ¨S¦³¬Ù²¤¡A¨º»ò CPU °£¤F¨Ï SP ¦A¥[ 2 ¤§¥~¨Ã±q°ïÅ|¨ú¥Xªð¦^¦ì§}¤§¥~¡AÁÙ·|¦A¨Ï SP ¥[¤W n ³o­Ó¼Æ¡A¥ç§Y±Ë±ó°ïÅ|ùتº­Y¤z¸ê®Æ¡C

MASM 6.x ªº°µªk

¥H¤W¬Oª© MASM §Q¥Î°ïÅ|¶Ç¤J°Ñ¼Æ¨Ó©I¥s°Æµ{¦¡ªº¥Îªk¡C¥Ñ¤W­±¡A±zÀ³·í¥i¥H¤F¸Ñ¦pªG±zºâ¿ù¤F°Ñ¼Æ­Ó¼Æ¡A©ÎªÌ¦h¤@­Ó¨BÆJ¤S©Î¤Ö¤@­Ó¨BÆJ¡A¨º»ò·¥¥i¯à³y¦¨µLªk¯u¥¿ªð¦^¨ì¥Dµ{¦¡¦ì§}¡A¦Ó³y¦¨·í¾÷¡C©Ò¥H¦b MASM 6.x ·s¼W¥[¤@¨Ç°²«ü¥O¡AÀ°§U§Ú­Ì©ó¼¶¼g­ì©l½X®É²¤Æ³o¨Ç¨BÆJ¡AÁקK¤@¨Ç¤£¥²­nªº¿ù»~¡C­º¥ý­n½Íªº¬O PROC/ENDP ³o¹ï°²«ü¥O¡AMASM 6.x ¹ï¥¦­Ì°µ¤F¤@¨Ç­×§ï¡C

PROC/ENDP °²«ü¥O¡G©w¸q°Æµ{¦¡

¦p«e©Ò´£¡APROC/ENDP °²«ü¥O¬O¥Î¨Ó©w¸q°Æµ{¦¡¡A¦b MASM 6.x ÁÙ·s¼W¤F³\¦h¥\¯à¡A¸û§¹¾ãªº»yªk¬O¡F

°Æµ{¦¡¦WºÙ proc [¦ì²¾][µ{¦¡»y¨¥][¥iµø°Ï°ì][USES ¼È¦s¾¹¦Cªí][,
                °Ñ¼Æ¤@[:Ãþ«¬][,°Ñ¼Æ¤G:[Ãþ«¬]... ]]
           ;°Æµ{¦¡¤º®e
°Æµ{¦¡¦WºÙ endp

»¡©ú¦p¤U¡G

°Æµ{¦¡¦WºÙ¡G ¥H CALL ©I¥s®É¡A¨ä«á©Ò±µªº¦WºÙ¡A¨ä¹ê¬O¤@­Ó¼Ð°O¡C
¦ì²¾¡G ¥i¥Î near ©Î far¡C
¡@near¡Gªí¥Ü°Æµ{¦¡»P¥Dµ{¦¡¦b¦P¤@°Ï¬q¤º¡C
¡@far¡Gªí¥Ü°Æµ{¦¡»P¥Dµ{¦¡¦b¤£¦P°Ï¬q¤º¡C
µ{¦¡»y¨¥¡G ¬O¥Î¨Ó¬ù©w©I¥s¤è¦¡¤Î°ïÅ|¦s©ñ¤è¦¡¡A¥i¥H¥Î BASIC¡BC¡BFORTRAN¡BPASCAL¡BSTDCALL¡BSYSCALL¡A¨ä¤¤ BASIC¡BFORTRAN¡BPASCAL ©Ò¥Nªíªº·N¸q¬Û¦P¡A¦]¦¹Á`¦@¥i¤À¬°¥|ºØ¡G
C¡G ©I¥s®É¡A¥Ñ³Ì¥kÃ䪺°Ñ¼Æ¶}©l±À¤J°ïÅ|¡Fªð¦^®É¡A¥Ñ¥Dµ{¦¡²M°£°ïÅ|ùتº°Ñ¼Æ¡C
PASCAL¡G ©I¥s®É¡A¥Ñ³Ì¥ªÃ䪺°Ñ¼Æ¶}©l±À¤J°ïÅ|¡Fªð¦^®É¡A¥Ñ°Æµ{¦¡²M°£°ïÅ|ùتº°Ñ¼Æ¡C
SYSCALL¡G ©I¥s®É¡A¥Ñ³Ì¥kÃ䪺°Ñ¼Æ¶}©l±À¤J°ïÅ|¡Fªð¦^®É¡A¥Ñ°Æµ{¦¡²M°£°ïÅ|ùتº°Ñ¼Æ¡C
STDCALL¡G ©I¥s®É¡A¥Ñ³Ì¥kÃ䪺°Ñ¼Æ¶}©l±À¤J°ïÅ|¡F¤@¯ëªð¦^®É¡A¥Ñ°Æµ{¦¡²M°£°ïÅ|ùتº°Ñ¼Æ¡A¦ý¬O·í¸ê®Æ«¬ºA¬O VARARG ®É¡A¥²¶·¥Ñ¥Dµ{¦¡²M°£°ïÅ|ùتº°Ñ¼Æ¡C
µ{¦¡»y¨¥¥i¥H¬Ù²¤¡A¦pªG¬Ù²¤®É¡A«h¥Ñ .MODEL ¤¤«ü©w ( ¨£µy«á»¡©ú )¡C
USES ¼È¦s¾¹¦Cªí¡G ²ÕĶ¾¹¦Û°Êªº¦b¶i¤J°Æµ{¦¡®É¡A¥[¤W PUSH «ü¥O¡A§â¦b USES ¤§«áªº¼È¦s¾¹±À¤J°ïÅ|«O¦s¡A¨Ã¦b RET «ü¥Oªð¦^¥Dµ{¦¡¤§«e¡APOP ³o¨Ç¼È¦s¾¹¡C
¥iµø°Ï°ì¡G ¥iµø°Ï°ì¥i¥H¬O PRIVATE¡BPUBLIC¡BEXPORT ¤TºØ¡A¦]½s¼g¤jµ{¦¡®É¡A¥i¯à¬O¥Ñ³\¦h OBJ¡BLIB ³sµ²¦Ó¦¨¡A¦]¦¹¦³³o­Ó¿ï¶µ¡C
¡@PRIVATE¡Gªí¥Ü¥u¦³³o­Ó¼Ò²Õ¥i¥Î¡A¥ç§Y¥u¦³¦¹ OBJ ¤ºªºµ{¦¡¥i©I¥s¡C
¡@PUBLIC¡Gªí¥Ü©Ò¦³¼Ò²Õ§¡¥i©I¥s¦¹°Æµ{¦¡¡C
°Ñ¼Æ»P¸ê®Æ«¬ºA¡G °Ñ¼Æ¥²¶·©M«e­±ªº¦ì²¾¡Bµ{¦¡»y¨¥¡Kµ¥¹j¤@­Ó¡y,¡z¡A¦pªG°Ñ¼Æ¤£¥u¤@­Ó¡A¨C­Ó°Ñ¼Æ¤§¶¡¤]­n¥H¡y,¡z¤À¶}¡C¦pªG°Ñ¼Æ¤Ó¦h¡A¤]¥i¥H´«¦æ¡A³o®É­Ô¡A¡y,¡z¥²¶·¦b¤W¤@¦æªº³Ì«á­±¡A§_«h·|µLªk²ÕĶ¦¨¥\¡C°Ñ¼Æ¬O«ü¦b¶i¤J°Æµ{¦¡¤§«á¡A©Ò¨Ï¥ÎªºÅܼƦWºÙ¡A¤]´N¬O»¡¡A¦b°Æµ{¦¡¤¤¶·¥H°Ñ¼Æ¦WºÙ¨Óªí¥Ü¡C°Ñ¼Æ¤§«á±o±µ¤W³o­Ó°Ñ¼Æªº¸ê®Æ§ÎºA¡A±`¥Îªº¸ê®Æ«¬ºA¦³ BYTE¡BWORD¡BDWORD¡BQWORD¡BTBYTE µ¥¡A¤À§O¥Nªí¤@­Ó¦ì¤¸²Õ¡B¤@­Ó¦r²Õ¡BÂù¦r²Õ¡B¥|¦r²Õ ( 8 ­Ó¦ì¤¸²Õ )¡B10 ­Ó¦ì¤¸²Õ¡C°Ñ¼Æ»P¸ê®Æ«¬ºA¤§¶¡¥H¡y:¡z¬Û³s¡A¸ê®Æ§ÎºA¥Î¨Óªí¥Ü³o­Ó°Ñ¼Æ¦û¥Î¦h¤Ö­Ó¦ì¤¸²Õ¡AÁöµM¦b DOS µ{¦¡¤¤¡A¨C¦¸ PUSH ³£¬O¤@­Ó¦r²Õ¡A¦ý¬O§Ú­Ì¤£¶·¾Þ¤ß·|¤£·|¥X°ÝÃD¡A¦]¬°²ÕĶ¾¹·|¦Û°Ê¦a§â¤£¬O¤@­Ó¦r²Õªº°Ñ¼Æ§ï¦¨¤À¦¸±À¤J°ïÅ|¡A©Î¥[ªø¦¨¤@¦r²Õ¦A±À¤J°ïÅ|¡C¥t¥~¡A¸ê®Æ«¬ºA¤]¥i¥H¥Î VARARG¡Aªí¥Ü¦¹°Æµ{¦¡ªº°Ñ¼Æ¤£©T©w¡A¥²¶·¥Ñ¥Dµ{¦¡©I¥sªº·í®É¨Ó¨M©w¡C

°Æµ{¦¡µ²§ô¤§³B¥H ENDP ªí¥Ü¡AMASM 6.x ¦b ENDP °²«ü¥O¤§«e¡A·|¦Û°Êªº¨Ì¾Ú PROC ¤§«áªº¦ì²¾¨M©w¥Îªñµ{©Î»·µ{ªð¦^¥Dµ{¦¡¡A¦P®É·í§Ú­Ì¥Î PASCAL¡BSYSCALL¡BSTDCALL ¤]·|¦Û°Êªº¥[¤W POP BP¡A«ì´_­ì¨Óªº BP¡A¥H¤Î RET N¡A±Ë±ó¦b°ïÅ|ùتº°Ñ¼Æ¡C

PROTO °²«ü¥O¡G«Å§i°Æµ{¦¡­ì«¬

PROTO ¬O¥Î¨Ó«Å§i°Æµ{¦¡­ì«¬ªº«ü¥O¡A©Ò¿×«Å§i­ì«¬ªº·N«ä¬O§i¶D²ÕĶ¾¹³o­Ó°Æµ{¦¡ªº©Ê½è¡A¨Ò¦p­n¥Î¨º¨Ç°Ñ¼Æ¡A³o¨Ç°Ñ¼Æªº¸ê®Æ«¬ºA¬O¤°»ò¡A°ïÅ|¦s¤J¤è¦¡µ¥µ¥¡C¤@¯ë¦pªG¦b­ì©l½Xªº«e­±¥Î PROC/ENDP ¤w©w¸q°Æµ{¦¡¡A¦Ó¥Dµ{¦¡¦b­ì©l½X«á­±¤~©I¥s°Æµ{¦¡¡A¨º»ò¥i¥H¤£¶·¥Î PROTO «Å§i°Æµ{¦¡­ì«¬¡C¦pªG­ì©l½X¦b©I¥s°Æµ{¦¡¤§«eÁÙ¨S¦³¥Î PROC/ENDP ©w¸q°Æµ{¦¡©Î¬O©I¥s¥~³¡µ{¦¡®w¡A¨º»ò´N­n¥Î PROTO ¶·§i°Æµ{¦¡­ì«¬¡C·í§Ú­Ì­×§ï°Æµ{¦¡®É¡A¦pªG´¿¸g«Å§i¡A¨º»ò PROTO ©M PROC ³£¥²¶·¦P®É­×§ï¡A§_«h²ÕĶ¾¹´N·|µL©Ò¾A±q¡C©Ò¥H«Øij¡A¦pªG¯à§â°Æµ{¦¡¼g¦b«e­±¡AºÉ¶q¬Ù²¤ PROTO¡C

PROTO ªº»yªk¦p¤U¡G

°Æµ{¦¡¦WºÙ proto [¦ì²¾][µ{¦¡»y¨¥][¥iµø°Ï°ì][,
                °Ñ¼Æ¤@[:Ãþ«¬][,°Ñ¼Æ¤G:[Ãþ«¬]... ]]

±zÀ³¸Ó¥i¬Ý±o¥X¨Ó¡A proto ªº»yªk©M proc ´X¥G¤@¼Ë¡A¥u§R°£¤F¼È¦s¾¹¦Cªíµ¥¤p³¡¥÷¡C

INVOKE °²«ü¥O¡G©I¥s°Æµ{¦¡

INVOKE ­^¤å¬O¥l³ê¤§·N¡A¦b²Õ¦X»y¨¥¤¤«K¬O©I¥s°Æµ{¦¡¡C¨ä»yªk¬O¡G

        invoke  °Æµ{¦¡¦WºÙ[,°Ñ¼Æ¤@[,°Ñ¼Æ¤G]¡K¡K]

INVOKE ¬O MASM 6.x ¤¤·sªº°²«ü¥O¡A¥¦·|³Q²ÕĶ¾¹¡y½Ķ¡z¦¨¼Æ­Ó 80x86 «ü¥O

        push    °Ñ¼Æ n
        push    °Ñ¼Æ n¡Ð1
        push    ¡K¡K¡K¡K
        push    °Ñ¼Æ¤G
        push    °Ñ¼Æ¤@
        call    °Æµ{¦¡¦WºÙ

¤W¦¡¤¤¡A¦³¦h¤Ö­Ó°Ñ¼Æ¡A´N·|³Q½Ķ¦¨¦h¤Ö­Ó push «ü¥O¡A³Ì«á¦A¥Î call ©I¥s°Æµ{¦¡¡C¤£¹L¬O³Ì¥kÃ䪺°Ñ¼Æ¥ý±À¤J°ïÅ|¡AÁÙ¬O°Ñ¼Æ¤@¥ý±À¤J°ïÅ|¡A±o¨Ì¾Ú PROC ©Î PROTO ªºµ{¦¡»y¨¥¿ï¶µ¨M©w¡C

¤@­Ó°Æµ{¦¡¥i¯à·|³Q¥Dµ{¦¡©I¥s¦n´X¦¸¡A¨C¦¸©I¥s®É¶Ç¤Jªº°Ñ¼Æ³£¥i¯à ¤£¤@¼Ë¡A¦]¦¹³o¨Ç±µ¦b INVOKE ¤§«á°Ñ¼Æªº¦WºÙ©M¦b PROC ¤§«á©w¸qªº°Ñ¼Æ¦WºÙ¤£¯à¦P¦W¡A§_«h·|¨Ï±o²ÕĶ¾¹§Ë¤£²M·¡¡C

LOCAL¡G©w¸q°Ï°ìÅܼÆ

°Æµ{¦¡¤¤±`±`·|°µ¤j¶q­pºâ¡A¦pªG¼È¦s¾¹¤£°÷´N±o¥Î¨ì¤@¨ÇÅܼơA°²¦p°£¤F³o­Ó°Æµ{¦¡¨Ï¥Î³o¨ÇÅܼƥH¥~¡A¨ä¾lµ{¦¡³£¥Î¤£µÛ³o¨ÇÅܼơA¨º»ò¦b¸ê®Æ°Ï¬qùØ©w¸q³o­ÓÅܼơA¤£¬O³Ì¦nªº°µªk¡C¦]¬°³o¼Ë·|³y¦¨ºûÅ@¤Wªº³Â·Ð¡A·í±z·Q§â³o­Ó°Æµ{¦¡Åܦ¨µ{¦¡®w¡A¦b¸ê®Æ°Ï¬qªºÅܼƤ]¬O¤@¤j°ÝÃD¡C³Ì¦nªº¤èªk¬O§â³oºØ¥u¦³¦b°Æµ{¦¡¤¤¤~¦s¨úªºÅÜ¼Æ ( ºÙ¬°°Ï°ìÅÜ¼Æ ) ©w¸q¦b°ïÅ|¬qùØ¡A³o¼Ë´N¯à§â°Æµ{¦¡«Ê¸Ë°_¨Ó¡A¥H¹Fµ²ºc¤Æªº¥Øªº¡C

¦b MASM 6.x ªºª©¥»¡A´£¨Ñ¤F¤@­Ó²³æ©w¸q°Ï°ìÅܼƪº¤èªk¡A¨º´N¬O¨Ï¥Î LOCAL °²«ü¥O¡ALOCAL ªº»yªk¬O

        LOCAL   ÅܼƦW[[­«½Æ¦¸¼Æ]]:¸ê®Æ«¬ºA [,ÅܼƦW[[­«½Æ¦¸¼Æ]]:¸ê®Æ«¬ºA¡K¡K]

¤@­Ó LOCAL °²«ü¥O¥i¥H©w¸q¼Æ­Ó°Ï°ìÅܼơA·íµM¤]¥i¥H¤À¶}¨Ó©w¸q¡A¨Ò¦p¤U­±¨â­Ó¨Ò¤l¡G

        LOCAL   a:WORD
        LOCAL   key_buffer[16]:BYTE

²Ä¤@­Ó¨Ò¤l¬O©w¸q¤@­Ó¦r²Õªø«×ªº°Ï°ìÅܼơAa¡C²Ä¤G­Ó¨Ò¤l¬O©w¸q¤@­Óªø 16 ¦ì¤¸²Õªº°Ï°ìÅܼơAkey_buffer¡A³o­Ó°Ï°ìÅܼƬO¤@­Ó°}¦C¡A³o­Ó°}¦C¦³ 16 ­Ó¤¸¯À¡A¨C­Ó¤¸¯Àªø¤@­Ó¦ì¤¸²Õ¡C·í²ÕĶ¾¹¹J¨ì LOCAL ®É¡A²ÕĶ¾¹·|¦b°ïÅ|¤¤¯d¤U¤@¶ôªÅ¶¡¡A®e¯Ç©Ò¦³ªº°Ï°ìÅܼơC­n¦b°ïÅ|¤¤¯d¤U¤@¶ôªÅ¶¡¡A¥u»Ý­n¨Ï SP ´î±¼©Ò¦³°Ï°ìÅܼƪºªø«×¤§©M¡C¦Óµ{¦¡³]­p®v©Ò­n°µªº¡A´N¬O©M¨Ï¥ÎÅܼƤ@¼Ëªº¤è¦¡¨Ï¥Î°Ï°ìÅܼơA¤]´N¬O¥H°Ï°ìÅܼƦWºÙ·í¦¨¦ì§}¦s¨ú¨ä¤º®e¡A¨Ò¦p¡G

        mov     a,ax

­ì©l½X¤¤¦pªG­n¦s¨ú°Ï°ìÅܼƤ]¤£»Ý­n¦b°Ï°ìÅܼƤ§«e¥[¤W SS:¡A¦]¬°²ÕĶ¾¹·|§â°Ï°ìÅܼÆÅܦ¨°ïÅ|¤Wªº¦ì§}¡A¦¹¦ì§}¤]¬O¥H BP ¬°°ò·Ç¡A¦Ó¥H BP ¬°°ò·Çªº¦ì§}¡A¦b 80x86 «ü¥O¤¤ªº¤º©w°Ï¬q¼È¦s¾¹´N¬O SS ¬q¼È¦s¾¹¡C¥i¯à±z·|°Ý¡A³o¼Ë·|³y¦¨°ïÅ|§ïÅÜ¡A¨º»ò¦bªð¦^¥Dµ{¦¡·|¤£·|¦³°ÝÃD¡H³o±z¤j¥i©ñ¤ß¡A¦]¬°²ÕĶ¾¹·|¦Û°Êªº¦b°Æµ{¦¡µ²§ô©M±Ë±ó°Ñ¼Æ¤§«e¡A¥[¤W¤U­±³o±ø«ü¥O

        mov     sp,bp

¨Ï SP «ì´_¦¨­è¶i¤J°Æµ{¦¡®É­Ôªº¼Ë¤l ( ÁÙ°O±o§a¡H­è¶i¤J°Æµ{¦¡®É¡A·|¦³¤@±ø mov bp,sp¡A¥ç§Y¨Ï BP «O¦s SP )¡AµM«áªð¦^¥Dµ{¦¡¤Î±Ë±ó°Ñ¼Æ¡C¤p¤ì°¸¹ê»ÚÁ|¤@­Ó¨Ò¤l¨Ó»¡©ú°ïÅ|¦p¦ó¦s©ñ°Ï°ìÅܼơC¦p¦P¤W­±ªº day_of_week °Æµ{¦¡¡A°²³]¨ä¤º¦³¨â­Ó°Ï°ìÅܼơAa¡Bcentury¡A¨ä«¬ºA³£¬O WORD¡C¨º»ò§â³¡¥÷­ì©l½X§ï¼g¦¨¾A¦X MASM 6.x ªº·s¥\¯à¡G


;-------------------------------------------------
day_of_week     proc    y:WORD,m:WORD,d:WORD
        local   a:WORD
        local   century:WORD
        ¡K¡K    ¡K¡K
        sub     bx,a
        mov     y,bx
        mov     century,ax
        ¡K¡K    ¡K¡K
        ret
day_of_week     endp
;-------------------------------------------------
        ¡K¡K    ¡K¡K
        ;¥Dµ{¦¡
        ¡K¡K    ¡K¡K
        invoke  day_of_week,year,month,day

³o¬qµ{¦¡¡A·|³Q²ÕĶ¾¹Åܦ¨¡G

day_of_week:
        push    bp
        mov     bp,sp       ;¡¯
        add     sp,-04
        ¡K¡K¡@¡@¡K¡K
        sub     bx,[bp-02]  ;BX ´î¥h°Ï°ìÅÜ¼Æ a
        mov     [bp+04],bx  ;°Ñ¼Æ year µ¥©ó BX
        mov     [bp-04],ax
        ¡K¡K    ¡K¡K
        mov     sp,bp       ;¶}©lÂ÷¶}°Æµ{¦¡
        pop     bp
        ret     0006
        ¡K¡K    ¡K¡K
        push    day
        push    month
        push    year
        call    day_of_week

¤W­±²HÂŦ⪺³¡¥÷¬O day_of_week °Æµ{¦¡¡A«e­±§Ú­Ì¤w¸g°Q½×¹L°Ñ¼Æ¦p¦ó¦s©ñ¦b°ïÅ|ùØ¡AÅý§Ú­ÌÄ~Äò¬Ý¤U¥h¡G

°ïÅ|¤¤ªº°Ï°ìÅܼÆ
·í¶i¤J°Æµ{¦¡¡A¨Ã¥B³]©w BP ¬°°ò·Ç«á ( ¥ç§Y¤w°õ¦æ§¹¦³¡y¡¯¡zµù°Oªº¨º±ø«ü¥O«á )¡A¦]¬°°Æµ{¦¡©w¸q¤F¨â­Ó¦r²Õªº°Ï°ìÅܼơA¨â­Ó¦r²Õ¦@¦û¥Î 4 ­Ó¦ì¤¸²Õ¡A¬G¨Ï SP ´î¤Ö 4¡AªÅ¤U¨â­Ó¦r²Õ¡A¤À§O§@¬° a¡Bcentury ªº¦s©ñªÅ¶¡¡A¦p¹Ï¤C¡B¤K¡A¨ì¦¹¶i¤J°Æµ{¦¡ªº¤@¤Á¤âÄò³£¤w§¹³Æ¡C¦pªG¦b°Æµ{¦¡¤¤¡A·Q­n¦s¨ú°Ï°ìÅÜ¼Æ a¡A¨º»ò´N¥Î [BP¡Ð2] ªí¥Ü¡A­n¦s¨ú°Ñ¼Æ year¡A´N¥Î [BP¡Ï4] ªí¥Ü¡A³o¥i¥H«Ü²M·¡ªº±q¹Ï¤W¤Î²ÕĶ«áªº±¡§Î¹ï·Ó´N±o¨ì¡C

¹Ï¤E¬O­nÂ÷¶}°Æµ{¦¡ªð¦^¥Dµ{¦¡®Éªº±¡§Î¡A­º¥ý¬O°õ¦æ mov sp,bp¡A¦¹®É BP ­È«ü¦V­ì BP ­Èªº°ïÅ|¦ì§}¡A°Ñ¦Ò¤W¹Ï³Ì¥ªÃä²HÂŦ⪺ BP¡ABP¡Ð2 µ¥¡A¥i±oª¾ BP ¤§­È¡C·í°õ¦æ§¹ mov sp,bp «á¡ASP «K«ü¦V­ì BP ­Èªº°ïÅ|¦ì§}¡A¦p¹Ï¤Q¡A¦¹®É«K¤w±Ë±ó¤F°Ï°ìÅܼơC±µ¤U¨Ó°õ¦æ pop bp¡A¥Ñ°ïÅ|¨ú¦^­ì BP ­È¡A¦p¹Ï¤Q¤@¡C³o¨â¨B¥i¥H¥Î¤@±ø LEAVE «ü¥O¥N´À¡C

ÁöµM¨Ï¥Î°Ï°ìÅܼƪº¤èªk©M¤@¯ëÅܼƴX¥G¨S¤°»ò¨â¼Ë¡A¦ý¬O¦pªG­n¨ú±o°Ï°ìÅܼƪº¦ì§}®É¡A´N¤£¯àª½±µ¥Î

        mov     si,offset key_buffer

¤F¡C¦]¬°§Ú­Ì¦b¼¶¼g­ì©l½X®É¡AµLªk½Tª¾¶i¤J°Æµ{¦¡«á¡A°ïÅ|¨ì©³¨Ï¥Î¤F¦h¤Ö ( ¦]¬°¦³¥i¯à¦b°Æµ{¦¡¤¤©I¥s°Æµ{¦¡ )¡A©Ò¥HµLªk¥Î OFFSET ¨Ó¨ú±o°Ï°ìÅܼƪº¦ì§}¡C¦ý¬O©³¤U¦³­ÓÅܳqªº¿ìªk¡C

LEA «ü¥O

LEA ¬O 80x86 CPU «ü¥O¶°ªº¤@­û¡A¦b 8086 CPU ´N¤w¸g¦³³o­Ó«ü¥O¡A³o­Ó«ü¥O¬O¥Î¨Ó¨ú±oÅܼƪº¦ì§}¡A¨ä»yªk¬O

        LEA     ¼È¦s¾¹,ÅܼƦW

³o­Ó«ü¥O©M OFFSET °²«ü¥Oªº¥\¯à´X¥G¤@¼Ë¡A¦ý¬O¥¦¬O¦b CPU °õ¦æ®É¡A¤~¨ú±oÅܼƪº¦ì§}¡F¦Ó OFFSET «h¬O¦b²ÕĶ®É´N¨ú±o¦ì§}¡C¦]¦¹ LEA ¥i¥H¥Î¦bÅܼƦì§}¥i¯à·|§ïÅܪº±¡§Î¡A¨Ò¦p¨ú±o°Ï°ìÅܼƪº¦ì§}¡C

ADDR °²«ü¥O¡G¨ú±o°Ï°ìÅܼƦì§}

ADDR °²«ü¥Oªº»yªk¬O

        ADDR ÅܼƦW

ADDR °²«ü¥O¥i¥H¨ú±oÅܼƪº¦ì§}¡A¦ý¤@¯ë¥u°t¦X INVOKE °²«ü¥O¤¤¨Ï¥Î¡C¦pªG¬O­n¨ú±o°Ï°ìÅܼƦì§}¡A²ÕĶ¾¹·|§â ADDR¡y½Ķ¡z¦¨

        lea     ax,ÅܼƦW
        push    ax

¦pªGÅܼƪº¦ì§}¦b²ÕĶ®É¤w½T©w¡A²ÕĶ¾¹·|§â¥L¬Ý¦¨ OFFSET ÅܼƦW¡C

LEAVE «ü¥O

LEAVE «ü¥O¬O 80X86 CPU «ü¥O¶°ªº¤@­Ó«ü¥O¡A¥¦¥ý¨Ï SP ¼È¦s¾¹³]©w¬° BP ¤§­È¡AµM«á¦A¼u¥X¤@­Ó°ïÅ|¼Æ­È¦s©ó BP¡C±`¥Î©óªð¦^¥Dµ{¦¡®É§â SP ¤§­È³]©w¬°¥¿½T­È¡C¦b 32 ¦ì¤¸ªº§@·~¨t²Î¤¤¡A¨Ò¦p Win32 ¡A¤]¥i¥H¨Ï¥Î¡A³o®É¨Ï ESP ¼È¦s¾¹³]©w¬° EBP ¤§­È¡AµM«á¦A¼u¥X¤@­Ó°ïÅ|¼Æ­È¦s©ó EBP¡A©Ò¤£¦Pªº¬O°ïÅ|¤@­Ó¼Æ­Èªø«×¬°Âù¦r²Õ ( 32 ­Ó¦ì¤¸ )¡C


°ª¶¥µ{¦¡±±¨î¬yµ{

MASM 6.x °£¤F§ó¤è«Kªº©I¥s°Æµ{¦¡¡B¨Ï¥Î°Ï°ìÅܼƤ§¥~¡AÁÙ²K¥[¤F§ó¤è«Kªºµ{¦¡¬yµ{¡C¦b§C¶¥ª©¥»ªº MASM ­n±±¨î¬yµ{¡A¤£¥~¥G¤@¤j°ï cmp¡Bjz¡Bja¡Bjb µ¥¡A¤£¦ý¥iŪ©Ê§C¡A¤]Ãø¥HºûÅ@¡C¦ý¬O²{¦b¤£¦P¤F¡AMASM ¥[¤W¤F¦n´XºØ±±¨î¬yµ{¡A¦b Win32 ªº²Õ¦X»y¨¥²Ä¥|³¹¤]¤¶²Ð¹L¤@ÂI¡A¥i¨Ñ°Ñ¦Ò¡C

@@ ¼Ð°O»P¸õÅD @F ©Î @B

°£¤F°ª¶¥ªº¬yµ{±±¨î¤§¥~¡AMASM 6.x ÁÙ±µ¨ü¤@ºØ¯S®í¼Ð°O¡A@@:¡C³oºØ¼Ð°O¬O°µ¬°¸õÅD«ü¥Oªº¥Øªº¦a¡A­n¥Î @@: °µ¬°¥Øªº¦aªº¸õÅD«ü¥O¡A¥²¶·°t¦X @f ©Î @b ¨Ï¥Î¡A«eªÌ¬O«ü©¹«e¸õÅD¡A«áªÌ¬O©¹«á¸õÅD¡A¥¦­Ì³£¥u¦V«e©Î¦V«á¸õÅD¨ì²Ä¤@­Ó @@: ¼Ð°O³B¡C

¨Ò¦p¦³¤@­Óµ{¦¡¤ù¬q¡A¬O¥Î¨Ó¨Ï¤@­Ó¦û¥Î 16 ­Ó¦ì¤¸²Õªº key_buffer °}¦C©Ò¦³¤¸¯À¶ñ¤W 0¡A¤@¯ë·|³o¼Ë¼g¡G

        mov     cx,16
        lea     si,key_buffer
next:   mov     byte ptr ss:[si],0
        inc     si
        loop    next

¦pªG next: ¼Ð°O¥u¦³¦¹³B¥Î¨ì¡A¨º»ò«K¥i¥H¥Î @@: ¥N´À¡AÅܦ¨¤U­±ªºµ{¦¡¡G

        mov     cx,16
        lea     si,key_buffer
@@:     mov     byte ptr ss:[si],0
        inc     si
        loop    @b

°ª¶¥°²«ü¥O¡Jµ{¦¡¬yµ{±±¨î

¦b²Ä 26 ³¹¥¨¶°»P²Ä 27 ³¹±ø¥ó²ÕĶ¨â³¹ùØ¡A´¿¸g´£¨ì IF/ELSE/ENDIF °²«ü¥O¡A³o¨Ç«ü¥O«e¨S¦³¤p¼ÆÂI¡A¦Ó¥B¦b·N¸q¤W©M©³¤U¤p¤ì°¸±N¤¶²Ðªº¤TºØ°ª¶¥¬yµ{±±¨î§¹¥þ¤£¦P¡A¬G¦b¼¶¼gµ{¦¡®É¡A¤d¸U¤£¥i·d²V¡C¨Æ¹ê¤W¡A¹ê»Ú½s¼gµ{¦¡®É¡A©³¤U­n¤¶²Ðªº°ª¶¥¬yµ{±±¨î¤ñ±ø¥ó²ÕĶ§ó±`¥Î¨ì¡C

.WHILE/.ENDW °²«ü¥O

¥ý¨Ó¬Ý¬Ý¥¦ªº»yªk¡J

.WHILE  §PÂ_¦¡
        µ{¦¡
.ENDW

³o­Ó .WHILE/.ENDW °j°éªº°õ¦æ¹Lµ{¦p¤U¡J·íµ{¦¡°õ¦æ¨ì .WHILE ®É¡A·|Àˬd§PÂ_¦¡¬O§_¬°¯u¡A°²¦p¬°¯u¡A«h°õ¦æ .WHILE »P .ENDW ¤§¶¡ªºµ{¦¡¡Aª½¨ì¹J¨ì .ENDW ®É¡A¦A¦^¨ì¶}ÀY .WHILE ³BÀˬd§PÂ_¦¡¬O§_¬°¯u¡A­Y¬°¯u®É¡A¦A«×°õ¦æ .WHILE »P .ENDW ¤§¶¡ªºµ{¦¡¡A­Y¬°°²¡A«h¸õ¨ì .ENDW ¤U¤@¦æµ{¦¡°õ¦æ¡C©Ò¥H¬Ý°_¨Ó¡A.WHILE/.ENDW ´N¹³¬O C/C¡Ï¡Ï ªº WHILE {} °j°é¤@¼Ë¡C

¦Ü©ó§PÂ_¦¡ªº¼Ò¼Ë¡A¤j­P¥i¤À¬°¨âºØ¡J

  ¼È¦s¾¹©ÎÅÜ¼Æ ÅÞ¿è¹Bºâ¤l ¼È¦s¾¹©Î¼Æ­È
  ¼È¦s¾¹©ÎÅܼƩμƭÈ

¤W­±¨º¤@ºØ±¡§Î®É¡A¹Bºâ¤l¥ª¥k¨âÃä¥i¥H¦P®É¬°¼È¦s¾¹¡A¦ý¤£¯à¦P®É¬°ÅܼơA³o¬O¦]¬°¦b 80X86 «ü¥OùØ¡A¥i¥H¦³ cmp ax,bx¡A¦ý¨S¦³ cmp a,b ³o¼Ëªº«ü¥O¡C°²¦p¬°¤U­±¨º¤@ºØ±¡§Î®É¡A¼È¦s¾¹¡BÅܼơB¼Æ­È¬°«D¹s®É¡A·|³Q²ÕĶ¾¹»{¬°¡y¯u¡z¡F¬°¹s®É¡A³Q»{¬°¡y°°¡z¡C

±`¥ÎªºÅÞ¿è¹Bºâ¤l¦p¤Uªí¡J

¹Bºâ¤l ´y­z ¹Bºâ¤l ´y­z
==µ¥©ó !=¤£µ¥©ó
>¤j©ó >=¤j©óµ¥©ó
<¤p©ó <=¤p©óµ¥©ó
&¥B ¦©Î
!«D

°£¤F³o¨ÇÅÞ¿è¹Bºâ¤l¤§¥~¡A¨â­Ó§PÂ_¦¡¤§¶¡¤]¥i¥H°µ¡y©Î¡z»P¡y¥B¡zªºÅÞ¿è¹Bºâ¡A³o®É¡y©Î¡z­n¥Î¦¦¡A¡y¥B¡z­n¥Î&&¡A¨Ó³s±µ¨â­Ó§PÂ_¦¡¡A¨Ã¥B³o¨â­Ó§PÂ_¦¡À³¸Ó¥Î¨â¹ï¤p¬A¸¹¬A°_¨Ó¡C¨Ò¦p¡A©³¤Uªº¨Ò¤l¬O·í AX ¤j©ó SI ¥B BX ¤j©ó DI ®É¡A¨Ï CX ¼W¥[¤@¡A¨Ã¨Ï BX ´î¤@¡Aª½¨ì¤W­z±ø¥ó¤£¦¨¥ß®É¡J

.WHILE  (ax>si)&&(bx>di)
        inc     cx
        dec     bx
.ENDW

©³¤Uªº¨Ò¤l¬O·í AX ¤£µ¥©ó¹s®É¡A§â BX ©Ò«ü¦ì§}¤§¼Æ­È²¾¤J AX¡Aª½¨ì AX µ¥©ó¹s®É°±¤î¡J

.WHILE  AX
        mov     ax,[bx]
        inc     bx
        inc     bx
.ENDW

.IF/.ESLEIF/.ELSE/.ENDIF °²«ü¥O

³Ì²³æªº±¡§Î¬O¡J

.IF     §PÂ_¦¡
        µ{¦¡¤@
.ELSE
        µ{¦¡¤G
.ENDIF

³oÀ³¸Ó«Ü®e©ö¤F¸Ñ¡A·í§PÂ_¦¡¬°¡y¯u¡z®É°õ¦æµ{¦¡¤@ùتº«ü¥O¡F¬°¡y°°¡z®É´N°õ¦æµ{¦¡¤Gùتº«ü¥O¡A°²¦p¬°¡y°°¡z®É¤£¥Î°õ¦æ¥ô¦ó«ü¥O¡A«h .ELSE ¥H¤Îµ{¦¡¤G¥i¥H§R°£¡C©³¤U¬O¤@­Ó¤ñ¸û½ÆÂøªº¨Ò¤l¡A

.IF     §PÂ_¦¡¤@
        µ{¦¡¤@
.ELSEIF §PÂ_¦¡¤G
        µ{¦¡¤G
.ELSEIF §PÂ_¦¡¤T
        µ{¦¡¤T
.ELSE
        µ{¦¡¥|
.ENDIF

³o¬O¤À¤ä«ü¥O¡A°²¦p§PÂ_¦¡¤@¬°¯u¡A«h°õ¦æµ{¦¡¤@ªº«ü¥O¡F°²¦p§PÂ_¦¡¤G¬°¯u¡A«h°õ¦æµ{¦¡¤Gªº«ü¥O¡F°²¦p§PÂ_¦¡¤T¬°¯u¡A«h°õ¦æµ{¦¡¤Tªº«ü¥O¡K¡K¡A°²¦p³£¤£¬O¤W­±ªº±¡§Î¡A«h°õ¦æ .ELSE ¤§«áªºµ{¦¡¡C´«¥y¸Ü»¡¡A.IF/.ESLEIF/.ELSE/.ENDIF «Ü¦³¼u©Ê¡A±z¥i¥H¨Ì»Ý­n¡A¬Ù«o .ELSEIF ©Î¬Ù«o .ELSE¡A¤]¥i¥Hµø±¡ªp¼W¥[ .ELSEIF ±ø¥ó¤À¤ä¡A¤£¹L¤£½×¨º¤@ºØ±¡§Î¡A.IF ©M .ENDIF ¥²©w¬O·f°t¦b¤@°_¡A¨Ã¥B¦b±ø¥ó¸õÅDªº³Ì«e»P³Ì«á¡C

³Ì«áÁÙ¦³¤@­Ó°ÝÃD¡C.IF/.ESLEIF/.ELSE/.ENDIF ¬O 80x86 «ü¥O¶°ªº¤@­û¶Ü¡Hµª®×·íµM¤£¬O¡A¥L­Ì¥u¬O°²«ü¥O¡A²ÕĶ¾¹·|¦Û°Ê¦a§â¥¦Åܦ¨¾A·íªº«ü¥O¡C¨Ò¦p¤U­±³o­Óµ{¦¡¡G

.if cx==7
        mov     bx,0ch
.else
        mov     bx,0ah
.endif

·|³Q²ÕĶ¾¹²ÕĶ¦¨©³¤U³o¬qµ{¦¡¡G

        CMP    CX,+07
        JNZ    N1
        MOV    BX,000C
        JMP    N2
N1:     MOV    BX,000A
N2:

.IF/ENDIF §PÂ_¦¡¤]¥i¥H¥ÎºX¼Ðªí¥Ü¡C¨Ò¦p ZERO?¡BCARRY?¡BOVERFLOW?¡BSIGN? ©Î PARITY?¡A¤À§Oªí¥Ü¹sºX¼Ð¡B¶i¦ìºX¼Ð¡B·¸¦ìºX¼Ð¡B²Å¸¹ºX¼Ð©Î¦P¦ìºX¼Ð³Q³]©w®É¬°¯u¡A¨Ò¦p¤U­±ªº¨Ò¤l¬O¹sºX¼Ð³Q³]©w®É¡A«h¨Ï AX ¼W¥[¤@¡G

.IF ZERO?
        inc     ax
.ENDIF

¥ÎºX¼Ð§@¬°§PÂ_¦¡¡A¤£¶È .IF/.ENDIF ¥i¥H¡A.WHILE/.ENDW ©Î©³¤U±N­n¤¶²Ðªº .REPEAT/.UNTIL ¤]³£¥i¥H¦p¦¹¡C

.REPEAT/.UNTIL

³o¤@¹ï°²«ü¥O©M C/C¡Ï¡Ï ªº DO °j°é¤@¼Ë¡A¦b MASM ùØ¡A.REPEAT/.UNTIL ªº»yªk¬O¡G

.REPEAT
        µ{¦¡
.UNTIL  §PÂ_¦¡

³o¬qµ{¦¡½X·|¤@ª½­«½Æ¦b .REPEAT ¨ì .UNTIL ¤§¶¡ªºµ{¦¡¡Aª½¨ì§PÂ_¦¡¬°¯u¬°¤î¡C.REPEAT/.UNTIL »P .WHILE/.ENDW «Ü¹³¡A¦ýµy¦³¤£¦P¡C.REPEAT/.UNTIL ·|¥ý°õ¦æ¨ä¤¤ªºµ{¦¡¤@¦¸¡AµM«á¦A§PÂ_ .UNIT «áªº¯u°°¡A¥H¨M©w¬O§_­«½Æ¦A°õ¦æ¤@¦¸¡F¦Ó .WHILE/.ENDW «h·|¥ý§PÂ_ .WHILE «áªº¯u°°¡A¨M©w¬O§_°õ¦æ¨ä¤ºªºµ{¦¡¡C

§PÂ_¦¡¤¤ªº¦³¸¹¼Æ

¤W­z¤TºØ±ø¥ó¸õÅD©Î°j°é¡A³£»Ý­n§PÂ_¦¡¡A¦b¤º©w±¡§Î¤U¡AMASM ³£·|§â¦b§PÂ_¦¡¤¤ªºÅܼƩμȦs¾¹·í¦¨¥¿¼Æ ( µL¸¹¼Æ ) ¨Ó§@§PÂ_¡C¦ý¬O¦pªG­n¨ÏÅܼƩμȦs¾¹·í¦¨¦³¸¹¼Æ¨Ó§PÂ_®É¡A¥i¥H¦b«e­±¥[¤W SBYTE PTR¡BSWORD PTR¡BSDWORD PTR ±j­¢¨Ï¨äÅܦ¨¦³¸¹¼Æ¡C¨Ò¦p¤U­±ªº¨Ò¤l¬O§PÂ_ AX ¬O§_¤j©ó¹s¡A¦pªG¤£¬O¨º»ò¨C¦¸¥[¤W 7¡Aª½¨ì AX ¤j©ó¹s¬°¤î¡G

        mov     bx,7
.while  sword ptr ax<0  ;­Y AX<0¡A¥[¤W 7 ª½¨ì AX>0
        add     ax,bx
.endw

«Ü©úÅ㪺¡ASBYTE PTR¡BSWORD PTR¡BSDWORD PTR ³o¨Ç¸ê®Æ§ÎºA¤§«e«a¥H¡yS¡z¡A³o¡yS¡zªí¥Ü²Å¸¹ ( sign ) ¤§·N¡C

.BREAK .IF »P .CONTINUE .IF

¦b .WHILE/.ENDW ©Î .REPEAT/.UNTIL °j°éùØ¡A¦pªG¦³¨ä¥L±¡§Î¤]­n°h¥X°j°é®É¡A¤]¥i¥H¥[¤W .BREAK .IF °²«ü¥O¡A±j¨î°h¥X°j°é¡Aªí¥Ü¥u¦³¦b .IF ¤§«áªº±ø¥ó¬°¡y¯u¡z®É¡A¤~°h¥X°j°é¡C¨Ò¦p¡J

.WHILE 1
        lodsw
.BREAK  .IF     !AX
        add     ax,bx
.ENDW

¤W­±³o­Ó¨Ò¤l¬O§â SI ©Ò«üªº°O¾ÐÅé¼Æ­È²¾¤J AX ¤¤¡A¦P®É SI ¦Û°Ê«ü¦V¤U¤@¦ì§}¡A¨Ã¨Ï BX ¤§¼Æ­È»P AX ¬Û¥[¡A¦A¦s¤J AX ùØ¡Aª½¨ì AX µ¥©ó¹s®É°h¥X .WHILE/.ENDW °j°é¡C

.CONTINUE .IF «h¬O¦b .IF ¤§«áªº±ø¥ó¬°¯u®É¡A·|¸õ¨ì .WHILE/.ENDW ©Î .REPEAT/.UNTIL °j°é¶}©l³B°õ¦æ¡C¨Ò¦p¤U­±¬O¤@­Ó¿é¤J¼Æ¦r¦r¦êªºµ{¦¡¡A·í¨Ï¥ÎªÌ¤£¬O«ö 0¡ã9 ªºªü©Ô§B¼Æ¦r®É¡A·|¸õ¦^°j°é°_©l³B¡AÄ~Äòµ¥«Ý¨Ï¥ÎªÌ¿é¤J¼Æ¦r¡F¦pªG¨Ï¥ÎªÌ«ö¤U Enter Áä ( ASCII ½X¬° 0DH ) ©Î Esc Áä ( ±½´y½X¬O 01 ) ®É¡A¸õ¥X°j°é¡C

.REPEAT
        mov     ah,0
        int     16h
.BREAK .IF al==0dh
.CONTINUE .IF (al<='0')||(al>='9')
        stosb
.UNTIL ah==1

½d¨Ò¡GCALENDAR.ASM

·Ó¨Ò¡A¤p¤ì°¸¼g­Óµ{¦¡¡A·í°µ¬O³o³¹ªº½d¨Ò¡C³o­Óµ{¦¡ºÙ¬° CALENDAR.ASM¡A¥¦¬OÅã¥Ü¦è¤¸¬Y¦~¬Y¤ëªº¤ë¾äµ{¦¡¡C±ý¹F¦¹¥Øªº¡A³Ì¦³½ìªº¤@­Ó°ÝÃD¬O­pºâ³o­Ó¤ëªº²Ä¤@¤Ñ¬O¬P´Á´X¡A¦³Ãö³o­Ó°ÝÃDªº­ì²z¡A½Ð°Ñ¦Ò Calvin Shing ªº¤Ñ¤å¾äªkºô¯¸¡ACalvin Shing ªººô¯¸¦³¸Ô²Óªº»¡©ú¡A¤p¤ì°¸´N¤£¦A´y­z¤F¡C

CALENDAR.ASM ·|¥Î¨ì¥|­Ó°Æµ{¦¡¡A¤À§O¬O¥Î¨Ó¦b¿Ã¹õ¬Y³B¦L¥X¦r¦êªº print_string °Æµ{¦¡¡B¦b¿Ã¹õ¬Y³B¦L¥X¤@­Ó¦r¤¸ªº print_char °Æµ{¦¡¡B¥i¥H¿é¤J 64 ¦ì¤¸¾ã¼Æªº input °Æµ{¦¡»P¦L¥X AL ¼È¦s¾¹ªº¤º®e¡C³o¥|­Ó°Æµ{¦¡«Ü¦³¥Î¡A¦]¦¹¤p¤ì°¸§â¥¦¿W¥ß¥X¨Ó¡AÅܦ¨ STR_NUM.ASM¡AµM«á¦A¥[¤J§Ú­Ì­ì¦³ªºµ{¦¡®w MYASMLIB.LIB ùØ¡C¥t¥~¦b¿Ã¹õ¤WÅã¥Üªº¤å¦rÃC¦â¡A¹³¬OÂŦr¶Â©³¥Î 09H ( ½Ð°Ñ¦Òªþ¿ý¤C )¡A³o¨Ç¼Æ­È¤£©ö¤@¥Ø¤FµM¡A¦]¦¹¥i¥H¥Î¤@±`¼Æªí¥Ü¡A¦Ó±`¼Æ¦W«h¨ú¬° blue_on_black¡A´N¥i±æ¤å¥Í¸q¤F¡A¤p¤ì°¸§â³o¤@³¡¥÷Åܦ¨¤@­Ó MYASMINC.INC §t¤JÀÉ¡C¦¹¥~¦U¥~³¡°Æµ{¦¡ªº«Å§i¡A¤]¥i©ñ¤J§t¤JÀɤ¤¡A³o¼Ë¤]¥iÁקK°Æµ{¦¡®w­×§ï®É¡A¤Z¬O¥Î¨ì¸Ó°Æµ{¦¡ªº­ì©lÀɤ]¸òµÛ¬Û§ï¡C

­ì©l½X

©³¤U¬O§t¤JÀÉ MYASMINC.INC ªº­ì©l½X¡G

black_on_black   equ    000h    ;¶Â©³¶Â¦r
navy_on_black    equ    001h    ;¶Â©³²`ÂŦr
green_on_black   equ    002h    ;¶Â©³²`ºñ¦r
cyan_on_black    equ    003h    ;¶Â©³«C¦r
maroon_on_black  equ    004h    ;¶Â©³¬õ¦r
purple_on_black  equ    005h    ;¶Â©³µµ¦r
brown_on_black   equ    006h    ;¶Â©³´Ä¦r
silver_on_black  equ    007h    ;¶Â©³»È¦r
gray_on_black    equ    008h    ;¶Â©³¦Ç¦r
blue_on_black    equ    009h    ;¶Â©³ÂŦr
lime_on_black    equ    00ah    ;¶Â©³«Gºñ¦r
aqua_on_black    equ    00bh    ;¶Â©³«G«C¦r
red_on_black     equ    00ch    ;¶Â©³«G¬õ¦r
fushisa_on_black equ    00dh    ;¶Â©³¯»¬õ¦r
yellow_on_black  equ    00eh    ;¶Â©³«G¶À¦r
white_on_black   equ    00fh    ;¶Â©³¥Õ¦r
black_on_navy    equ    010h    ;²`ÂÅ©³¶Â¦r
navy_on_navy     equ    011h    ;²`ÂÅ©³²`ÂŦr
green_on_navy    equ    012h    ;²`ÂÅ©³²`ºñ¦r
cyan_on_navy     equ    013h    ;²`ÂÅ©³«C¦r
maroon_on_navy   equ    014h    ;²`ÂÅ©³¬õ¦r
purple_on_navy   equ    015h    ;²`ÂÅ©³µµ¦r
brown_on_navy    equ    016h    ;²`ÂÅ©³´Ä¦r
silver_on_navy   equ    017h    ;²`ÂÅ©³»È¦r
gray_on_navy     equ    018h    ;²`ÂÅ©³¦Ç¦r
blue_on_navy     equ    019h    ;²`ÂÅ©³ÂŦr
lime_on_navy     equ    01ah    ;²`ÂÅ©³«Gºñ¦r
aqua_on_navy     equ    01bh    ;²`ÂÅ©³«G«C¦r
red_on_navy      equ    01ch    ;²`ÂÅ©³«G¬õ¦r
fushisa_on_navy  equ    01dh    ;²`ÂÅ©³¯»¬õ¦r
yellow_on_navy   equ    01eh    ;²`ÂÅ©³«G¶À¦r
white_on_navy    equ    01fh    ;²`ÂÅ©³¥Õ¦r

cr               equ    0dh
lf               equ    0ah
carriage_return  equ    cr
line_feed        equ    lf

print_char      proto   near :byte,:word,:word
print_string    proto   near :word,:word,:word
input           proto   near :word,:word,:word,:word
print_al        proto   near :word,:word
print_ax        proto   near :word,:word

©³¤U¬O STR_NUM.ASM ªº­ì©l½X¡G

;§@¬°µ{¦¡®wªº­ì©lÀÉ

        .model  tiny,stdcall
        .386
        public  print_char,print_string,input
        public  print_al,print_ax

include myasminc.inc

;***********************************************************
code    segment byte    public  'code'  use16
        assume  cs:code
;-----------------------------------------------------------
;¦L¥X¦r¤¸
;
;¥Îªk¡G invoke  print_char,¦r¤¸,ÃC¦â,¦ì¸m
;
;       ¦r¤¸¡G¤@­Ó¦ì¤¸²Õªø¡AASCII ¦r¤¸
;       ÃC¦â¡G¤@­Ó¦r²Õªø«×¡A¸û°ª 8 ¦ì¤¸¥²¶·¬°¹s¡A¸û§C 8 ¦ì¤¸ªº¦â½X¦p¤U
;             00¡Ð¶Â¦â¡F01¡ÐÂŦâ¡F02¡Ðºñ¦â¡F03¡Ð«C¦â¡F04¡Ð¬õ¦â
;             05¡Ðµµ¦â¡F06¡Ð´Ä¦â¡F07¡Ð»È¦â¡F08¡Ð¦Ç¦â¡F09¡Ð«GÂÅ
;             0A¡Ð«Gºñ¡F0B¡Ð«G«C¡F0C¡Ð«G¬õ¡F0D¡Ð«Gµµ¡F0E¡Ð¶À¦â
;             0F¡Ð¥Õ¦â
;       ¦ì¸m¡G¸û°ª 8 ¦ì¤¸ªí¥Ü¦C ( y )¡A¸û§C 8 ¦ì¤¸ªí¥Ü¦æ ( x )
;¿é¥X¡GDX «ü¦V¤U¤@­Ó¦ì¸m
print_char      proc    near uses ax bx cx,
                        char:BYTE,color:WORD,p_xy:WORD
        mov     ah,2
        mov     dx,p_xy
        mov     bx,color
        int     10h
        mov     al,char
        mov     ah,9
        mov     cx,1
        int     10h
        inc     p_xy
        mov     ah,2
        mov     dx,p_xy
        int     10h
        ret
print_char      endp
;-----------------------------------------------------------
;¦L¥X¦r¦ê¡A¨Ã²M°£¦r¦ê«áªº¿Ã¹õ¤º®e
;
;¥Îªk¡G invoke  print_string,¦r¦ê¦ì§},ÃC¦â,¦ì¸m
;
;       ¦r¦ê¦ì§}¡G­n¦C¦L¦r¦êªº¦s©ñ°¾²¾¦ì§}¡A°Ï¬q¦ì§}©T©w¬° DS
;                 ¡A¥B¦r¦ê¥H'$'µ²§ô¡C
;       ÃC¦â¡G¤@­Ó¦r²Õªø«×¡A¸û°ª 8 ¦ì¤¸¥²¶·¬°¹s¡A¸û§C 8 ¦ì¤¸ªº¦â½X¦p¤U
;             00¡Ð¶Â¦â¡F01¡ÐÂŦâ¡F02¡Ðºñ¦â¡F03¡Ð«C¦â¡F04¡Ð¬õ¦â
;             05¡Ðµµ¦â¡F06¡Ð´Ä¦â¡F07¡Ð»È¦â¡F08¡Ð¦Ç¦â¡F09¡Ð«GÂÅ
;             0A¡Ð«Gºñ¡F0B¡Ð«G«C¡F0C¡Ð«G¬õ¡F0D¡Ð«Gµµ¡F0E¡Ð¶À¦â
;             0F¡Ð¥Õ¦â
;       ¦ì¸m¡G¸û°ª 8 ¦ì¤¸ªí¥Ü¦C ( y )¡A¸û§C 8 ¦ì¤¸ªí¥Ü¦æ ( x )
;¿é¥X¡GDX¡Ð«ü¦V¤U¤@­Ó¦ì¸m
print_string    proc    near,
                        addr_str:WORD,attrib:WORD,posi:WORD
        pusha
        mov     si,addr_str
        mov     dx,posi
        mov     cx,1
        mov     bx,attrib
@@:     lodsb
        mov     ah,2
        int     10h     ;³]©w´å¼Ð¦ì¸m
        cmp     al,'$'  ;­Y¬° '$' «h¦r¦ê¤w¦L§¹
        je      @f
        invoke  print_char,al,bx,dx
        jmp     @b
@@:     mov     cx,79   ;²M°£¦r¦ê«áªº¿Ã¹õ
        sub     cl,dl
        mov     ax,920h
        mov     bx,attrib
        mov     posi,dx
        int     10h
        popa
        mov     dx,posi
        ret
print_string    endp
;-----------------------------------------------------------
;¦L¥X AL ¤º¤§¤Q¤»¶i¦ì¼Æ­È
;
;¥Îªk¡G invoke  print_al,ÃC¦â,¦ì¸m
;
;       ÃC¦â¡B¦ì¸m¡G¦P print_string
print_al        proc    near uses ax,
                        al_color:word,al_posi:word
        mov     ah,al
        shr     al,4
        add     al,'0'
        cmp     al,'9'
        jbe     @f
        add     al,7
@@:     invoke  print_char,al,al_color,al_posi
        mov     al,ah
        and     al,0fh
        add     al,'0'
        cmp     al,'9'
        jbe     @f
        add     al,7
@@:     invoke  print_char,al,al_color,dx
        ret
print_al        endp
;-----------------------------------------------------------
;¦L¥X AX ¤º¤§¤Q¤»¶i¦ì¼Æ­È
;
;¥Îªk¡G invoke  print_ax,ÃC¦â,¦ì¸m
;
;       ÃC¦â¡B¦ì¸m¡G¦P print_string
print_ax        proc    near uses ax,
                        ax_color:word,ax_posi:word
        push    ax
        mov     al,ah
        invoke  print_al,ax_color,ax_posi
        pop     ax
        invoke  print_al,ax_color,dx
        ret
print_ax        endp
;-----------------------------------------------------------
;±µ¦¬¿é¤Jªº¼Æ¦r
;
;¥Îªk¡G invoke  input,³Ì¤j¿é¤Jªº¦ì¼Æ,¶i¦ì¨î,ÃC¦â,¦ì¸m
;
;       ³Ì¤j¦ì¼Æ¡G¨Ï¥ÎªÌ³Ì¦h¥u¯à¿é¤Jªº¦ì¼Æ¡A³Ì¤j¬° 16
;       ¶i¦ì¨î¡G10D ªí¤Q¶i¦ì¨î¡A10H ªí¤Q¤»¶i¦ì¨î
;       ¦ì¸m»PÃC¦â¡G¨Ï¥ÎªÌ¨C¿é¤J¤@­Ó¼Æ¦r¡A·|Åã¥Ü¦b¿Ã¹õ¤Wªº¦ì¸m»PÃC¦â
;¿é¥X¡GNC¡Ð¨Ï¥ÎªÌ¿é¤J¥¿½T¡A¦¹®É EDX:EAX ¬°¿é¤Jªº¤Q¤»¶i¦ì¼Æ¥Ø
;      CY¡Ð¨Ï¥ÎªÌ«ö Esc Áä¨ú®ø¿é¤J
input   proc    near uses bx cx si di,
                n:WORD,rdx:WORD,char_color:WORD,position:WORD
        local   key_buffer[16]:BYTE
        mov     cx,16
        cmp     n,cx
        ja      ipt8

        lea     si,key_buffer
@@:     mov     byte ptr ss:[si],0      ;³]©w key_buffer ªì©l­È¬° 0
        inc     si
        loop    @b

        mov     dx,position     ;CX=¨Ï¥ÎªÌ¤w¸g¿é¤Jªº¦ì¼Æ
                                ;DX=¿Ã¹õ¦ì¸m
;DI=¨Ï¥ÎªÌ¿é¤Jªº¼Æ¦r¦s¤J¦ì§}¡A¨Ò¦p¨Ï¥ÎªÌ¿é¤J ¡y1¡z¡B¡yF¡z¡B¡y8¡z¡B
;¡yEnter¡z¡A«h key_buffer Åܬ° 01¡B0F¡B08¡B00¡B00¡B00¡K¡K
        lea     si,key_buffer
ipt1:   mov     ah,0
        int     16h
        cmp     ah,01   ;¨Ï¥ÎªÌ¬O§_«ö¤U Esc Áä
        je      ipt8
        cmp     al,cr   ;¨Ï¥ÎªÌ¬O§_«ö¤U Enter Áä
        je      ipt4
        cmp     al,8    ;¨Ï¥ÎªÌ¬O§_«ö¤U­Ë°hÁä
        je      ipt6
        mov     bl,'0'
        cmp     al,bl   ;Àˬd¨Ï¥Î«ö¤UªºÁä¬O§_¤p©ó
        jb      ipt1    ;30H¡A­Y¤p©ó«h­«·s¿é¤J
        cmp     al,'9'  ;Àˬd¨Ï¥Î«ö¤UªºÁä¬O§_¦b 30H¡ã39H ¤§¶¡
        jbe     ipt2    ;­Y¬O¡A«h¸õ¨ì ipt2:
        cmp     rdx,10d ;Àˬd¤Q¶i¦ì¨îÁÙ¬O¤Q¤»¶i¦ì¨î¡A­Y¬°¤Q¶i¦ì¨î
        je      ipt1    ;¨Ï¥ÎªÌ¥u¯à¿é¤J 0¡ã9¡AEsc¡BEnter¡BBS Áä
        cmp     rdx,10h ;­Y¬°¤Q¤»¶i¦ì¨î¡A«h¨Ï¥ÎªÌÁÙ¥i¿é¤J A¡ãF Áä
        jne     ipt8
        and     al,0dfh ;¨Ï¥ÎªÌ«ö¤U 39H ¥H«áªºÁä¡A¥B¥Î¤Q¤»¶i¦ì¨î¿é¤J
        cmp     al,'A'  ;Àˬd¬O§_¦b A¡ãF ¤§¶¡
        jb      ipt1
        cmp     al,'F'
        ja      ipt1
        mov     bl,37h
ipt2:   invoke  print_char,al,char_color,dx     ;¨Ï¥ÎªÌ¿é¤J A¡ãF Áä
        sub     al,bl
ipt3:   mov     ss:[si],al
        inc     si
        inc     cx      ;¨Ï¥ÎªÌ¿é¤J¦ì¼Æ¼W¤@¡A¤§«á©M³Ì¤j¿é¤Jªº¦ì¼Æ¤ñ¸û
        cmp     cx,n
        jne     ipt1

;¨Ï¥ÎªÌ«ö¤U Enter Áä¡A§¹¦¨¿é¤J¡A±µ¤U¨Ó±o§â¿é¤J©Ò±oªº¦r¦ê¡AÂà´«¦¨¼Æ­È¡A
;¨Ã¦s©ó EDX:EAX ùØ¡C­Y CX=0¡Aªí¥Ü¨Ï¥ÎªÌ¨S¦³¿é¤J¥ô¦ó¼Æ¦r¡A´N«ö¤U Enter Áä
ipt4:   jcxz    ipt8
        lea     si,key_buffer
        sub     eax,eax
        mov     edi,10
        mov     edx,eax ;EDX:EAX ±N¦s©ñ¨Ï¥ÎªÌ¿é¤Jªº¼Æ­È
ipt5:   movzx   ebx,byte ptr ss:[si]
        inc     si
.if rdx==10d            ;¨Ï¥ÎªÌ¿é¤J¤Q¶i¦ì
        mul     edi
        add     eax,ebx
        adc     edx,0
.elseif rdx==10h
        shld    edx,eax,4
        shl     eax,4
        add     eax,ebx
.else
        jmp     short ipt8
.endif
        loop    ipt5
        clc             ;¨Ï¥ÎªÌ¿é¤J¥¿±`¼Æ¦rÂ÷¶}¡A¥O¶i¦ìºX¼Ð¬° NC
        jmp     short ipt9

;¨Ï¥ÎªÌ«ö BackSpace Áä
ipt6:   jcxz    ipt7    ;Àˬd¬O§_ÁÙ¨S¿é¤J¡A´N«ö BackSpace Áä
        dec     dx
        invoke  print_char,' ',char_color,dx
        dec     dx
        mov     ah,2
        mov     bh,0
        int     10h
        dec     si
        dec     cx
ipt7:   jmp     ipt1

ipt8:   stc             ;¨Ï¥ÎªÌ¨ú®ø¿é¤J¡A¥O¶i¦ìºX¼Ð¬° CY
ipt9:   ret
input   endp
;-----------------------------------------------------------
code    ends
;***********************************************************
        end     print_char

©³¤U¬O CALENDAR.ASM ªº­ì©l½X¡G

;Åã¥Ü¬Y¦~¬Y¤ëªº¤ë¾ä
;¥²¶·¥H MASM 6.0 ¥H¤Wª©¥»²ÕĶ
        .model  tiny,stdcall
        .386

include         myasminc.inc
includelib      myasmlib.lib

input_color     equ     yellow_on_black
normal_color    equ     lime_on_black
title_color     equ     white_on_black
sunday_color    equ     red_on_black

;***********************************************************
code    segment para    public  'code'  use16
        assume  cs:code,ds:code
        org     100h
start:  jmp     begin
msg0    db      '¿é¤J¤½¤¸¦~¡G$'
msg1    db      '¿é¤J¤ë¥÷¡G$'
msg2    db      '¤é ¤@ ¤G ¤T ¥| ¤­ ¤»$'
year    dw      ?
month   dw      ?
day     dw      ?       ;¨Ï¥ÎªÌ©Ò¿é¤J¤ë¥÷ªº¤Ñ¼Æ
cursor  dw      100h    ;´å¼Ð¦ì¸m ( ¸û°ª 8 ¦ì¤¸ªí¦C¡A¸û§C 8 ¦ì¤¸ªí¦æ )
;day_m ¬O¤@¤ë¨ì 12 ¤ë¡A¨C­Ó¤ëªº¤Ñ¼Æ ( ¥H BCD ¼Æªí¥Ü )
day_m   db      31h,28h,31h,30h,31h,30h,31h,31h,30h,31h,30h,31h
;-----------------------------------------------------------
;­pºâ©Òµ¹ªº®æ°Ç­ô¨½¾ä¡A¨D¥X¸Ó¤é¬O¬P´Á´X
;¥Îªk¡G invoke  day_of_week,year,month,date
;       year ¬O¦è¤¸¦~¥÷¡A¤]´N¬O®æ°Ç­ô¨½¾äªkªº¦~¥÷
;       month ¬O¤ë¥÷¡A1¡ã12
;       date ¬O¤é¡A1¡ã31
;¿é¥X¡GAX¡Ð0¡ã7 ¤À§Oªí¥Ü¬P´Á¤é¡ã¤»
;¤½¦¡¡GZeller's ¤½¦¡
;      W={C/4¡V2*C + Y+ Y/4 + [(13*M¡V1)/5]+D} Mod7
;        a=int((14-month)/12)
;        Y=(year - a)¤§¥½¨â¦ì¼Æ
;        C=¥@¬ö=(year -a)¤§¤d¦ì¼Æ»P¦Ê¦ì¼Æ¡A¨Ò¦p year=2006¡A«h C=20
;        M=month+12a-2
;        D=day
;        ­pºâ¤W­±ªº©Ò¦³°£ªk¹Bºâ®É¡A¥u¨D°Ó¡AµL±ø¥ó±Ë¥h¤p¼Æ
day_of_week     proc    uses bx ,y:WORD,m:WORD,d:WORD
        local   a:WORD
        local   century:WORD
        mov     ax,14
        sub     ax,m
        mov     bl,12
        div     bl
        cbw
        mov     a,ax    ;a=int((14-month)/12)
        sub     y,ax
        mov     ax,y
        mov     bl,100
        div     bl
        movzx   bx,ah   ;BX=year ¤§¥½¨â¦ì¼Æ
        and     ax,0ffh ;AX=¥@¬ö
        mov     y,bx
        mov     century,ax
        mov     bl,12
        mov     ax,a
        mul     bl
        add     ax,m
        inc     bl      ;BL=13
        sub     ax,2    ;AX=M=month+12a-2
        mul     bl
        dec     ax
        mov     bl,5
        div     bl
        mov     ah,0    ;AX=int((13M-1)/5)
        add     ax,y
        add     ax,d
        shr     y,2     ;y=int(y/4)
        add     ax,y
        mov     bx,century
        shl     century,1
        shr     bx,2
        add     ax,bx
        sub     ax,century
        mov     bx,7
.while  sword ptr ax<0  ;­Y AX<0¡A¥[¤W 7 ª½¨ì AX>0
        add     ax,bx
.endw
        div     bl
        shr     ax,8    ;AL=W
        ret
day_of_week     endp
;-----------------------------------------------------------
;­pºâ¬Y¦~¬O§_¬°¶|¦~
;
;¥Îªk¡G invoke  leap_year,¦è¤¸¦~
;
;¿é¥X¡G¶|¦~¡AAL=29H¡F¥­¦~¡GAL=28H
leap_year       proc    near stdcall uses bx dx ,year1:word
        sub     dx,dx
        mov     ax,year1
        mov     bx,400
        div     bx
        or      dx,dx
        jz      leap
        mov     ax,year1
        sub     dx,dx
        mov     bx,100
        div     bx
        or      dx,dx
        jz      common
        sub     dx,dx
        mov     bx,4
        mov     ax,year1
        div     bx
        or      dx,dx
        jz      leap
common: mov     al,28h
        jmp     short ly_qut
leap:   mov     al,29h
ly_qut: ret
leap_year       endp
;-----------------------------------------------------------
begin:  mov     ax,600h
        sub     cx,cx
        mov     bh,normal_color
        mov     dx,184fh
        int     10h             ;²M°£¿Ã¹õ

        invoke  print_string,offset msg0,input_color,cursor
        invoke  input,4,10,input_color,dx
        mov     year,ax
        invoke  leap_year,ax    ;Àˬd¬O§_¶|¦~
        mov     bx,1            ;­Y¬°¶|¦~¡A§â¤G¤ë³]¬° 29 ¤Ñ
        mov     day_m[bx],al

        add     cursor,20
        invoke  print_string,offset msg1,input_color,cursor
        invoke  input,2,10,input_color,dx
        mov     bx,ax
        mov     month,ax
        dec     bx
        movzx   ax,day_m[bx]    ;AX=¨Ï¥ÎªÌ©Ò¿é¤J¤ë¥÷ªº¤Ñ¼Æ
        mov     day,ax

        add     cursor,100h
        and     cursor,0ff00h   ;¨Ï´å¼Ð²¾¨ì¤U¤@¦C
        invoke  print_string,offset msg2,title_color,cursor
        invoke  day_of_week,year,month,1

;­pºâ¸Ó¤ë¤@¤é¶}©l¦L¥Xªº¦æ¦ì¸m ( x )¡C¬P´Á¤é¦b¨C¦Cªº²Ä 0 ¦æ¡A¬P´Á¤@¦b²Ä 3 ¦æ
;¬P´Á¡G¤é ¤@ ¤G ¤T ¥| ¤­ ¤»
;¦æ¡G   0  3  6  9 12 15 18
        mov     dx,ax
        mov     bx,ax
        shl     dx,1
        add     dx,bx   ;DX=¸Ó¤ë¤@¤é¶}©l¦L¥Xªº¦æ¦ì¸m ( x )
        mov     ax,1    ;AX=¤é´Á¡A¥Ñ 1 »¼¼W¨ì day
nxt_rw: mov     cx,7    ;CX=¨C¤@¦C­n¦L¥X´X­Ó¤é¤l
        sub     cx,bx   ;CX=¸Ó¤ëªº²Ä¤@­Ó¬P´Á¡AÁÙ¦³´X¤Ñ­n¦L¥X¨Ó
        add     cursor,100h
        and     cursor,0ff00h   ;¨Ï´å¼Ð²¾¨ì¤U¤@¦C
        add     cursor,dx
nxt_d:  
.if cx==7
        mov     dx,sunday_color ;¥H¬õ¦â¦L¥X¬P´Á¤Ñ
.else
        mov     dx,normal_color ;¥Hºñ¦â¦L¥X¨ä¥L¤é¤l
.endif
        push    ax
        invoke  print_al,dx,cursor      ;¦L¥X¤é´Áªº¤Q¦ì¼Æ
        pop     ax
        inc     dx
        add     al,1
        daa
        mov     cursor,dx       ;«ü¦V¤U¤@­Ó¦ì¸m
        cmp     ax,day          ;Àˬd¬O§_¶W¹L day
        ja      exit
        loop    nxt_d
        sub     bx,bx   ;¥u¦³¦b¸Ó¤ëªº²Ä¤@­Ó¬P´Á¡A¥H day_of_week ºâ¥X¿Ã¹õ
        mov     dx,bx   ;°_©l¦ì¸m¡F§_«h BX¡BDX §¡¬°¹s¡A³£¬O±q²Ä 0 ¦æ¶}©l
        cmp     ax,day
        jbe     nxt_rw

exit:   mov     ax,4c00h;ªð¦^ DOS
        int     21h
;-----------------------------------------------------------
code    ends
;***********************************************************
        end     start

²ÕĶ»P³sµ²

³o­Óµ{¦¡µLªk¥Î MASM 5.x ©Î¥H¤Uªºª©¥»²ÕĶ¡A¥²¶·¥Î MASM 6.0 ©Î¥H«áªºª©¥»¡CMASM 6.0 ¤Î¨ä¥H«áª©¥»ªº²ÕĶ¾¹ºÙ¬° ML.EXE¡A¥¦¯à¦b²ÕĶ¤§«á¦Û°Ê¸ü¤J³sµ²¾¹ ( §Y LINK.EXE ) ³sµ²¡A¬°¤F¨¾¤î ML.EXE §ä¤£¨ì LIN.EXE¡A©Ò¥H±o¥ý³]¦n¸ô®|¡C¦]¬°¤p¤ì°¸§â ML.EXE »P LINK.EXE ©ñ¦b I:\MASM611\BIN ¤l¥Ø¿ý¤¤¡A©Ò¥H¥ý³]¦n PATH¡G

E:\HomePage\SOURCE>set path=i:\masm611\bin;path% [Enter]

E:\HomePage\SOURCE>ml /c str_num.asm [Enter]¡@¡@¡÷¦¹¨BÆJ¥[¤W¡y/c¡z¡Aªí¥Ü¥u²ÕĶ¤£³sµ²
Microsoft (R) Macro Assembler Version 6.11
Copyright (C) Microsoft Corp 1981-1993.  All rights reserved.

 Assembling: str_num.asm

E:\HomePage\SOURCE>lib myasmlib [Enter]  ¡÷§â STR_NUM.OBJ ¼Ò²Õ¥[¤J MYASMLIB.LIB ùØ

Microsoft (R) Library Manager  Version 3.20.010
Copyright (C) Microsoft Corp 1983-1992.  All rights reserved.

Operations: +str_num [Enter]
List file: myasmlib.lst [Enter]
Output library: myasmlib [Enter]  ¡÷¨ì¦¹¡A¤w§â STR_NUM ¼Ò²Õ¥[¤Jµ{¦¡®w¤F

E:\HomePage\SOURCE>ml calendar.asm [Enter]
Microsoft (R) Macro Assembler Version 6.11
Copyright (C) Microsoft Corp 1981-1993.  All rights reserved.

 Assembling: calendar.asm

Microsoft (R) Segmented Executable Linker  Version 5.31.009 Jul 13 1992
Copyright (C) Microsoft Corp 1984-1992.  All rights reserved.

Object Modules [.obj]: calendar.obj/t
Run File [what_day.com]: "calendar.com"  ¡÷¨£¤U­±»¡©ú
List File [nul.map]: NUL
Libraries [.lib]: ¡÷¦]¥[¤W includelib¡A¬G¤£¶·«ü©wµ{¦¡®w
Definitions File [nul.def]:

E:\HomePage\SOURCE>

©³¤U¨Ó¬Ý¬Ý³o­Óµ{¦¡¥]§t¤F¨º¨Ç·sªº«ü¥O¡C

.MODEL °²«ü¥O

.MODEL ªº¥\¥Î¸ûÂø¶Ã¡A¨ä»yªk¬O¡G

.MODEL  °O¾ÐÅé¼Ò¦¡ [,µ{¦¡»y¨¥] [,°ïÅ|¿ï¶µ]

°O¾ÐÅé¼Ò¦¡¥i¥H¬O TINY¡BSMALL¡BCOMPACT¡BMEDIUM¡BLARGE¡BHUGE ©Î FLAT µ¥¤CºØùØ­±ªº¤@ºØ¡G

TINY¡G µ{¦¡½X°Ï¬q¡B¸ê®Æ°Ï¬q¡B°ïÅ|°Ï¬qµ¥©Ò¦³°Ï¬q³£­«Å|¡A¤]´N¬O¦bÀ½¦b¦P¤@­Ó°Ï¬qùØ¡C¬G¥þ³¡¤j¤p¤£¯à¶W¹L 64KB¡A¦ý¬Oµ{¦¡¥i¥H¦b°õ¦æ®É°t¸m¶W¹L 64KB ªº°O¾ÐÅé¡C¤]¦]¬°©Ò¦³°Ï¬q³£¦b¦P¤@°Ï¬q¤º¡A¬G©I¥s°Æµ{¦¡§¡¬°ªñµ{©I¥s¡C
«ü©w .model tiny «á¡AML.EXE ·|¦Û°Ê°e /TINY °Ñ¼Æµ¹ LINK.EXE¡A¬G¤£¶·¦b²ÕĶ®É¡A¿é¤J ml /AT °Ñ¼Æ¡C
SMALL¡G ¤@­Óµ{¦¡½X°Ï¬q»P¤@­Ó¸ê®Æ°Ï¬q¡A¥B³o¨â­Ó°Ï¬q¬O¦b¤£¦P°Ï¬qùØ¡C¬G©I¥s°Æµ{¦¡®É¡A¤´¬°ªñµ{©I¥s¡C
MEDIUM¡G ¥i¥H¦³¦h­Óµ{¦¡½X°Ï¬q»P¤@­Ó¸ê®Æ°Ï¬q¡C¬G©I¥s°Æµ{¦¡¥i¥H¬O»·µ{©I¥s¡C
COMPACT¡G¥u¦³¤@­Óµ{¦¡½X°Ï¬q»P¦h­Ó¸ê®Æ°Ï¬q¡C¬G©I¥s°Æµ{¦¡¥u¯à¬Oªñµ{©I¥s¡C
LARGE¡G ¥i¥H¦³¦h­Óµ{¦¡½X°Ï¬q»P¦h­Ó¸ê®Æ°Ï¬q¡C¬G©I¥s°Æµ{¦¡¥i¥H¬O»·µ{©I¥s¡C
HUGE¡G¦h­Óµ{¦¡½X°Ï¬q»P¦h­Ó¸ê®Æ°Ï¬q¡C¬G©I¥s°Æµ{¦¡¥i¥H¬O»·µ{©I¥s¡C
FLAT¡G µ{¦¡½X°Ï¬q¡B¸ê®Æ°Ï¬q¡B°ïÅ|°Ï¬qµ¥©Ò¦³°Ï¬q³£­«Å|¡A¤]´N¬O¦bÀ½¦b¦P¤@­Ó°Ï¬qùØ¡A¦ý¬O©ó¦¹¼Ò¦¡®É¡A¬O¥H 32 ¦ì¤¸ªº©w§}¼Ò¦¡¡A©Ò¥H³o­Ó°Ï¬qªø 4GB¡A¤@¯ë¦b Win32 ¨t²Î¤¤ªºÀ³¥Îµ{¦¡Äݩ󦹼Ҧ¡¡C
¦b«ü©w .model flat «e¡A±o¥ý«ü©w .386 ©Î¤ñ¨ä¸û°ªµ¥¯Åªº CPU ¤~¥i¨Ï¥Î FLAT ¼Ò¦¡¡C

.MODEL ªºµ{¦¡»y¨¥·N¸q»P PROC ¬Û¦P¡A¦¹³B¤£¦h»¡¤F¡C¦pªG PROC ¤§«áªºµ{¦¡»y¨¥¬Ù²¤¡A¨º»ò²ÕĶ¾¹«K·|¥H³o¨à©Ò©w¸qªº§@¬°²ÕĶªº·Ç÷¡C

¤p¤ì°¸°¾¦n *.COM °õ¦æÀÉ¡A¬G¤]§â CALENDAR.ASM ¼g¦¨ *.COM ÀÉ¡A¦]¦¹²ÕĶ®É¦³¨Ç²Ó¸`¦b¦¹»¡©ú¡C¥Ñ¤W­±¡y.model tiny¡zªº»¡©ú¡A¥iª¾¨Ã¤£¬O©Ò¦³­ì©l½X³£¥i¥H²ÕĶ¦¨ *.COM °õ¦æÀÉ¡A¥u¦³µ{¦¡½X°Ï¬q¡B¸ê®Æ°Ï¬q¡B°ïÅ|°Ï¬qµ¥©Ò¦³°Ï¬q³£¦b¦P¤@°Ï¬qªº­ì©l½X¤~¥i²ÕĶ¦¨ *.COM °õ¦æÀÉ¡C¦pªG¦b­ì©l½X¤¤¡A¦³«ü©w¡y.model tiny¡z¡A¨º»ò¦b²ÕĶ®É¡AML.EXE ·|¦Û°Ê»s§@¥X *.COM ¨Ó¡F¦pªG­ì©l½X¤¤¨S¦³«ü©w¡y.model tiny¡z¡A¨º»ò¤]¥i¥H¦b©R¥O´£¥Ü²Å¸¹¿é¤J

E:\HomePage\SOURCE>ml /AT ­ì©lÀɦW.ASM {Enter]

¨Ó»s§@ *.COM¡A°Ñ¼Æ¡y/AT¡z«üªº´N¬O¡yEnable tiny model ¡z¤§·N¡C·íµM¡A¤£½×¨º¤@ºØ¤èªk¡A©Ò¦³ªº°Ï¬q³£¥²¶·­«Å|¦b¦P¤@°Ï¬q¤~¯à²£¥Í *.COM¡C

INCLUDE °²«ü¥O

·í§Ú­Ì»s§@µ{¦¡®w®É¡A¦³¨Ç±`¼Æ©Î°Æµ{¦¡ªº«Å§i·|¦P®É¥X²{¦b°Æµ{¦¡­ì©lÀÉ»P¥Dµ{¦¡­ì©lÀÉùØ¡A¹³³o­Ó¨Ò¤lªºÃC¦â¡C¦b³oºØ±¡§Î¤U¡A¦pªG­n­×§ïµ{¦¡¡A´N¥²¶·¦P®É­×§ï°Æµ{¦¡»P¥Dµ{¦¡ªº­ì©lÀÉ¡A³o¼Ë«Ü¤£¤è«K¡A©ó¬O§t¤JÀÉ´N¥¥¨|¦Ó¥Í¤F¡C

¤@¯ë§t¤JÀɪº°ÆÀɦW¬O¡y*.INC¡z¡A¦b MASM 6.x ªºª©¥»ùØ¡A¤]¤ä´©§t¤JÀÉ¡C¨ä»yªk¬O¡G

        include     §t¤JÀɦW

§t¤JÀɦW¥i¥H¥]§t¸ô®|¡A¥i¥H¥Î¤@¹ï¡y<¡z¡B¡y>¡z¬A°_¨Ó¡A¤]¥i¥H¤£¥Î¡C§t¤JÀɦW¥²¶·¬O§¹¾ãªº¡A²ÕĶ¾¹¨S¦³¤º©wªº°ÆÀɦW¡C¨Ò¦p¡A¦pªG±zªº include °²«ü¥O¬O

        include     color

ªí¥Ü±z¬O­n§â color ÀÉ¡A¦Ó¤£¬O color.inc ©Î¨ä¥L color.txt ¡K¡KÀÉÅn¬A¶i¨Ó¡C¦pªG±z¨S¦³¦b§t¤JÀɦW«ü©w¸ô®|¡A¨º»ò ML.EXE ·|¥ý¦b¥Ø«eªº¥Ø¿ý¤¤´M§ä§t¤JÀÉ¡A¦pªG¨S§äµÛ¡A·|¨ì±z¦b©R¥O´£¥Ü²Å¸¹©Ò¿é¤Jªº¡y/I¡z°Ñ¼Æ«áªº¸ô®|¥h§ä¡A¦pªG¤]¨S§äµÛªº¸Ü¡A³Ì«á·|¨ìÀô¹ÒÅÜ¼Æ INCLUDE ©Ò«ü©wªº¥Ø¿ýùØ´M§ä¡C

INCLUDELIB °²«ü¥O

INCLUDELIB ¬O§i¶D³sµ²¾¹±N­n»P¨º¤@­Óµ{¦¡®w³sµ²¡A¨ä»yªk¬O¡G

        INCLUDE     µ{¦¡®wÀɦW

µ{¦¡®wÀɦW¥i¥H¤£¥[°ÆÀɦW¡A¤£¥[°ÆÀɦW®É¡AML.EXE ·|¦Û¦æ¥[¤W .LIB ·í°µ°ÆÀɦW¡Cµ{¦¡®wÀɦW¤]¥i¥H¥[¤W§¹¾ãªº¸ô®|¦W¡A¤]¥i¥H¥Î¤@¹ï¡y<¡z¡B¡y>¡z¬A°_¨Ó¡A¤]¥i¥H¤£¥Î¡C°²¦p¦b­ì©lµ{¦¡ùØ¡A¥[¤W³o¤@¹D°²«ü¥O¡A¨º»ò ML.EXE ´N·|¦Û°Ê¦a§âµ{¦¡®wÀɦW¶Çµ¹ LINK.EXE¡A¦]¦¹´N¤£¶·«ü©wµ{¦¡®w¤F¡C

MOVZX »P MOVSX «ü¥O

§^¤H¼¶¼gµ{¦¡®É¡A¦pªG­n§â¤@­Óªø 8 ¦ì¤¸ªºÅܼƲ¾¶i 16 ¦ì¤¸ªº¼È¦s¾¹¤¤¡A¤@¯ë­n¥Î ptr °²«ü¥O¡A¨Ò¦p¡G

centimeter      db      0c8h    ;0c8h=200d
cm_per_meter    db      64h     ;64h=100d
        mov     ax,ptr word centimeter

¦ý³o¼Ë°µÁÙ¤£°÷¡A¦]¬° ptr ¥u¬O©¿²¤ db ªº©w¸q¡A¦Ó§â¥¦¦V°ª¦ì§}ÂX®i¦¨¦r²Õ¡A¦pªG°ª¥¦¤@­Ó¦ì§}ªº°O¾ÐÅ餣¬O¹s¡A¨º»ò¤]·|·Ó¼Ë¦a·h¨ì AX ¤¤¡A©Ò¥H³Ì«á AX Åܦ¨ 64c8h¡C¦pªG¯u­n¥u·h²¾ centimeter¡A¦Ó¨Ï°ª¦ì¤¸²Õ¬°¹s¡A¦b 80386 ¤§«eªº CPU ±o¦A¥[¤W¡ymov ah,0¡z¡A¦ý 80386 ¤Î¨ä¥H«áªº CPU ¦³¨â±ø·sªº«ü¥O¡AMOVZX ©M MOVSX¡A¥i¥H¹F¨ì¥Øªº¡CMOVZX ©M MOVSX ªº»yªk¬O¡G

        movzx   r32,r8/m8
        movzx   r32,r16/m16
        movzx   r16,r8/m8

        movsx   r32,r8/m8
        movsx   r32,r16/m16
        movsx   r16,r8/m8

r8¡Br16¡Br32 ¤À§Oªí¥Ü 8¡B16¡B32 ¦ì¤¸ªº¼È¦s¾¹¡Am8¡Bm16 ¤À§Oªí¥Ü 8¡B16 ¦ì¤¸ªºÅÜ¼Æ ( m ªí¥Ü°O¾ÐÅé¡A¦]¬°ÅܼƳ£¦s¦b°O¾ÐÅ餤 )¡CMSOZX «ü¥Oªº¥Øªº¬O§â«á­±ªº¸ûµuªº¼È¦s¾¹©ÎÅܼƤ§­È²¾¨ì«e­±¸ûªøªº¼È¦s¾¹¤¤¡A¥B¨Ï¸ûªø¼È¦s¾¹¤¤¸û°ªªº©Ò¦³¦ì¤¸³£¬°¹s¡F¦Ó MOVSX «h¬O¨Ï¦³¸¹¼Æ¦b·h²¾«áµ²ªG¤´¬°¦³¸¹¼Æ¡A¥ç§Yµø²Ä¤G­Ó¹Bºâ¤¸ªº³Ì°ª¦ì¤¸¬O§_¬° 1¡A¨M©w¬O§_§â¸ûªø¼È¦s¾¹ªº¸û°ª¦ì¤¸³£¶ñ¤J 1¡C¨Ò¦p¦³¬qµ{¦¡¡G

        mov     bl,88h
        mov     bh,70h
        movzx   eax,bl
        movsx   ecx,bl
        movsx   edx,bh

°õ¦æ§¹«á¡AEAX=00000088H¡AECX ¬° 0FFFFFF88H¡AEDX ¬° 00000070H¡CMOVZX¡BMOVSX ¦b§â¸ûµu¦ì¤¸ªº¼È¦s¾¹ÂX®i¦¨¸ûªø¦ì¤¸ªº¼È¦s¾¹«Ü¦³¥Î¡A«Ü©úÅ㪺¡yZ¡zªí¥Ü ZERO ¤§·N¡AMOVZX ¬O°µµL¸¹¼ÆªºÂX®i¡F¡yS¡z¬O SIGN ¤§·N¡A¬O°µ¦³¸¹¼ÆªºÂX®i¡C

SHLD »P SHRD «ü¥O

SHLD «ü¥Oªº»yªk¬O¡G

        SHLD    r/m16,r16,imm8
        SHLD    r/m16,r16,CL
        SHLD    r/m32,r32,imm8
        SHLD    r/m32,r32,CL

¤W¦¡ r16¡Br32 ¤À§O¬O 16¡B32 ¦ì¤¸ªº¼È¦s¾¹¡Am16¡Bm32 ¤À§O¬O 16¡B32 ¦ì¤¸ªº°O¾ÐÅéÅܼơAimm8 ¬O 8 ¦ì¤¸ªº¥ß§Y­È ( ±`¼Æ )¡CSHLD ¤j·§¬O¤Ö¼Æ¦³¤T­Ó¹Bºâ¤¸ªº 80x86 «ü¥O¡A¨ä§@¥Î¬O¨Ï²Ä¤G­Ó¹Bºâ¤¸ ( ºÙ¬°¨Ó·½¹Bºâ¤¸ ) ¦V¥ª²¾¼Æ­Ó¦ì¤¸¨ì²Ä¤@­Ó¹Bºâ¤¸ ( ºÙ¬°¥Øªº¹Bºâ¤¸ ) ùØ¡C­n¥ª²¾ªº¦ì¤¸¼Æ¦b²Ä¤T­Ó¹Bºâ¤¸ªí¥Ü¡A¥i¥H¬O±`¼Æ¤]¥i¥H©ñ¦b CL ¼È¦s¾¹¤¤¡A¦ý¤£½×¬O¨º¤@ºØ¡A¨ä¼Æ­È¥u¯à¦b 0¡ã31 ½d³ò¤º¡C³o­Ó«ü¥O¹Bºâ§¹«á¡A¨Ó·½¹Bºâ¤¸ªº¼Æ­È¤£§ïÅÜ¡C¨Ò¦p©³¤Uªºµ{¦¡¤ù¬q¡G

        mov     edx,12345678h
        mov     eax,9abcdef0h
        shld    edx,eax,4

¦]¬°¥ª²¾ 4 ­Ó¦ì¤¸¡A¬Û·í©ó 16 ¶i¦ì¨îªº¤@¦ì¼Æ¡A©Ò¥H«Ü®e©ö¥i±o°õ¦æ§¹«á EDX Åܬ° 23456789H¡AEAX ¤´¬° 9abcdef0¡C¥ç§Y EAX ¦V¥ª²¾¤@¦ì¼Æ ( §Y 4 ¦ì¤¸ )¡A³o¤@¦ì¼Æ³Q²¾¶i¤F EDX ªº­Ó¦ì¼Æ¤F¡C

SHRD ªº»yªk»P§@¥Î©M SHLD ¤@¼Ë¡A¥u¬O§â¥ª²¾§ï¦¨¥k²¾¡C¨Ò¦p¡G

        mov     edx,12345678h
        mov     eax,9abcdef0h
        shrd    edx,eax,4

°õ¦æ§¹ SHRD «á¡AEDX Åܬ° 01234567H¡AEAX ¤´¬° 9abcdef0h¡CEAX ¦V¥k²¾ 4 ¦ì¤¸¡A²¾¥Xªº 4 ¦ì¤¸³Q²¾¶i¤F EDX ³Ì°ªªº 4 ¦ì¤¸ùؤF¡C


«á°O

¦b¼¶¼g³o¤@³¹®É¡A´¿¬°¤@­Ó°ÝÃD§xÂZ¬Æ¤[¡A¨ì²{¦b¤]¤£¯à»¡§¹¥þ¸Ñ¨M¡C¨º´N¬O¦b¤@­Ó¥Dµ{¦¡ùØ¡A¦ü¥GµLªk¦P®É¥H°ïÅ|¶Ç»¼°Ñ¼Æ©M¥H¼È¦s¾¹¶Ç»¼°Ñ¼Æ©I¥s¦bµ{¦¡®wùتº¤£¦P°Æµ{¦¡¡A³o¼Ë°µ·|³y¦¨ LINK ½s¸¹ L2029 ªº¿ù»~¡Aunresolved external¡A¦¹°T®§¬Oµ{¦¡®wùبS³o­Ó°Æµ{¦¡¡C³Ì«á¤p¤ì°¸¥u¦n§â³o³¹©Ò¦³¦bµ{¦¡®wùتº°Æµ{¦¡§ï¦¨¥H°ïÅ|¶Ç»¼¡C

¥t¤@­Ó±`¥Çªº¿ù»~¡A¬O°õ¦æÀɪºÀu¥ý¦¸§Ç¡C·Q¨Ó¤]¬O¦n¯º¡A³o­Ó¿ù»~¥H«e¤]¥Ç¹L¡A¦ý¦b³o³¹ùؤS¦A­«ÁÐÂÐÂá¡A¯Ó¶O¤@¤Ñ°£¿ù¡A«o§ä¤£¨ì¿ù»~¡C«e­±´¿´£¹L¡ADOS ªº¥i°õ¦æÀɦ³ *.COM »P *.EXE ¨âºØ¡A·í¤@­Ó¥Ø¿ýùØ­Y¦³¥DÀɦW¬Û¦P¡A¦ý°ÆÀɦW¤£¦Pªº¥i°õ¦æÀÉ¡ADOS Àu¥ý°õ¦æ COM ÀÉ¡A¨ä¦¸¤~¬O EXE ÀÉ¡C¨Ò¦p¦P¤@¤l¥Ø¿ýùئ³ CALENDAR.COM »P CALENDAR.EXE¡A·í¦b MS-DOS ¼Ò¦¡ªº´£¥Ü²Å¸¹¤U¿é¤J CALENDAR ®É¡A¬O°õ¦æ CALENDAR.COM ¦Ó¤£¬O°õ¦æ CALENDAR.EXE¡A¦Ó¤p¤ì°¸¥ý«e¦³¤@­Ó¿ù»~ªº CALENDAR.COM¡A«á¨Ó·Q²¤Æ¤âÄò¡A§â­ì©l½X§ï¦¨ *.EXE ®æ¦¡¡C¦]°õ¦æ®É¥u­n¿é¤J¥DÀɦW¡A¦ý°£¿ù«o­n¿é¤J DEBUG CALENDAR.EXE¡A§¹¾ãÀɦW¡A©Ò¥Hµ²ªG°õ¦æ°_¨Ó¦Ñ¬O¿ù»~¡A¦ý°£¿ù«oÁ`¬O§ä¤£¨ì¿ù»~¡C


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