Ch 01 ²Ä¤@­Ó²Õ¦X»y¨¥µ{¦¡


²Ä¤@­Óµ{¦¡

DOS ªº¥i°õ¦æÀÉ¥]§t COM¡BEXE ©M BAT ¤TºØÀɮסCBAT ¬O§å¦¸ÀÉ¡A¤£¦b§Ú­Ì°Q½×½d³ò¡FCOM Àɤñ¸û²³æ¡A«e´X­Óµ{¦¡½d¨Ò³£¬O COM ÀÉ¡FEXE ÀÉ¥]§tªíÀY¡A¦]¦¹¤ñ¸û¤j¸ü¤J®É¤]¤ñ¸ûºC(¥i¯à¥uºC¼Æ­Ó²@¬í§a¡H)¡A¸û¬°½ÆÂø¡CÁöµM EXE Àɸû½ÆÂø¡A¦ý¬O¸g²ÕĶ¡B³sµ²«áªºÀɮ׳£·|¥ýÅܦ¨ EXE ÀÉ¡AÁÙ­n°õ¦æÂà´«µ{¦¡( EXE2BIN.EXE )¤~¯àÂà´«¦¨ COM ÀÉ¡C¤£¹L¨Ã¤£¬O©Ò¦³ªº EXE Àɳ£¥i¥HÂà´«¦¨ COM ÀÉ¡C¦]¦¹²{¦b¥ý¨Ó¬Ý¬Ý COM ¥i°õ¦æÀɧa¡C

¨Ì·Ó¤£¦¨¤åªººD¨Ò¡A²Ä¤@­Ó²³æªºµ{¦¡¡A¦ü¥G³£¬O¦b¿Ã¹õ¤W¨q¥X¤@¬q¤å¦r¡A¦]¦¹§Úªº²Ä¤@­Óµ{¦¡¤]¬O¦p¦¹¡C©³¤U´N¬O­ì©lÀɦCªí¡A³oµ{¦¡¤]¬OÅܦ¨ COM ÀÉ«á¦A°õ¦æªº¡G

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
;***************************************
code    SEGMENT                         ;.code ¬q¶}©l¦ì§}
        ASSUME  cs:code,ds:code         ;.°²³]µ{¦¡¬q¤Î¸ê®Æ¬q
        ORG     100h                    ;.¥i§ï¦¨ *.COM ÀÉ
;---------------------------------------
start:  jmp     begin                   ;µ{¦¡¶i¤JÂI
mes     DB      'Hi, I learn assembly.$';­n¦L¥Xªº°T®§
begin:  mov     dx,OFFSET mes           ;«ü¦V mes ªº¦ì§}
        mov     ah,9                    ;©I¥sDOSªA°Èµ{¦¡¡AAH=9/INT 21H ªí¥Ü¦L¥X¦r¦ê
        int     21h                     ;©I¥s DOS ªA°Èµ{¦¡
        mov     ax,4c00h                ;«ü©w­n©I¥sªºªA°È¸¹½X
        int     21h                     ;©I¥s DOS ªA°Èµ{¦¡
;---------------------------------------
code    ENDS                            ;code ¬qµ²§ô
;***************************************
        END     start                   ;¨Ï²ÕĶ¾¹ª¾¹Dµ{¦¡¶i¤JÂI

²ÕĶ¡B³sµ²¡B°õ¦æ

±N¤W­z­ì©l½X¥Î¥ô¦ó¤@­Ó¤å¦r½s¿è¾¹¡]¦pµ§°O¥»©Î UltraEdit 32 ©Î¨ä¥L¤å¦r½s¿è¾¹¡^¼g¦n¤§«á¡A¦s¦¨¯Â¤å¦rÀÉ¡A°²³]ÀɦW¬O EXAM01.ASM ( ·íµM§A¤]¥i¥H¨Ì°ª¿³¥ô·N¨úÀɦW¡A¦ý³sµ²®É­n¥Î¦Û¤vªºÀɦW )¡C¦pªG§A¨Ï¥Î Win 9x/Me¡A½Ð¶}±Ò¡yMS-DOS ¼Ò¦¡¡z¡F¦pªG±z¨Ï¥Î XP/Vista/7¡A½Ð¶}±Ò¡y©R¥O´£¥Ü¦r¤¸¡z¡A²ÕĶªº¤èªk·|ÀH¤£¦Pª©¥»ªº²ÕĶ¾¹¤£¦P¡A¦]¦¹¿ï¾Ü¾A·íªº¤èªk²ÕĶ¡CÁöµM¬O³o¼Ë¡AÁÙ¬O«ØijŪªÌ¨Ì§Ç¬Ý¬Ý MASM 5.0 ¦p¦ó²ÕĶ¡A¦]¬°³o¬O³Ì­ì©lªº¤è¦¡¡C¥t¥~¡A°²¦p±z¤w¸g¦w¸Ë¦nµêÀÀ¾÷¾¹¡AMicrosoft Virtual PC 2007 SP1¡A¤]¤w¦bµêÀÀ¾÷¾¹¦w¸Ë¦n¤F DOS¡A¨º»ò¥i¥H°Ñ¾\ªþ¿ý¤Q¤@¡A¦bµêÀÀ¾÷¾¹¤¤²ÕĶ¡C

¥Î MASM 5.0 ²ÕĶ

¦b DOS ´£¥Ü¤U©Î©R¥O´£¥Ü¦r¤¸ùØ¥ý¤Á´«¨ì­ì©lÀÉ©Ò¦bªº¤l¥Ø¿ý¡A¿é¤J¡y..\masm50\masm exam01;¡z(µù¤@) ²ÕĶ­ì©lÀÉ ( ©³¤U§A­n¿é¤Jªº¤å¦r¥Î¶À¦â¡A·íµM¤£­n§Ñ¤F¿é¤J§¹«á­n«öÁä½L¤Wªº Enter Áä¡C¦¹¥~¦b DOS ¤¤¡A¤j¤p¼g¬O¬Û¦Pªº )¡AMASM.EXE ·|¦Û°Ê±N­ì©lÀɦW¥[¤W ASM¡A©Ò¥H¥i¥H¤£¥Î¿é¤J°ÆÀɦW¡C
E:\HomePage\SOURCE>..\masm50\masm exam01; [Enter]

Microsoft (R) Macro Assembler Version 5.00
Copyright (C) Microsoft Corp 1981-1985, 1987.  All rights reserved.


  51526 + 397850 Bytes symbol space free

        0 Warning Errors
        0 Severe  Errors

¦¹³B¤p¤ì°¸ªº²Õ¦X»y¨¥²ÕĶµ{¦¡¤Î­ì©lÀɤ£¦b¦P¤@¥Ø¿ý¡A©Ò¥H¥²¶·«ü©w²ÕĶµ{¦¡©Ò¦b¥Ø¿ý¡A¦]¦¹«e­±¦h¤F¡y..\masm50\¡z¡A´N¬O§i¶D DOS ²ÕĶµ{¦¡¦b¦ó³B¡A¦pªG§A§â­ì©lÀÉ¡B²ÕĶ¾¹¡B³sµ²¾¹¥þ³¡³£©ñ¦b¤@°_´N¤£¥Î¥´³o¨Ç¦r¤F¡C¦pªG¹q¸£Åã¥Ü 0 Warning Error »P 0 Severe Error ´N¬O§i¶D§A¤w²ÕĶ§¹¦¨¡A±µ¤U¨Ó§A±o³sµ²µ{¦¡®w¡]*.LIB¡^¡A¿é¤J¡y..\masm50\link exam01; ¡]¬°¦ó­n¥Î³sµ²¾¹³sµ²µ{¦¡®w¡A½Ð°Ñ¦Ò²Ä¤Q³¹¡^( LINK.EXE «áªº;¤]©MMASM.EXEªº·N¸q¬Û¦ü¡A¥i¦Û¤v¸Õ¸Õ )

E:\HomePage\SOURCE>..\masm50\link exam01; [Enter]

Microsoft (R) Personal Computer Linker  Version 2.40
Copyright (C) Microsoft Corp 1983, 1984, 1985.  All rights reserved.

Warning: no stack segment

³Ì«á·|¥X²{¤@­Ó¨S¦³°ïÅ|°Ï¬q ( no stack segment ) ªºÄµ§i°T®§¡A¦³Ãö°ïÅ|¯d¨ì²Ä¤­³¹¦A»¡©ú¡A¦¹³B§Ú­Ì©¿²¤³o¶µÄµ§i°T®§¡C±µ¤U¨Ó§Ú­Ì±N EXAM01.EXE ÀÉÅܦ¨ EXAM01.COM¡A¿é¤J¡y..\masm50\exe2bin exam01 exam01.com¡z

E:\HomePage\SOURCE>..\masm50\exe2bin exam01 exam01.com [Enter]

¨S¦³¥ô¦ó°T®§´N¥Nªí¦¨¥\¤F¡C±µ¤U¨Ó¡A¹ï¡y©R¥O´£¥Ü¦r¤¸¡z¿é¤J¡ydir¡z«ü¥O¡A¬Ý¬Ý§Ú­ÌªºÀɮצ³¨º¨Ç¡HµM«á¿é¤J¡yexam01¡z°õ¦æ¬Ý¬Ý¡G

E:\HomePage\SOURCE>dir [Enter]

 Volume in drive H is DATA_1
 Volume Serial Number is 0330-08F6
 Directory of E:\HomePage\SOURCE

.              <DIR>        02-02-02  21:31 .
..             <DIR>        02-02-02  21:31 ..
EXAM01   ASM           989  03-23-00   6:00 EXAM01.ASM
EXAM01   OBJ           107  02-02-02  22:26 EXAM01.OBJ
EXAM01   EXE           805  02-02-02  22:26 EXAM01.EXE
EXAM01   COM            37  02-02-02  22:27 EXAM01.COM
         5 file(s)          1,938 bytes
         2 dir(s)        7,984.43 MB free

E:\HomePage\SOURCE>exam01 [Enter]
Hi, I learn assembly.
E:\HomePage\SOURCE>

¦b³o­Ó¥Ø¿ý ( ¸ê®Æ§¨ ) ¸Ì¡AEXAM01.COM ´N¬O§Ú­Ì³Ì«á±o¨ìªº°õ¦æÀÉ¡A·í§Ú­Ì¦b DOS ´£¥Ü¤U©Î Windows ªº¡y©R¥O´£¥Ü¦r¤¸¡z¤U¿é¤J¦¹°õ¦æÀÉÀɦW´N¥Nªí§Ú­Ì­n°õ¦æ¦¹µ{¦¡¤F¡C§A¬Ý¡A§Ú­Ìªº§V¤O²×©ó¦³¤F¥N»ù¡A¬O¤£¬O¨q¥X§Ú­Ì©Ò­nªº¤å¦r¨Ó¡C

°²¦p±z¬O¦b XP ¨t²Î¤W¡A¨º»ò°õ¦æ exam01.com ®É¥i¯àµLªk¶¶§Q¦L¥X³o¬q¦r¨Ó¡A¥i¯à¬O¹ï INT 21H ªº¿é¥X¤£¤Ó¬Û®e¡A³o®É§A¥i¦bµêÀÀ¾÷¾¹¤U°õ¦æ¬Ý¬Ý¡A½Ð°Ñ¦Òªþ¿ý¤Q¤@¡C

¤W­zªº¹Lµ{¬O MASM.EXE ¬O§â­ì©lÀÉ ( ¤]´N¬O*.ASM ) ²ÕĶ¬°¥ØªºÀÉ *.OBJ¡A¦Ó³sµ²¾¹¬O§â¥ØªºÀÉ»Pµ{¦¡®w³sµ²°_¨Ó¡AÅܦ¨¥i°õ¦æªºÀÉ®× *.EXE¡Aµy«á§Ú¦A§@»¡©ú¡C³Ì«á¥i¥Î EXE2BIN ±N *.EXE ÀÉÂà´«¦¨ *.COM ÀÉ¡C¦ý¬O¨Ã«D¨C¦¸´N¯à¼g¥X¥¿½Tªºµ{¦¡¡A©Ò¥H¥²¶·°£¿ù¡Aµo²{¦³¿ù»~®É¤W­z¨BÆJ´N±o­«½Æ¤@¦¸¡A«Ü¬O³Â·Ð¡A¦pªG¯à¿é¤J´X­Ó¦r¨Ó¥N´À´N¦n¦h¤F¡A³o´N¬O§å¦¸Àɪº¦n³B¡A®e§Úµy«á¸ÑÄÀ¦p¦ó¼g§å¦¸ÀÉ¡C²{¦b¥ý¬Ý¬Ý MASM 6.11 ¦p¦ó²ÕĶ¡A¦A¨Ó¸ÑÄÀ¤W­z­ì©lÀÉ ( EXAM01.ASM ) ¨C¦æªº·N¸q¡C

¨Ï¥Î MASM 6.11 ²ÕĶ

¦]¬°¨C¦¸¼g¦n­ì©lÀÉ«á¡A³£­n¥ý²ÕĶ¦A³sµ²µ{¦¡®w¡A«Ü¬O³Â·Ð¡A©Ò¥H MASM 6.0 ¥H«á¡A¤£¦A¨Ï¥Î MASM.EXE¡A¦Ó§ï¦¨ ML.EXE¡CML.EXE ¯à¦Û°Ê©I¥s³sµ²¾¹ ( LINK.EXE ) ³sµ²¡A©Ò¥H¥u»Ý¤U¤@¦¸©R¥O§Y¥i¡AÁö¬O¦p¦¹¡A¦ý¬O±zÁÙ±o±N³sµ²¾¹ªº¦ì¸m§i¶D ML.EXE ¤~¥i¥H¡A§_«h ML.EXE ·|©ê«è§ä¤£¨ì LINK.EXE ¥X²{¿ù»~¦Ó°±¤î¡C§Ú­Ì¥i¥H¥Î DOS ªº PATH «ü¥O§i¶D ML.EXE¡ALINK.EXE ¦b¨º¤@­Ó¥Ø¿ý¡A¦p¤U¡G

E:\HomePage\SOURCE>path E:\HomePage\masm611d;%path% [Enter]

E:\HomePage\SOURCE>

·í§Ú­Ì°õ¦æ PATH «ü¥O«á¡A¥u»Ý°õ¦æ¤@¦¸¡ADOS ´N¯à°O¦í¡A©Ò¥H¦pªG­ì©lµ{¦¡²ÕĶµo²{¿ù»~¡A­×§ï¦n¥H«á­n¦A²ÕĶ®É¡A´N¤£¥Î¤U PATH ©R¥O¤F¡C¥u»Ý¦A¿é¤J¡yml /AT ­n²ÕĶªºÀɦW¡z§Y¥i¡C¦Ó¡y%path%¡z³o­Ó°Ñ¼Æ¬O«ü­×§ï PATH «ü¥Oªº¸ô®|¡C¸Ô²Ó±¡§Î½Ð¬Ýªþ¿ý¤T¤Îµù¤­¡C

±µ¤U¨Ó´N°õ¦æ ML.EXE¡C¦]¬°¤p¤ì°¸·Q§â­ì©lµ{¦¡©M²ÕĶ¾¹¤À¶}¦b¤£¦P¥Ø¿ý¡A©Ò¥H¤p¤ì°¸´N¹³¤W¤@³¹ªº¦w±Æ¤è¦¡¡AML.EXE ¦b E:\HomePage\MASM611D ¦Ó EXAM01.ASM ¦b E:\HomePage\SOURCE ¥Ø¿ý¤º¡A¦Ó¥B¤p¤ì°¸¤]§Æ±æ²ÕĶ¦nªºµ{¦¡¯à©ñ¦b E:\HomePage\SOURCE ¤l¥Ø¿ý¤º¡A©Ò¥H¤p¤ì°¸¤Á´«¨ì E:\HomePage\SOURCE ¤l¥Ø¿ý¤º¡A³o¼Ë DOS ´N·|¦b E:\HomePage\SOURCE ¤¤¤u§@¡A§â²ÕĶ¦nªºÀɮצs©ñ©ó¦¹¤l¥Ø¿ýùØ¡C³Ì«á¤U¹F¡yml /AT ­n²ÕĶªºÀɦW¡z«ü¥O¡A³o¼Ë ML.EXE ´N¯à¨Ì¤p¤ì°¸ªº§Æ±æ°õ¦æ¡C¡y­n²ÕĶªºÀɦW¡z¥²¶·¬O§¹¾ãªºÀɦW¡A¤]´N¬O­n¥]§t°ÆÀɦW¡A³o¬O ML.EXE ªº»yªk¤@©w±o¿í¦u¡C³Ì«áµ²ªG¦p¤U¡G

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

 Assembling: exam01.asm

Microsoft (R) Segmented Executable Linker  Version 5.60.339 Dec  5 1994
Copyright (C) Microsoft Corp 1984-1993.  All rights reserved.

LINK : warning L4017: /r : unrecognized option name; option ignored
Object Modules [.obj]: /r exam01.obj/t
Run File [exam01.com]: "exam01.com"
List File [nul.map]: NUL
Libraries [.lib]:
Definitions File [nul.def]:

¦Ü©ó ML.EXE ªº°Ñ¼Æ¡y/AT¡z¬O§i¶D ML.EXE §Ú­Ì­n»s§@¦¨ *.COM ÀÉ¡AML.EXE ·|¦Û°Ê¦aÂন EXAM01.COM ¦Ó¤£¶·¦A¥Î EXE2BIN ¤F¡C­nª`·N ML.EXE ªº°Ñ¼Æ¬O¦³¤j¤p¼gªº¤À§O¡A¡yAT¡z­YÅܦ¨¡yat¡z¬O·|¥X¿ùªº¡C

¨Ï¥Î MASM 8.0/9.0 ²ÕĶ

¦pªG±z­n¨Ï¥Î MASM 8.0 ª©©Î 9.0 ª©ªº²Õ¸q¾¹²ÕĶ exam01.asm¡A¤]¤£¬O¤£¥i¥H¡A¦ý¬O¦³´X­Ó­­¨î¡C­º¥ý¡A8.0/9.0 ª©ªº ML.EXE ¥u¯à¦b Windows ¨t²Î¤¤°õ¦æ¡AµLªk¦b DOS §@·~¨t²Î¤¤°õ¦æ¡A¤]¤£¯à¦bµêÀÀ¾÷¾¹ªº DOS ùØ°õ¦æ¡A¤£¹L©Ò²£¥Íªºµ{¦¡ÁÙ¬O¯à¦b DOS ùØ°õ¦æ¡C²Ä¤G¡A8.0/9.0 ª©ªº ML.EXE ¥»¬O°t¦X Visual C++ ²ÕĶ VC ùؤº´Oªº²Õ¦X»y¨¥µ{¦¡½X¡A©Ò¥H¹w¥ý³]©w¬O¥Î¨Ó²ÕĶ 32 ¦ì¤¸ªº Windows µ{¦¡¡A¦pªG­n²ÕĶ 16 ¦ì¤¸ªº DOS µ{¦¡¡A¥²¶·¥[¤W¡y/omf¡z°Ñ¼Æ¨Ï²ÕĶ©Ò±oªº¥ØªºÀɮ榡¬° Intel Object Module Format ®æ¦¡¡C²Ä¤T¡A©Ò¨Ï¥Îªº³sµ²¾¹¡A¥²¶·¬O¯à³sµ² OMF ®æ¦¡ªº¥ØªºÀɪº³sµ²¾¹¡A³Ì°ªª©¥»¬O 5.63 ª©¡A¤£­n»P³sµ²¦¨ Windows µ{¦¡·d²V¤F¡C©³¤U¤p¤ì°¸°²³] 8.0 ª©ªº ML.EXE ¤Î 5.63 ª©ªº LINK.EXE ³£¦b¡yE:\HomePage\MASM8¡z¤l¥Ø¿ýùØ¡A¦Ó exam01.asm ¦b¡yE:\HomePage\SOURCE¡zùØ¡G

E:\HomePage\SOURCE>..\masm8\ml /omf /AT exam01.asm [Enter]
Microsoft (R) Macro Assembler Version 8.00.50727.218
Copyright (C) Microsoft Corporation.  All rights reserved.

 Assembling: exam01.asm

E:\HomePage\SOURCE>..\masm8\link exam01 [Enter]

Microsoft (R) Segmented Executable Linker  Version 5.60.339 Dec  5 1994
Copyright (C) Microsoft Corp 1984-1993.  All rights reserved.

Run File [exam01.exe]:
List File [nul.map]:
Libraries [.lib]:
Definitions File [nul.def]:
LINK : warning L4021: no stack segment

E:\HomePage\SOURCE>..\masm8\exe2bin exam01 exam01.com [Enter]

E:\HomePage\SOURCE>

8.0/9.0 ª©ªº ML.EXE ¦ü¥G¤£¹³ 6.x ª©ªº ML.EXE ¯à¦Û°Ê°õ¦æ³sµ²¾¹¡A¦]¦¹¤£±o¤w¡A¥u¯à¤â°Ê°õ¦æ¡C


µ{¦¡»¡©ú

¡F»P COMMENT

EXAM01.ASM ªº²Ä¤@¦æ¬O¡y;***************************************¡z¡A¤Z¬O¦b¡y;¡z¤§«áªº¤å¦r³£·|³Q²ÕĶ¾¹©¿²¤¡A¦]¦¹³Q¥Î¨Ó·íµù¸Ñ¡Cµ{¦¡³]­p®vÀ³¾¨¶q¯d¤Uµù¸Ñ¡A¥H«K¤é«á­×§ï¡Cµù¸Ñ³Ì¦n»¡©úºtºâªk¡B©Ò¥Îªº­ì²z¡BÅܼƩҥNªíªº·N¸q¡K¡K¡A¤£­n¼g¤@¨ÇµL·N¸qªºµù¸Ñ¡A¨Ò¦p¤U­±ªºµù¸Ñ¬O¨S¦³·N¸qªº¡C

;***************************************    ;³o¬Oµù¸Ñ

¦³®Éµù¸Ñ¤Óªø¡A¥²¶·¨Ï¥Î¦n´X¦æ¤å¦r®É¡A¥i¥H¥Î COMMENT ¨Ó·í¦¨µù¸Ñ¡ACOMMENT ªº»yªk¬O¡G

COMMENT ¤À¹j¸¹
µù¸Ñ¤å¦r
¤À¹j¸¹

¤À¹j¸¹¥i¥H¬O¥ô·N¦r¤¸¡A¦ý¬O¤£¥i¥H¥X²{¦bµù¸Ñ¤å¦r¤¤¡A°²¦p³o¼Ëªº¸Ü¡A²ÕĶ¾¹·|»{¬°µù¸Ñµ²§ô¤F¡A¦Óµo¥Í¿ù»~¡C

SEGMENT »P ENDS °²«ü¥O

²Ä¤G¦æ¬O code segment¡A¨ä¤¤ segment ¬O²ÕĶ¾¹ªº°²«ü¥O¡C©Ò¿×°²«ü¥O¬O§i¶D²ÕĶ¾¹¦p¦ó²ÕĶ¡A¨Ã¤£¬O CPU ªº«ü¥O¶°¡C²Õ¦X»y¨¥ªº«ü¥O¤¤¡A¦³¨Ç¬O«ü¥Ü²ÕĶ¾¹¦p¦ó²ÕĶªº¡A§Y°²«ü¥O¡Q¦³¨Ç¬O 80X86 «ü¥O¡A³o¬O¨Ï CPU ¯u¥¿¹Bºâ©Î¤u§@ªº«ü¥O¡Csegment °²«ü¥O¬O§i¶D²ÕĶ¾¹¦³¤@­Ó°Ï¬q ( segment ) ±q³o¨à¶}©l¤F¡Csegment ¤@©w·|»P ends ( end segment ªºÂ²¼g¡Aends ªº s ¬O«ü segment ) °t¹ï¡Aends ¤]¬O¤@­Ó°²«ü¥O¡A¬O§i¶D²ÕĶ¾¹¡A³o­Ó°Ï¬q¨ì¦¹µ²§ô¤F¡C°Ï¬qªº¦WºÙ¥i¥ô·N¥Ñ­^¤å¦r¥À¡B¼Æ¦r¤Î©³½u²Õ¦¨¡A¦¹³B§Ú±N¥¦¨ú¦W¬°¡ycode¡z°Ï¬q¡C¯u¹ê¼Ò¦¡©³¤U¡A¨C­Ó°Ï¬q¤£¥i¶W¹L 64K ¦ì¤¸²Õ¡C½Ð°Ñ¦Òµù¤G¦³Ãö°²«ü¥Oªº»¡©ú¡C

¦b²Õ¦X»y¨¥¤¤¡A¨C¤@¦æµ{¦¡½X©Î¨C¤@µ§¸ê®Æ³£¥²¶·¦b¬Y­Ó°Ï¬q¤º¡A§_«h²ÕĶ®É²ÕĶ¾¹·|²£¥Í¿ù»~¡A§ó¤£­n»¡°õ¦æ¤F¡C°Ï¬q¤j­P¥i¤À¬°µ{¦¡½X°Ï¬q¡B¸ê®Æ°Ï¬q¤Î°ïÅ|°Ï¬q¡Aµ{¦¡½X°Ï¬q¬O¥Ñ³\¦h 80x86 «ü¥O²Õ¦¨¡A³o¨Ç«ü¥O§i¶D CPU ¸Ó¦p¦ó°Ê§@¡A¸Ó°µ¤°»ò¹Bºâ¡F¸ê®Æ°Ï¬q¬O CPU °Ê§@©Î¹Bºâ®É©Ò»Ýªº¸ê®Æ²Õ¦¨¡C¥H¥[ªk¬°¨Ò¡A¥[ªí¥Ü¹Bºâ¡A¦Ó³Q¥[¼Æ»P¥[¼Æªí¥Ü¸ê®Æ¡A¬Û¥[«á©Ò±oªº©M¤]¬O¸ê®Æ¡C¦b¯à°÷¥Ñ*.EXE ÀÉÂà´«¦¨ *.COM ªºµ{¦¡¡A¥¦ªºµ{¦¡¬q¤Î¸ê®Æ¬q¦b¦P¤@­Ó¬q¤º¡A´«¥y¸Ü»¡µ{¦¡¬q»P¸ê®Æ¬q¦b 64K ¤º­«Å|¦b¤@°_¡C

ªì¾ÇªÌ¥i¥H±N³o¨â­Ó°²«ü¥Oµø¬°©T©w®æ¦¡¡A´N¦n¹³ HTML ¤¤ªº <HTML></HTML> ¤@¼Ë¡C²Õ¦X»y¨¥¤¤¡ACOM µ{¦¡ªº­ì©lÀɤ]¦³©T©w®æ¦¡¡A´N¬O¡G

°Ï¬q¦W  segment
        assume  cs:code,ds:code
        org     100h
start:
        ;¦¹³B©ñµ{¦¡¤º®e
°Ï¬q¦W  ends
        end     start
·í¦³¸ê®Æ®É¡A¥i¥Î¤U­±©T©w®æ¦¡¡G
code    segment
        assume  cs:code,ds:code
        org     100h
start:	jmp begin
        ;¦¹³B¦s©ñ¸ê®Æ
begin:
        ;¦¹³B©ñµ{¦¡¤º®e
code    ends
        end     start

¨ì¤F MASM 5.x ¥H«áªº²ÕĶ¾¹¡A¥i¥H¨Ï¥Î¸û²³æªº©w¸q¨Ó©w¸q°Ï¬q¡C¤èªk¬O¥Î¡y.code¡z©w¸qµ{¦¡½X°Ï¬q¡A¥Î¡y.data¡z©w¸q¸ê®Æ°Ï¬q¡A¤@­Ó°Ï¬qªºµ²§ô´N¬O¥t¤@­Ó°Ï¬qªº¶}©l¡A¦pªG¨ì­ì©lÀɳ̫á¡A´Nªí¥Ü³Ì«á¤@­Ó°Ï¬q¤]µ²§ô¤F¡C¨Ò¦p COM µ{¦¡ªº­ì©lÀÉ¥i¥H¼g¦¨¡G

        .code
        org     100h
start:  jmp     begin
        ;¦¹³B¦s©ñ¸ê®Æ
begin:
        ;¦¹³B©ñµ{¦¡¤º®e
end     start

ASSUME °²«ü¥O

²Ä¤T¦æ¬O

assume  cs:code,ds:code

³o¤@¦æ¬O¹w¥ý±N CS ©M DS ¼È¦s¾¹³]¬° code °Ï¬q¡C¦b 8086 CPU ¤¤¦@¦³ 4 ­Ó 16 ¦ì¤¸ªº°Ï¬q¼È¦s¾¹¡A¤À§O¬O CS¡BDS¡BES¡BSS¡A²ßºD¤W¤À§O«ü¦Vµ{¦¡½X°Ï¬q¡B¸ê®Æ°Ï¬q¡BÃB¥~°Ï¬q¤Î°ïÅ|°Ï¬q¡C¡CÃö©ó8086¼È¦s¾¹¡A¸Ô²Ó±¡§Î½Ð°Ñ¦Ò³o¸Ì¡C

COM µ{¦¡ªºµ{¦¡½X¡B¸ê®Æ¬q¡BÃB¥~¬q¡B°ïÅ|¬q³£¦b¦P¤@°Ï¬q¤¤¡A¦]¦¹¦¹³B±N CS¡BDS ³£³]¬° code °Ï¬q¡C³]¦n¤§«áªº¥Î³B¬O¡A·í­n¦s¨úÅܼƮɡA´N¤£¶·¦A«ü©w DS ¤F¡A§_«h¥i¯à­n¥Î­â¶V°Ï¬q ( °Ñ¦Ò 24 ³¹¡@) ªº¤èªk¤F¡C

ORG °²«ü¥O

²Ä¥|¦æ¤¤¬O¡yorg 100h¡zªí¥Ü¦¹¦æ¥H«áªºµ{¦¡¥Ñ 100H ( ¥[¤W H ªí¥Ü 16 ¶i¦ì ) ³o­Ó¦ì§}¶}©l¡CDOS ¥ÑºÏºÐ¸ü¤J COM µ{¦¡Àɮ׮ɡA·|¦Û°Ê§âµ{¦¡½X¤À°t¨ì¦ì§} 100H ¶}©l°õ¦æ¡A¦]¦¹¥²¶·¥[¤J³o¤@¦æ¡A§i¶D³sµ²¾¹µ{¦¡½X­n±q 100H ¶}©l³sµ²¡C

¤°»ò¬O¦ì§}©O¡H¹q¸£©Ò¯à±±¨îªº°O¾ÐÅé«Ü¤j¡A·í CPU ­n¦s¨ú°O¾ÐÅ餤ªº¸ê®Æ®É¡A¥²¶·­nª¾¹D±o¦V¨º¤@­Ó°O¾ÐÅé­n¸ê®Æ¤~¦æ¡C¦Ó°O¾ÐÅé¬O¦³½s¸¹ªº¡A¹q¸£¥H¤@­Ó¦ì¤¸²Õ ( ¦ì¤¸²Õ¬O byte¡A§Y 8 ¦ì¤¸¡A¦ì¤¸¬O bit ) ¬°³æ¦ì°µ½s¸¹¡A³o½s¸¹´N¥s¦ì§}¡C¦b DOS ùØ¡A¥Î XXXX:YYYY ªí¥Ü¦ì§}¡A¨ä¤¤ XXXX ºÙ¬°°Ï¬q¦ì§} ( segment address )¡AYYYY ºÙ¬°°¾²¾¦ì§} ( offset address )¡A8086 ¤¤¨C­Ó°Ï¬q³Ì¤j¥i¥H¨ì 64KBytes ( 64KBytes¡×65536 ­Ó¦ì¤¸²Õ ) ¨C¤@­Ó°Ï¬qªº°O¾ÐÅ骺½s¸¹¬O¥Ñ 0 ¸¹¨ì 65535 ¸¹¡A¦@¦³ 65536 ­Ó( 65536 °£¥H 1024 ±o 64¡A©Ò¥H¤@¯ë³£»¡¬O 64 KBytes)¡A³o 65536 ­Ó¦ì§}¡A¨C¤@­Ó¦ì§}ªº®e¶q¤j¤p¥u¦³¤@­Ó¦ì¤¸²Õ(byte)¡C´N¹³§Ú­Ì®a®xªº¦a§}¤@¼Ë¡A¤¤µØ¸ô 263 ¸¹¡A³o¤¤µØ¸ô´N¹³¬O°Ï¬q¡AªùµP¸¹½X 263 ´N¹³¬O°¾²¾¦ì§}¡C·í CPU ¹Bºâ®É»Ý­n¸ê®Æ¡A´N¥u­n§i¶D°O¾ÐÅé¡A­n¨ú¨º¤@­Ó¦ì§}ªº¸ê®Æ¡A¹q¸£´N·|¨Ì¾Ú­þ­Ó°Ï¬q¡A­þ­Ó°¾²¾¦ì§}¥h¦s¨ú¡A´N¤£·|§Ë¿ù¤F¡C

¼Ð°O¡G

²Ä¤»¦æ¡Astart:¡A¬Oªí¥Ü¤@­Ó¼Ð°O¡A¤Z¬O¥H¡y:¡zµ²§Àªº¦r¦ê³£¬O¼Ð°O¡A¥Lªí¥Ü°O¾ÐÅ餤ªº¤@­Ó¦ì§}¡A¸õÅD®É·|¥Î¨ì¡A¨Ò¦p jmp begin¡A´N¬Oªí¥ÜÅý CPU ¸õ¨ì begin: ¼Ð°O³BÄ~Äò°õ¦æ¡C¦b¸õÅD«ü¥O«á¡A¤£»Ý¥[¤W´U¸¹¡A©w¸q¼Ð°O®É¤~»Ý­n¥Î¨ì´U¸¹¡C jmp ´N¬OµL±ø¥ó¸õÅD¡A´N¹³ BASIC ¤¤ªº GOTO ¤@¼Ë¡C

DB ©Î BYTE °²«ü¥O

²Ä¤C¦æªº«ü¥O¬O db (define byte)¡A¨ä»yªk¬O¡G

ÅܼƦW    db     ¼Æ­È
ÅܼƦW    byte   ¼Æ­È

MASM 6.x ¥H«á¤~¥i¥Î byte ©w¸q¦ì¤¸²Õ¡A¤£ºÞ¬O¡ydb¡z©Î¡ybyte¡z¡A³£¬O¤@­Ó°²«ü¥O¡A¥¦¬O§i¶D²ÕĶ¾¹³o¨à¦³¤@¶ô°O¾ÐÅéªÅ¶¡«O¯d°_¨Óµ¹«e­±ªºÅܼƦW¨Ï¥Î¡A¦Ó«O¯dªº¤j¤p¬O¤@­Ó¦ì¤¸²Õ ( ¦ì¤¸²Õ­^¤å¬O byte¡Aªø 8 ­Ó¦ì¤¸ )¡C¤@­Ó¦ì¤¸²Õªº¤j¤p¥i¥Hªí¥Ü 0 ¨ì 255 ¦@ 256 ­Ó¼Æ¦r ( 28¡×256)¡A©Ò¥H¦pªG±zªºÅܼƼƭȦb¦¹½d³ò¤º´N¥i¥H¥Î db ¨Óªí¥Ü¡C¦pªG­n©w¸q¨â­Ó¦ì¤¸²Õ¥i¥H¥Î

ÅܼƦW    db     ¼Æ­È1¡A¼Æ­È2

°²¦p¤@¶}©l¤£ª¾¹DÅܼƪº¼Æ­È¡A¨º»ò¥i¥Î¡y?¡zªí¥Ü¡G

ÅܼƦW    db     ?

°£¤Fªí¥ÜÅܼƤ§¥~¡Adb ¤]¥i¥H©w¸qªº¬O¤@­Ó­^¤å¥y¤l ( ³N»yºÙ¬°¦r¦ê¡Astring )¡A´N¹³¦b³o­Ó¨Ò¤lùتº²Ä¤C¦æ¡A¦ý¬°ÁקK²ÕĶ¾¹»~¸Ñ¬°¼Æ¦r¡A©Ò¥H¥Î¡y"¡z©Î¡y'¡z±N¥y¤l¬A°_¨Ó¡C°²¦p¥H¡ydb¡z©w¸q¤@­Ó¦r¦êªº¸Ü¡A¨C¤@­Ó­^¤å¦r¥À·|¦û¥Î¤@­Ó¦ì¤¸²Õ¡A¦Ó¤¤¤å¦r«h¦û¥Î¨â­Ó¦ì¤¸²Õ¡C

MOV «ü¥O

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

        MOV     ¹Bºâ¤¸1,¹Bºâ¤¸2

MOV ¦b 80X86 ²Õ¦X»y¨¥¤¤¬Û·í©ó«ü©w©Î½á¤©¹Bºâ¤¸2ªº¼Æ­Èµ¹¹Bºâ¤¸1¡AÃþ¦ü¨ä¥L°ª¶¥»y¨¥ªº¡y¡×¡z¤§·N¡C¨Ò¦p²Ä 9 ¦æªº

mov     ah,9

´N¬O§â AH ³]¬° 9 ªº·N«ä¡C¤]¥i¥H§â¥¦·Q¦¨¬O±N«á­±ªº¸ê®Æ²¾°Ê¡]move¡^¨ì«e­±ªº¹Bºâ¤¸¤¤¡C¨º»ò¡AAH ¬O¤°»ò©O¡HAH ¬O¤@­Ó 8 ¦ì¤¸¤j¤pªº¼È¦s¾¹¡C¼È¦s¾¹¥i¥H·Q¹³¦¨¬O¦b CPU ¤º³¡¤@¶ô¼È®ÉÀx¦s¸ê®Æªº°O¾ÐÅé¡A³o¨Ç°O¾ÐÅé¤j¤p¨Ã¤£¤j¡A¨C­Ó¶È 8¡B16 ©Î 32 ¦ì¤¸ªø¡A¦ý¬O¹Bºâ³t«×«o¤ñ¦b°O¾ÐÅé§Ö±o¦h¡C¦b 8086/8088 CPU ¦³ 4 ­Ó 16 ¦ì¤¸³q¥Î¼È¦s¾¹¡A¨Ñ§@¥[´î­¼°£µ¥¹Bºâ¤§¥Î¡A¤À§O¬O AX¡BBX¡BCX¡BDX¡A¦Ó¨C­Ó³q¥Î¼È¦s¾¹¡A¤S¦U¤À¬°°ª¦ì¤¸©M§C¦ì¤¸ªº¨â­Ó¡A¥H AX ¬°¨Ò¤S¤À¬° AH¡BAL¡AAH ªí¥Ü¸û°ªªº 8 ¦ì¤¸¡AAL ªí¥Ü¸û§Cªº 8 ¦ì¤¸¡A¦p¤U¹Ï©Ò¥Ü¡C

¤K¦ì¤¸ªº¼È¦s¾¹¡A´N¥u¯à¦s¤J 8 ­Ó¦ì¤¸ªº¤j¤p¡A¨C­Ó¦ì¤¸¥i¯à¬O 0 ©Î¤@¡A©Ò¥H¥u¯àªí¥Ü 28 ­Ó¼Æ¡A¤]´N¬O 0¡ã255 ¤§¶¡¤£¦Pªº¼Æ¡C16 ¦ì¤¸ªº¼È¦s¾¹¡A«h¯àªí¥Ü 216 ­Ó¼Æ¡A¤]´N¬O 0¡ã65535 ¤§¶¡ªº¼Æ¡C

MOV «ü¥Oªº¨â­Ó¹Bºâ¤¸¥²¶·ªø«×¬Û¦P¡A¦P¼Ë³£¬° 16 ¦ì¤¸©Î 8 ¦ì¤¸¡A¤£¥i¥H¹Bºâ¤¸1 ¬° 16 ¦ì¤¸¡A¦Ó¹Bºâ¤¸2 ¬° 8 ¦ì¤¸¡C¦Ó¥B³o¨â­Ó¹Bºâ¤¸¥²¶·¦³¤@­Ó¬O¼È¦s¾¹©Î±`¼Æ¼Æ­È¡A¤£¥i¥H¨â­Ó¹Bºâ¤¸¦P®É¬O°O¾ÐÅ餤ªº¸ê®Æ ( ¥ç§YÅÜ¼Æ )¡C

OFFSET °²«ü¥O

OFFSET ¬O±N¨ä«á¹Bºâ¤¸ªº°¾²¾¦ì§}­pºâ¥X¨Ó¡CEXAM01.ASM ªº²Ä¤K¦æ¬O

begin:  mov     dx,offset mes

¨ä·N¸q´N¬O±N mes ©Ò¦b°¾²¾¦ì§}¶ñ¤J¨ì DX ¼È¦s¾¹¤¤¡A­nª`·Nªº¬O¨Ã¤£¬O§â mes ªº¤º®e¦s¤J DX¡A¦Ó¬O§â°¾²¾¦ì§}·í¦¨¤@­Ó¼Æ­È¡A¦s¤J DX ùØ¡C¦pªG»¡°¾²¾¦ì§}´N¬OªùµP¸¹½X¡A¨º»ò¸Ó°¾²¾¦ì§}ªº¤º®e´N¬O§A®aùØ­±©Ò¦íªº¤H¡C¨C­Ó°Ï¬q¶}©lªº¦ì§}³£¬O¥Ñ 0 ¶}©l¡A¦Ó­ì©lµ{¦¡¤¤¨C¦æ©Ò¦û¥Îªº°O¾ÐÅé¦ì¤¸²Õ¦h¹è¤£ºÉ¬Û¦P¡AOFFSET ·|¥h­pºâ¨C¦æµ{¦¡½X©Ò¦û¦ì¤¸²Õ¼Æ¡A´N¥i¥H¨D¥X¨Ó mes ©Ò¦b¦ì§}¡AµM«á¦A²¾¨ì DX ùØ¡COFFSET ³o­Ó«ü¥O¡A¬O«ü¥Ü²ÕĶ¾¹¥hºâ¥X mes ©Ò¦bªº°¾²¾¦ì§}¡A¦]¦¹¬O°²«ü¥O¡C

INT «ü¥O

²Ä¤Q¦æ int 21h¡Aint ªí¥Ü¤¤Â_¡A¦b²Õ¦X»y¨¥¤¤¡A¤¤Â_¬O¤@ªù¤j¾Ç°Ý¡A¦b¦¹³B§Ú­Ì¥i¥H§â¤¤Â_·Q¦¨¬O¤@ºØ°Æµ{¦¡¡A°Æµ{¦¡¬OÀ°§Ú­Ì°õ¦æ¤@¨Ç±`¥Îªº¤u§@¡Aµ¥§¹¦¨«á¡A¦A±N°õ¦æµ²ªG¶Ç¦^µ¹­ì¨Óµ{¦¡Ä~Äò°õ¦æ¡C¦b¤@¯ëµ{¦¡¤¤¥i¯à­n±`±`¦L¥X¤@¬q¤å¦r¡A¨Ò¦p´£¿ô§A¿é¤J©m¦W¡A©ÎªÌ¦L¥X­pºâªºµ²ªG¡A¦pªG¨C¦¸³£¼g¤@¬q¦L¥X¦r¦êªºµ{¦¡¡A¤£¬O«Ü¨S®Ä²v¶Ü¡H©Ò¥H§Ú­Ì±`±`¬O§â­n¦L¥Xªº¤å¦r°O¿ý©ó¬Y³B¡A¦A¶Çµ¹¤@¬q±Mªù¦L¥X¤å¦rªºµ{¦¡¡A³o¬qµ{¦¡´N¥s°Æµ{¦¡¡C¦¹³B¡A§Ú­Ì©I¥s¤Q¤»¶i¦ìªº 21 ¸¹¤¤Â_¡A¦¹¤¤Â_¬O DOS ´£¨Ñªº¤]¥s DOS ªA°Èµ{¦¡¡C·í§Ú­Ì¶}¾÷¶i¤J DOS ®É¡ADOS ´N·|¦Û°Êªº±N¦¹¤¤Â_¤]¸ü¤J°O¾ÐÅ餤¡A²Õ¦X»y¨¥µ{¦¡±`§Q¥Î DOS ¤¤Â_³B²z³\¦hÁcÂøªº¨Æ¡A21h ¤¤Â_©Ò§@ªº¨Æ¡A³£¥Ñ AH ¤º®e¨M©w¡A·í AH=9 ¶i¤J 21h ¤¤¬q®Éªí¥Ü­n¦L¥X¤@¬q¤å¦r¡A¦Ó¦¹¤å¦rªº°_©l¦ì§}«K¥Ñ DX ¨M©w¡A¤@ª½¦L¨ì¡y$¡z¬°¤î¡C

DOS ©M BIOS ³£´£¨Ñ¤F³\¦h¤¤Â_ªA°Èµ{¦¡¡A¨C¤@­Ó¤¤Â_³B²zªº¨Æ³£¤£¦P¡A¦]¦¹¼g²Õ¦X»y¨¥ªº¤H¤âÀY¤W³£À³¸Ó­n¦³¤@¥»¤¤Â_¦Cªí¡A¥H¨Ñ°Ñ¦Ò¡C

²Ä¤Q¤@¦æ¡B¤Q¤G¦æ¤]¬O°õ¦æ DOS ªA°Èµ{¦¡¡A¥Øªº¬Oµ²§ôµ{¦¡¡A¦b²Õ¦X»y¨¥¤¤µ²§ôµ{¦¡¦³¦n´XºØ¤è¦¡¡A³Ì±`¥Îªº´N¬O AH=4CH/INT 21H¡A¦Ó AL ¤ºªº¼Æ­È¬Oªí¥Üµ²§ô®É¶Ç¦^µ¹ DOS ªº¿ù»~½X¡A¦pªG§A¼g¹L DOS ªº§å¦¸ÀÉ ( *.BAT ) ¥i¥H§Q¥Î¿ù»~½X¨Ó¿ï¾Ü¡C

¦b¦¹§A¤]¥i¥H¼g¦¨¹³¤U­±ªº¼Ë¤l¡A¦ý¬O­n¦h¤@­Ó byte¡C

        mov     ah,4ch
        mov     al,0
        int     21h
¥t¥~¦b COM ÀÉùØ¡A¤]¥i¥H¨Ï¥Î int 20h ¨Óµ²§ôµ{¦¡¡C

END °²«ü¥O

²Ä¤Q¤»¦æ¡Aend ¤]¬O°²«ü¥O¡Aªí¥Üµ{¦¡µ²§ô¡Aend «á­±ªº¼Ð°O¬O«üµ{¦¡¶i¤JÂI¡A¦ý¹ï COM ÀɦӨ¥¬OµL·N¸qªº¡A¼g¤£¼g³£¨SÃö«Y¡A¦]¬° COM Àɳ£¬O¥Ñ 100h ¶}©l°õ¦æ¡F¦ý¹ï EXE ÀɦӨ¥§A´N¥i¥H¨Ì»Ý­n¦Ó¥[¥H³]©w¡Cend ¬O§i¶D²ÕĶ¾¹¡A­ì©l½X¨ì¦¹¬°¤î¤F¡A¦A¤U­±´N¨S¦³¤F¡A¥¦¨Ã¤£¬O§i¶D CPU ³o­Óµ{¦¡µ²§ô¡A¦]¦¹ end ¤]¬O¤@­Ó°²«ü¥O¡C¤]¦]¬° END ¤£¬O§i¶D CPU µ{¦¡µ²§ô¤F¡A©Ò¥H²Ä 11 ¦æ¨ì 12 ¦æªº¡ymov ax,4c00h/int 21h¡z¬O¤£¯à¬Ù²¤¡A§_«h·|·í¾÷¡C


»s§@µ{¦¡ªº¬yµ{

­n¼g¥Î²Õ¦X»y¨¥¼g¤@­Óµ{¦¡¡A¨ä¬yµ{¹Ï¤j­P¦p¤U¡G¥ý¥Î¤å®Ñ½s¿è³nÅé¼g¦n­ì©lÀÉ¡A¨Ã¦s¦¨°ÆÀɦW¬° ASM ªº­ì©lÀÉ¡AµM«á¸g²ÕĶ¾¹²ÕĶ¡A³sµ²¾¹³sµ²µ{¦¡®w¡A¦A¨Ó´N¬O¥Î°£¿ù¾¹°£¿ù¤F¡A¦pªG¦³¿ù»~¡A´N¦^¨ì¤å®Ñ½s¿è³nÅé­×§ï­ì©lÀÉ¡AµM«á¦A²ÕĶ³sµ²°£¿ù¡A¤@ª½­«½Æ¨ì¨S¦³¿ù»~¤î¡C¾ã­Ó¬yµ{¹Ï¦p¤U¡G

¥Î§å¦¸ÀɲÕĶ¡B³sµ²

¥Ñ¤W¹Ï¥iª¾¡A±q¼¶¼g­ì©lÀɨ찣¿ù¡A¥²¶·¦b DOS ¼Ò¦¡¤U¿é¤J«ü¥O¡A·íµ{¦¡¸û¤j®É¨Ã¤£¬O¤@¦¸´N¯à­×¥¿©Ò¦³¿ù»~¡A¦Ó¨C¦¸­ì©lÀɼg¦n¤§«á³£¥²¶·­«½Æ¤@¦¸²ÕĶ³sµ²ªº¹Lµ{¡A«Ü³Â·Ð¡CDOS ªº³]­pªÌ¦­¤w·Q¨ì¤F³o­Ó°ÝÃD¡A¨Ã¥B³]­p¦n¨âºØ¤èªk¸Ñ¨M¡A²Ä¤@ºØ¬O¥Î¸ô®|¡A²Ä¤GºØ¬O¥Î§å¦¸ÀÉ ( °ÆÀɦW¬° BAT ) ¨Ó²¤Æ¡A¦¹³B»¡©ú¦p¦ó¨Ï¥Î§å¦¸ÀÉ¡A¤j­P¦³¨â­Ó¨BÆJ¡G
  1. ­º¥ý­n«Ø¥ß¤@­Ó¯Â¤å¦rÀÉ¡A³o­Ó¯Â¤å¦rÀÉ¥i¥Î°O¨Æ¥»¿é¤J¥H¤U¤å¦r¡AµM«á¦s¦¨ CPL.BAT ÀÉ¡Q( ÀɦW¥i¥H¥ô·N¨ú¡A¦ý°ÆÀɦW¤@©w­n¥Î BAT¡A[Enter] ¬Oªí¥Ü«ö Enter Áä´«¦æªº·N«ä )
    ..\masm50\masm %1; [Enter]
    ..\masm50\link %1; [Enter]
    ..\masm50\exe2bin %1 %1.com [Enter]
    ¤]¥i¥Hª½±µ¦b DOS ¼Ò¦¡²£¥Í CPL.BAT¡A¥ý¤Á´«¨ì­ì©lÀÉ©Ò¦b¥Ø¿ý¡A¦A¿é¤J¥H¤U¤å¦r¡G
    E:\HomePage>cd source [Enter]
    
    E:\HomePage\SOURCE>copy con cpl.bat [Enter] ¡÷con ªí¥Ü±±¨î¥x ( ±±¨î¥x¥]§tÁä½L§Y¿Ã¹õ )¡A
    ..\masm50\masm %1; [Enter]                  ¡÷¤W¤@¦æªí¥Ü¥Ñ±±¨î¥x«þ¨©¤å¦r¨ì CPL.BAT
    ..\masm50\link %1; [Enter]
    ..\exe2bin %1 %1.com [Enter]
    ^Z [Enter](µù¥|)
            1 file(s) copied
    
    E:\HomePage\SOURCE>dir [Enter]
    
     Volume in drive H is DATA_1
     Volume Serial Number is 0330-08F6
     Directory of E:\HomePage\SOURCE
    
    .              <DIR>        02-02-02  21:31 .
    ..             <DIR>        02-02-02  21:31 ..
    EXAM01   ASM         1,121  03-23-00   6:00 EXAM01.ASM
    CPL      BAT            69  02-08-02   1:19 cpl.bat
             2 file(s)          1,190 bytes
             2 dir(s)        7,982.30 MB free

    ±z¥i¥H¬Ý¥X¨Ó¡A¨ä¹ê§å¦¸Àɪº¤º®e¡A§¹¥þ·Ó§Ú­Ì©Ò¿é¤Jªº«ü¥O¥h°õ¦æªº¡A¨ä¤¤¥u¦³¥i¯à·|§ïÅܪº¦a¤è¥Î %1¡N%2 ¡K¡K¨Ó¥N´À¡A¨Æ¹ê¤W¡A %1¡N%2 ¡K¡K´N¦n¹³¬O¡yÅܼơz¤@¼Ë¡C

  2. ²Ä¤G¡A¨Ï¥Î³o­Ó§å¦¸ÀɮɡA¥u»Ý­n¿é¤J¡ycpl ­n²ÕĶ³sµ²ªºÀɦW¡z§Y¥i¡A½Ð¬Ý¤U­±¡G
    E:\HomePage\SOURCE>cpl exam01 [Enter]
    
    E:\HomePage\SOURCE>..\masm50\masm exam01;
    Microsoft (R) Macro Assembler Version 5.00
    Copyright (C) Microsoft Corp 1981-1985, 1987.  All rights reserved.
    
    
      51536 + 418608 Bytes symbol space free
    
          0 Warning Errors
          0 Severe  Errors
    
    E:\HomePage\SOURCE>..\masm50\link exam01;
    
    Microsoft (R) Personal Computer Linker  Version 2.40
    Copyright (C) Microsoft Corp 1983, 1984, 1985.  All rights reserved.
    
    Warning: no stack segment
    
    E:\HomePage\SOURCE>..\masm50\exe2bin exam01 exam01.com
    
    E:\HomePage\SOURCE>
    
    E:\HomePage\SOURCE>dir [Enter]
    
     Volume in drive H is DATA_1
     Volume Serial Number is 0330-08F6
     Directory of E:\HomePage\SOURCE
    
    .              <DIR>        02-02-02  21:31 .
    ..             <DIR>        02-02-02  21:31 ..
    EXAM01   ASM         1,121  03-23-00   6:00 EXAM01.ASM
    CPL      BAT            69  02-08-02   1:19 cpl.bat
    EXAM01   OBJ           107  02-08-02   1:22 EXAM01.OBJ
    EXAM01   EXE           805  02-08-02   1:22 EXAM01.EXE
    EXAM01   COM            37  02-08-02   1:22 EXAM01.COM
             5 file(s)          2,139 bytes
             2 dir(s)        7,982.29 MB free
    
    E:\HomePage\SOURCE>exam01 [Enter]
    Hi, I learn assembly.
    E:\HomePage\SOURCE>
¥u¦³¶À¦âªº¦r¬O§Ú­Ì»Ý­n¿é¤Jªº¡A¥»¨Ó°õ¦æ MASM¡BLINK¡BEXE2BIN ³o¤T­Óµ{¦¡³£¥²¶·¥ÎÁä½L¿é¤J¡A¦ý¦p¤µ³£¥Ñ§å¦¸Àɪº¤º®e¥N´À¤F¡C§å¦¸Àɪº¤º®e´N¦n¹³¬O§Ú­Ì¿é¤Jªº¦r¤@¼Ë¡A¦ý¬O§Ú­Ì¥u¦³«Ø¥ß§å¦¸Àɮɿé¤J¤@¦¸¦Ó¤w¡A¥H«á­n¥Î®É¡A¥u»Ý¦A¿é¤J§å¦¸ÀɦW©M­n²ÕĶ³sµ²ªº­ì©lÀÉÀɦW´N¥i¥H¤F¡C

µ²½×


µù¤@¡G¦pªG¦b DOS ¼Ò¦¡°õ¦æ MASM.EXE ®É«á­±¨S¦³¥[¤J²Õ¦X»y¨¥­ì©lÀɮצW®É¡AMASM.EXE ·|¸ß°Ý§A­ì©lÀÉ¡B¥ØªºÀÉ(*.OBJ)¡B¦CªíÀÉ(*.LST)¡A¥æ¤¬°Ñ¦ÒÀÉ(*.CRF)ªºÀɦW¡A¨ä¤¤MASM²Ä¤@­Ó¸ß°Ýªº¬O­ì©lÀɦW¡A³o¤@©w­n¿é¤J§_«h·|¤@ª½°Ý¤U¥h¡C¦A¨Ó´N¬O°Ý¥ØªºÀÉÀɦW¡A§Y¨Ï§A¨S¦³¿é¤J MASM.EXE ÁÙ¬O·|«Ø¥ßªº¨Ã¥B¥Î©M­ì©lÀɦW¦P¼Ëªº¦W¦r¡A¥u¬O°ÆÀɦW¤£¦P¡C¦Ó¦CªíÀÉ©M¥æ¤¬°Ñ¦ÒÀÉ¥i¦³¥iµL¡A­Yª½±µ«ö¤U Enter Áä¡A¨º»ò MASM ´N¤£·|«Ø¥ß¥L­Ì¡A¥L­Ì³£¬O¯Â¤å¦rÀÉ¡A¥i¥Î°O¨Æ¥»¨ÓÆ[¬Ý¡A§Ú·Q§A¬Ý¹L¤§«á´NÀ³¸Óª¾¹D¥¦­Ì¬O¤°»òªF¦è¡A¤p¤ì°¸´N¤£¦AÂØ­z¤F¡C
E:\HomePage\SOURCE>..\masm50\masm [Enter]
Microsoft (R) Macro Assembler Version 5.00
Copyright (C) Microsoft Corp 1981-1985, 1987.  All rights reserved.

Source filename [.ASM]: exam01 [Enter]
Object filename [exam01.OBJ]:[Enter]
Source listing  [NUL.LST]:[Enter]
Cross-reference [NUL.CRF]:[Enter]

  51544 + 418712 Bytes symbol space free

      0 Warning Errors
      0 Severe  Errors
¤W­±ªº¨Ò¤l´N¬O¥u¦³«Ø¥ß¥ØªºÀɦӤw¡C±`±`¬°¤F¤è«K¡A´N¿é¤J¡yMASM ­ì©lÀɦW; [Enter]¡zªí¥Ü¥u«Ø¥ß¥ØªºÀɦӤw¡C

¦pªG±z¥u¿é¤J

E:\HomePage\SOURCE>..\masm50\masm exam01 [Enter]

¦Ó¨S¦³¿é¤J¡y;¡z¡A¨º»ò MASM ·|¸ß°Ý±z¥ØªºÀÉ¡B¦CªíÀÉ¡B¥æ¤¬°Ñ¦ÒÀɪºÀɦW¡C

¼Æ¦~«e¨ì²{¦b ( ¥Á°ê 98 ¦~¡A¤]´N¬O¦è¤¸ 2009 ¦~ ) ³\¦h¤H³£¨Ï¥Î Win XP §@·~¨t²Î¡A³o®É Windows ¨t²Î¤w¨Ï¥Î¤Q´X¦~¤F¡A¥¦¦³ 32 ¦ì¤¸©M 64 ¦ì¤¸ª©¥»¡A¥B»P DOS ®É¥N 16 ¦ì¤¸ªº¥i°õ¦æÀɮ榡¤£¦P¡A©Ò¥H²£¥Í¤èªk¤]¤£¬Û¦P¡C

µù¤G¡G¥»³¹©Ò´£¨ìªº°²«ü¥O¦³ SEGMENT¡BENDS¡BASSUME¡BORG¡BDB ³o¨Ç«ü¥O¬O§i¶D²ÕĶ¾¹¸Ó¦p¦ó°Ê§@¡A¨Ò¦p°Ï¬qªº¶}©l»Pµ²§ô¡B¯d¤U´X­Ó¦ì¤¸²Õµ¹¬Y­ÓÅܼƨϥε¥µ¥¡A³o¨Ç¨Ã¤£¬O¦b°õ¦æ®É­Ô¤U¹Fµ¹ CPU ªº¡A¬GºÙ¬°°²«ü¥O¡C¦Ó JMP¡BMOV¡BINT ¬O¯u¥¿Åý CPU ¦³©Ò°Ê§@ªº«ü¥O¡AºÙ CPU «ü¥O¶°¡CIntel ªº CPU ¤§©Ò¥H¯à¬Û®e¡A¦³«Ü¤jªº¦]¯À´N¬O·sªº CPU ªº«ü¥O¶°¥]§t¤Fªº CPU ªº«ü¥O¶°¡C

µù¤T¡G100H ªº H ¬Oªí¥Ü³o 100 ¬O¤Q¤»¶i¦ì¼Æ¨Ã«D¤Q¶i¦ì¼Æ¡C¦pªG¼Æ¥Ø«á­±¨S¦³¥ô¦ó­^¤å¦r¡A´Nªí¥Ü¦¹¼Æ¬°¤Q¶i¦ì¡A¤Q¶i¦ì¤]¥i¥H¥Î D ªí¥Ü¡C¤K¶i¦ì©M¤G¶i¦ì¼Æ¤À§O¥Î¡yO¡z¡]­^¤å¦rªº O ¡^©M¡yB¡zªí¥Ü¡C³o¨Ç­^¤å¦r³£¬O¦b¼Æ¦r«á­±¡A¤j¤p¼g¬Ò¥i¡C¦¹¥~¤Q¤»¶i¦ì¼Æ²Ä¤@­Ó¦ì¼Æ¦pªG¬O­^¤å¦r¡A­n¦b³Ì«e­±ÃB¥~¥[¤W¤@­Ó¹s¡A§_«h·|³Q·í¦¨ÅܼƦW©Î¼Ð°O¦W¡C¦pªG±z¤£¼ô±x¤Q¶i¦ì¡B¤G¶i¦ì ©M¤Q¤»¶i¦ìªº¸Ü¡A½Ð¥ß§Y°Ñ¦Òªþ¿ý¤@¡A¦b²Õ¦X»y¨¥¤¤±`±`­n¥Î¨ì³o´XºØ¶i¦ìªk¡C

µù¥|¡G¡y^Z¡z³o­Ó¦r¬Oª½±µ«ö¤U F6 ³o­ÓÁä¡A¤]¥i¥H¥ý«ö¦í Ctrl Á䤣©ñ¦A«ö¤U Z Áä¡C

µù¤­¡G¸ô®|¡APATH¡A¬O¤@­Ó DOS ¤º³¡«ü¥O¡A¥i°Ñ¦Òªþ¿ý¤Tªº»¡©ú¡C¨ä»yªk¬O

path ¸ô®|1;¸ô®|2;¸ô®|3......
¦pªG¨Ï¥ÎªÌ¦b DOS ¼Ò¦¡¤U¿é¤J¦n¸ô®|«á¡A·í¨Ï¥ÎªÌ¿é¤J¤@­Ó¥i°õ¦æÀÉ¡ADOS ¥ý¦b²{¦bªº¥Ø¿ý¤º´M§ä­Õ­Y¨S¦³ªº¸Ü¡ADOS ·|¨Ì§Ç¨ì¸ô®|1¡B¸ô®|2 µ¥¸ô®|¥h´M§ä³o­Ó¥i°õ¦æÀÉ¡C

©Ò¥H¦pªG§Ú­Ì¦b²ÕĶ«e¤U

E:\HomePage\SOURCE>path E:\HomePage\MASM50 [Enter]

³o­Ó«ü¥O¡A¨º»ò²ÕĶ®É¡A¥u»Ý¿é¤J

E:\HomePage\SOURCE>masm exam01; [Enter]

´N¥i¥H¤F¡ADOS ·|¥ý¨ì E:\HomePage\SOURCE ³o­Ó¤l¥Ø¿ý¥h§ä§ä¬Ý¡A¦³¨S¦³ MASM.EXE¡A¦pªG¨S¦³ªº¸Ü¡A´N·|¨ì path ©Ò«ü©wªº¥Ø¿ý¥h§ä MASM.EXE¡A¦pªG§ä¨ìªº¸Ü¡A´N°õ¦æ¥¦¡C©Ò¥H¥H«á´N¤£¥Î¦A¿é¤J¡y..\masm50\¡z¡A¦P¼Ë¦a³sµ²®É¤]¤£¥Î¦A¿é¤J¡y..\masm50\¡z³o´X­Ó¦r¤F¡C

·í¸ô®|³]¥ß¦n¤§«á¡ADOS ·|±N¥¦¦s¦b°O¾ÐÅ骺¤@­Ó¦a¤è¡A¦]¦¹°£«D­×§ï©ÎÃö¾÷¡A§_«h DOS ¬O¤£·|§Ñ°Oªº¡C¦pªG§Ú­Ì³]¦n¤@­Ó¸ô®|¡A¦Ó«á¤S·Q¦b¸ô®|¤W¦A¥[¤W¤@­Ó¤l¥Ø¿ý¡A³o®É¥i¥Î¡y%path%¡z³o­ÓÅܼơA¡y%path%¡z¥Nªí«e¦¸¸ô®|¡C°²¦p±z­n DOS ·j´M¨â­Ó¥H¤Wªº¤l¥Ø¿ý¡A´N¥Î¡y;¡z±N¥¦¹j¶}¡C

±z¤]¥i¥H¦b DOS ´£¥Ü¤§¤U¿é¤J¡yset¡z«ü¥O¡AÀˬd¥Ø«e¤w¸g³]¦nªº¸ô®|¦³¨º¨Ç¡A¦ý¤d¸U¤£­n¿é¤J¡yset path=¡z¡A¦p¦¹¤@¨Ó´N·|§â¸ô®|³]¬°ªÅªº¡A¥ç§Y²M°£©Ò¦³¸ô®|¤F¡C


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