¤p¤ì°¸³Ì±`¥Îªº²ÕĶ¾¹¬O·L³n¥X«~ªº MASM¡A¨ä¤¤ªº¡yASM¡z·íµM¬O«ü¡yassembly¡z¤§Â²¼g¡A¦ý¬O±z¥iª¾¹D²Ä¤@Ó¡yM¡z¥Nªí¤°»ò·N¸q¡H¥i¯à¦³³\¦h¤H¥H¬°¬O·L³n ( Microsoft ) ªº²Ä¤@Ó¦r¥À¡A¤£¹L³o¬O¤£¹ïªº¡A¦]¬°¤@¯ë¹ï·L³nªºÂ²ºÙ¬O¡yMS¡z¡A©Ò¥H¤p¤ì°¸¥H¬°³oÓ¡yM¡z»P¨ä¥Nªí·L³n¤£¦p¥Nªí¥¨¶° ( macro ) ¨Ó±o¥¿½T¡C¥Ñ©R¦W´N¥i¥Hª¾¹D¨Ï¥Î¥¨¶°À³¸Ó¤]¬O¬Û·í«nªº¡A©Ò¥H¦b³o¤@³¹ùØ¡A¤p¤ì°¸¥´ºâ¤¶²Ð¦p¦ó¨Ï¥Î¥¨¶°¡C
¦ó¿×¥¨¶°¡H²³æªº»¡¬O¥Î¨Ó²¤Æ¼¶¼gì©lµ{¦¡ªº¤@ºØ»yªk¡C²Õ¦X»y¨¥¤ñ¨ä¥L°ª¶¥»y¨¥³Ì¤jªº¦n³B¬O®Ä²v»P©Ò¦ûÅé¿n¤p¡A¦ý¬O¼¶¼g²Õ¦X»y¨¥µ{¦¡©Òªáªººë¤O«o»·¤ñ°ª¶¥»y¨¥¦h¡A¦Ó¨äºûÅ@¦¨¥»¤]°ª¡Cì¦]¬O²Õ¦X»y¨¥¨C°õ¦æ¤@Ӱʧ@n¼Æ¦æ¡A¬Æ¦Ü¼Æ¤Q¦æ¡B¼Æ¦Ê¦æ«ü¥O¤~¯à§¹¦¨¡C°²¦p±z¥Î BASIC ¼g¹Lµ{¦¡¡An¦b¿Ã¹õ¤W¦L¥X¡yHellow, world!¡z³oÓ¦r¦êªº¸Ü¡A¥u»Ý¼g
PRINT "Hellow, world!"
§Y¥i¡A¦ý¥Î²Õ¦X»y¨¥ªº¸Ü¥²¶·³o¼Ë¼g
message db 'Hellow, world!$' mov ah,9 mov dx,offset message int 21h
¦Ü¤Ö»Ýn¥|¦æ«ü¥O¤~¯à§¹¦¨¡C·L³n¦³Å²©ó¦¹¡A©ó¬O§â¥Lµo¦æªº²ÕĶ¾¹¥[¤J¥¨¶°ªº¼gªk¡A¨Ï¨ä¯à²¤Æì©lµ{¦¡¤§¼¶¼g¡A¬Æ¦Ü¥i¥H©M°ª¶¥»y¨¥ªº¼gªk«ÜÃþ¦ü¡C
©³¤U¤p¤ì°¸±N¤¶²Ð¦p¦ó²¤Æ¡H¥H²Ä¤@³¹ªº EXAM01.ASM ¬°¨Ò§a¡Iì¨Óªºµ{¦¡½X¬O¡G
;*************************************** ;01
code segment ;02.code ¬q¶}©l¦ì§}
assume cs:code,ds:code ;03.°²³]µ{¦¡¬q¤Î¸ê®Æ¬q
org 100h ;04.¥i§ï¦¨ *.COM ÀÉ
;--------------------------------------- ;05.
start: jmp begin ;06.µ{¦¡¶i¤JÂI
mes db 'Hi, I learn assembly.$' ;07.n¦L¥Xªº°T®§
begin: mov dx,offset mes ;08.«ü¦V mes ªº¦ì§}
mov ah,9 ;09.«ü©wn©I¥sªºªA°È¸¹½X
int 21h ;10.©I¥s DOS ªA°Èµ{¦¡
mov ax,4c00h ;11.«ü©wn©I¥sªºªA°È¸¹½X
int 21h ;12.©I¥s DOS ªA°Èµ{¦¡
;--------------------------------------- ;13.
code ends ;14.code ¬qµ²§ô
;*************************************** ;15.
end start ;16.¨Ï²ÕĶ¾¹ª¾¹Dµ{¦¡¶i¤JÂI
¤ÀªRµ{¦¡½X (¥Õ¦â³¡¤À)¡A¥i¤À¬°¨âÓ¨BÆJ¡A²Ä¤@¨B¬O¦L¥X¦r¦ê¡A¥Î¥h¤T¦æµ{¦¡½X¡A²Ä¤G¨B¬Oµ²§ôµ{¦¡¡A¥Î¥h¨â¦æ¡C¤p¤ì°¸¤À§O¥H display¡Bexit ³o¨âÓ¥¨¶°¥N´À¡Aµ{¦¡Åܦ¨
page ,132 ;01 ³]©w¶ªø»P¶¼e ( µù¤@ )
display macro string ;02 ©w¸q display ¥¨¶°
local st_addr,dsp_str ;03 ³]©w¼Ð¸¹ dsp_str ¬°§½³¡¼Ð¸¹
jmp short dsp_str ;04 µuµ{¸õÅD
st_addr db string,'$' ;05 ¥Ñ¥¨¶°¿é¤J¤Þ¼Æ¨M©w©Ò©w¸q¤§¦r¦ê
dsp_str: ;06 ©w¸q dsp_str ¼Ð¸¹
mov ah,9
mov dx,offset st_addr ;08 ¨ú±o st_addr ¤§¦ì§}
int 21h ;09 ©ó¿Ã¹õ¤W¦L¥X st_addr ¦r¦ê
endm ;10 display ¥¨¶°µ²§ô
exit macro exit_code ;12 ©w¸q exit ¥¨¶°
mov ah,4ch
mov al,exit_code ;14 ¨Ï AL µ¥©óªð¦^½X
int 21h ;15 ©I¥s DOS ªA°È¤¤Â_¥Hµ²§ô¥»µ{¦¡
endm ;16 exit ¥¨¶°µ²§ô
;***************************************
code segment
assume cs:code,ds:code
org 100h
;---------------------------------------
start: display 'Hi, I learn assembly.' ;23 ¦L¥X¦r¦ê
exit 0 ;24 µ²§ôµ{¦¡
;---------------------------------------
code ends
;***************************************
end start
³o¼Ëµ{¦¡½X ( ¥Õ¦â³¡¤À ) ¥uÅܦ¨¨â¦æ¡A¨Ï¥Î display ¤Î exit ³o¨âÓ¥¨¶°¡A¦bµ{¦¡¤p®É¤£©ö¬Ý¥X¨äÀuÂI¡A¦ý¬Oµ{¦¡¤j®É´N·|¨Ï±oì©lµ{¦¡«Ü®e©ö¾\Ū»Pקï¡Cn¨Ï¥Î¥¨¶°¡A¥²¶·¥ý©w¸q¥¨¶°¡A¤@¯ë¥¨¶°¥i¥H¼g¦bì©lµ{¦¡ùØ¡A¤]¥i¥H¼g¦b¥¨¶°µ{¦¡®w ( §t¤JÀÉ ) ùØ¡A¦pªGª½±µ¼g¦bì©lµ{¦¡ùØ¡A¤@¯ë¬O¦bµ{¦¡³Ì«e±¥ý©w¸q¨ä¤º®e¡C
¥¨¶°ªº¤º®e¥²¶·©w¸q¦b macro ©M endm ³o¨âÓ¦r¤§¶¡¡A¨ä§Î¦¡¹³
name macro x,y,z¡K¡K ¡K¡K¡K µ{¦¡½X ¡K¡K¡K endm
name ¬O¸Ó¥¨¶°ªº¦WºÙ¡A¤]´N¬Oµ¹µ{¦¡¨Ï¥Î®É¡y©I¥s¡z¤§¥Îªº¡Cx¡By¡Bz¡K¡Kµ¥¬O¸Ó¥¨¶°ªº¿é¤J¤Þ¼Æ¡A¿é¤J¤Þ¼Æ¥i¥H¦³¤@Ó¡B©Î¨âÓ¡B©Î¤TÓ¡K¡Kª½¨ì MASM ²ÕĶ¾¹ªº²Å¸¹°Ï³Q¶ñº¡¬°¤î¡A¥¨¶°¤]¥i¥H¨S¦³¿é¤J¤Þ¼Æ¡A¥þµø»Ýn¦Ó©w¡C¥¨¶°¦WºÙ¥i¥H¥ô·N¨ú¦W¡A¦ý¤£¥i¥Î¨ì MASM ªº«O¯d¦r©Î CPU «ü¥O¡C¥¨¶°µ²§ô®É¥Î endm ªí¥Ü¡A³oÓ¡ym¡z§Yªí¥Ü¥¨¶°¤§·N¡Anª`·Nªº¬O endm ¤§«e¤£¥i¥[¥¨¶°¦WºÙ¡A²ÕĶ¾¹·|¦Û°Ê°t¦X¡C°²¦p±z¦³»Ýn¡A¤]¥i¥H¦b¥¨¶°¤¤¨Ï¥Î¥t¥~¤@Ó¥¨¶°¡C
ì©lµ{¦¡¤¤¨Ï¥Î¥¨¶°®É¡Aª½±µ¼g¥X¥¨¶°¦WºÙ¤Î¨ä¿é¤J¤Þ¼Æ§Y¥i¡A´N¹³¤Wzµ{¦¡ªº²Ä 23¡B24 ¦æ¡C·í²ÕĶ¾¹²ÕĶì©lÀɮɡA²ÕĶ¾¹·|¦Û°Ê¥H¥¨¶°¤º®e¨ú¥N¸Ó¦æ¥¨¶°¦WºÙ¡A¥H¥¨¶°¦WºÙ«á¤§¼ÆȨú¥N¤Þ¼Æ¡C¹³¤W±ªº¨Ò¤l¡A·í²ÕĶ¾¹¬Ý¨ìì©lµ{¦¡ªº²Ä 24 ¦æ¡Aexit 0¡A¥Ñ«e±©w¸qª¾¹D³o¬O¤@Ó¥¨¶°¡A©ó¬O exit 0¡A³o¤@¦æ¦Û°ÊÅܦ¨
mov ah,4ch mov al,quit_code int 21h
¦Ó quit_code ³Q¿é¤J¤Þ¼Æ¡A0¡A¨ú¥N¡A©ó¬O¶i¤@¨BÅܦ¨
mov ah,4ch mov al,0 int 21h
¹³³oºØ¨ú¥N¤u§@ºÙ¤§¬°¥¨¶°¥N´« ( macro subtitution ) ©Î¥¨¶°®i¶} ( macro expansion )¡C¥¨¶°®i¶}»P©I¥s°Æµ{¦¡¨Ã¤£¬Û¦P¡A¨C¤@¦¸®i¶}¥¨¶°®É¡A²ÕĶ¾¹³£¬O§â¥¨¶°µ{¦¡½X·Ó§Û¤@¹M¡A¥u¦³¿é¤J¤Þ¼Æ¤£¦P¦Ó¤w¡A©Ò¥H¦pªG±zªºµ{¦¡®i¶} 10 ¦¸¬Û¦Pªº¥¨¶°¡A¨ä°õ¦æÀÉ®×¼W¥[ªº¤j¤p¤j¬ù¬O¥¨¶°ªº 10 ¿¡A·í°õ¦æ¨ì®i¶}ªº¥¨¶°®É¡Aµ{¦¡·ÓµÛ®i¶}ªºµ{¦¡½X°õ¦æ¡A¤£Âಾ¬yµ{¡C¦Ó©I¥s°Æµ{¦¡¬O¨Ïµ{¦¡¬yµ{Âಾ¨ì°Æµ{¦¡³B°õ¦æ¡A°õ¦æ§¹°Æµ{¦¡«á¤Sªð¦^¥Dµ{¦¡¡A¬G§Y¨Ï±z©I¥s 10 ¦¸¬Û¦Pªº°Æµ{¦¡¡A¦Ó¸Ó°Æµ{¦¡¥u¦³¤@¬q¡A¦Ó¥B©I¥s°Æµ{¦¡®É¥²¶·¥ý¨Ï¤UÓ«ü¥O¦ì§}±À¤J°ïÅ|¡A¦A²¾Âà¦Ü°Æµ{¦¡³B¡C
¦n¤F¡Aexit ¥¨¶°¤w¸g¤¶²Ð¹L¤F¡A¨º display ¥¨¶°¸Ì±¦h¤F¤@Ó©_©Çªº°²«ü¥O LOCAL ¬O¤°»ò§@¥Î©O¡H¥ý¤£ºÞ LOCAL ³oÓ°²«ü¥O¡A§ÚÌ¥ý§â dispaly ¥¨¶°®i¶}¡A¬Ý¨ì²Ä 23 ¦æ¦³ display ªº¿é¤J¤Þ¼Æ¡Astring¡A¬°¤@Ó¦r¦ê¡A¡yHi, I learn assembly.¡z¡A©Ò¥H¸Ó¥¨¶°©Ò¦³ªº string ³£Åܦ¨¡yHi, I learn assembly.¡z¡A¦A¬Ý²Ä 5 ¦æ¡A´NÅܦ¨¡G
st_addr db 'Hi, I learn assembly.','$'
©Ò¥H²Ä 23 ¦æ®i¶}«áÅܦ¨²Ä 4 ¦æ¨ì²Ä 9 ¦æ¡A¥u¬O st_addr ¦r¦êÅܦ¨¤Wz¤º®e¤F¡C³o¼Ë¦ü¥G¤@¤Á³£«Ü§¹¬ü¡AÀ³¸Ó¤£»Ýn local ³oÓ°²«ü¥O§a¡Hªº½T¡A¦b³oÓµ{¦¡ùØ¡A¦³¨S¦³ local ¬O¤@¼Ëªº¡A¦ý¬O¦pªG¦b³oÓµ{¦¡ùئA¨Ï¥Î¤@¦¸ display ¥¨¶°®É¡AMASM ´N·|µLªk²ÕĶ¡A¥¦·|§i¶D±z«½Æ©w¸qÅܼƦW¤Î¼Ð°O¦W¡Aì¦]¬O display ®i¶}®É¡A·|²£¥Í¨âÓ st_addr ¦r¦êÅܼƤΨâÓ dip_str ¼Ð°O¡C
¨Æ¹ê¤W¡A±zª¾¹D¡A³oÓ¦r¦ê»P¼Ð°O¥Î¤°»ò¦WºÙ¨ä¹ê¨Ã¤£«n¡A¬°¤F¸Ñ¨M³oÓ°ÝÃD¡AMASM ´£¨Ñ¤@Ó local °²«ü¥O¡Alocal ªí¥Üst_addr¡Bdsp_str ¬O¤@Ó§½³¡ÅܼƻP§½³¡¼Ð°O¡A¥¦ªº¦WºÙ¥u¦b¥»¦¸¨Ï¥Îªº¥¨¶°ùئ³®Ä¡A·í¤U¦¸¦A¨Ï¥Î³oÓ¥¨¶°®É¡A°Ï°ìÅܼƻP§½³¡¼Ð°Oªº¦WºÙ§ïÅÜ¡C¨Æ¹ê¤W¡AMASM °Ï°ìÅܼƷ|¨Ì¡y??NNNN¡zªº¶¶§Ç§ó´«¡A¦¹³Bªº NNNN ¬O¥Ñ 0000 ¶}©lªº¤Q¤»¶i¦ì¾ã¼Æ¨Ì¦¸»¼¼W¡C©Ò¥H²Ä¤@¦¸¨Ï¥Î display ®É¡Ast_addr ·|Åܬ°¡y??0000¡z¡Adsp_str Åܦ¨¡y??0001¡z¡A²Ä¤G¦¸¨Ï¥Î display ®É¡Ast_addr Åܦ¨¡y??0002¡z¡Adsp_str Åܦ¨¡y??0003¡z¡K¡K¡A³o¼Ë display ´N¯à«½Æ¨Ï¥Î¤F¡C
¦¹¥~¡A¨Ï¥Î local °²«ü¥O®É¡AÁÙ¦³¤@ÂInª`·N¡A§_«h¥²©w·|¥X¿ù¡C¨º´N¬O local ¤@©wn©ñ¦b¥¨¶°¤º®eªº²Ä¤@¦æ¡C¦n§a¡I©³¤U§ÚÌ¨Ó¬Ý¬Ý EXAM03.ASM ²ÕĶ®É©Ò«Ø¥ßªº EXAM03.LST ÀÉ¡A¥¨¶°®i¶}ªº¼Ë¤l¡C
H:\HomePage\SOURCE>masm exam03 [Enter] Microsoft (R) Macro Assembler Version 5.00 Copyright (C) Microsoft Corp 1981-1985, 1987. All rights reserved. Object filename [exam03.OBJ]: [Enter] Source listing [NUL.LST]: exam03 [Enter] ¡÷¿é¤J LST ÀÉ¥HÆ[¹î¥¨¶° Cross-reference [NUL.CRF]: [Enter] 50964 + 365948 Bytes symbol space free 0 Warning Errors 0 Severe Errors H:\HomePage\SOURCE>link exam03; [Enter] Microsoft (R) Personal Computer Linker Version 2.40 Copyright (C) Microsoft Corp 1983, 1984, 1985. All rights reserved. Warning: no stack segment H:\HomePage\SOURCE>exe2bin exam03 exam03.com [Enter] H:\HomePage\SOURCE>dir exam03.* [Enter] Volume in drive H is DATA_1 Volume Serial Number is 0330-08F6 Directory of H:\HomePage\SOURCE EXAM03 LST 3,236 02-08-03 0:19 EXAM03.LST EXAM03 OBJ 107 02-08-03 0:19 EXAM03.OBJ EXAM03 EXE 805 02-08-03 0:19 EXAM03.EXE EXAM03 COM 37 02-08-03 0:20 EXAM03.COM EXAM03 ASM 1,279 02-08-03 0:00 EXAM03.ASM 5 file(s) 5,464 bytes 0 dir(s) 3,689.07 MB free H:\HomePage\SOURCE>
LST ¬O¤@Ó¦CªíÀÉ¡AÄÝ©ó¯Â¤å¦rÀÉ¡A±z¥i¥H¥Î¥ô¦ó¤@Ó¤å®Ñ³B²z¾¹¶}±Ò¥¦¡A¨ÃÆ[¹î¥¦¡A·|¬Ý¨£¤U±ªºµ{¦¡½X¡C
start: display 'Hi, I learn assembly.' 1 jmp short ??0001 1 ??0000 db 'Hi, I learn assembly.', 1 ??0001: 1 mov ah,9 1 mov dx,offset ??0000 1 int 21h exit 0 1 mov ah,4ch 1 mov al,0 1 int 21h
¶À¦âªº¡y1¡zªí¥Ü¥¨¶°®i¶}¡Aª`·N¨ì¬õ¦â³¡¤ÀªºÅܼƦW»P¼Ð°O¦W³£³Q§ó´«¤F¡C
°²¦p±z¼g¤F³\¦h¥¨¶°µ{¦¡¡A¨º»ò±z¤]¥i¥H§â³o¨Ç¥¨¶°¶°¦X°_¨ÓÅܦ¨¤@ӯ¤å¦rÀÉ¡A³o¼Ë´N«Ø¥ß°_¥¨¶°µ{¦¡®w¡A·í±z¼¶¼g·sªºµ{¦¡®É¥i¥H§â³oÓ¥¨¶°µ{¦¡®w¥]§t¶i¨Ó¡C¦p¦¹¤@¨Ó¡A±z¥un¼g¤@¦¸¥¨¶°¡A´N¥i¥H¦b³\¦hµ{¦¡ùبϥΡA¸`¬Ù³\¦h·Ðº¾ªº¤u§@¡A°£¦¹¤§¥~¡A±zªºµ{¦¡¬Ý°_¨Ó·|«Ü²¼ä¡A´N·|¹³°ª¶¥»y¨¥¤@¼Ë¤ñ¸û¦nºûÅ@¡C
¨Æ¹ê¤W¡AMASM ¦w¸Ë¦n«á¡AINCLUDE ¤l¥Ø¿ýùر¡A´N´£¨Ñ³\¦h¥¨¶°µ{¦¡®w¡C¥¨¶°µ{¦¡®w©M²Ä 10 ³¹©Ò´£¨ìªºµ{¦¡®w¬O¤£¤@¼Ëªº¡A¥¨¶°µ{¦¡®w¬O¥Ñ¤å®Ñ³B²z¾¹½s¿è¦Ó¦¨ªº¯Â¤å¦rÀÉ¡A´£¨Ñ MASM ²ÕĶ¥Îªº¡A¤@¯ë°ÆÀɦW¬O *.H¡B*.INC ©Î *.MAC ( H¡BINC¡BMAC ¤À§O¬O head¡Binclude¡Bmacro ¤§·N )¡F¦Óµ{¦¡®w¬O°Æµ{¦¡ªº¥ØªºÀɸg¥Ñ LIB ½s½X¨Ã¶°¦X°_¨Ó©Ò»s§@ªº¤G¶i¦ìÀÉ¡A¬O´£¨Ñµ¹ LINK ³sµ²¥Îªº¡A°ÆÀɦW¬O *.LIB¡C
INCLUDE °²«ü¥O´N¬O¬°¤F¦bì©lÀÉùاt¬A¥¨¶°µ{¦¡Àɪº¡A»yªk¬O
include ¥¨¶°µ{¦¡ÀÉÀɦW
³oÓÀɦW¥i¥H¥]§tºÏºÐ¾÷¦W¡B¸ô®|¡C
°²¦p±zªº¥¨¶°µ{¦¡ÀɤӤj¡A¥HP¥]§t¤F³\¦h¥¨¶°¡A¦ý±z¥i¯à¥u¥Î¤F¨ä¤¤ªº¤@³¡¥÷¡A¦Ó¨S¥Î¨ìªº³¡¤ÀÁöµM¤£·|³Q²ÕĶ¡A¦ý¬O²ÕĶ®É·|®ø¯Ó°O¾ÐÅé¡A¥HP¨Ï MASM ²Å¸¹ªÅ¶¡¤£°÷¥Î¡A³o®ÉÔ¥i¥H¥Î purge °²«ü¥O¨Ï MASM ©¿²¤¥¦¡C¨ä»yªk¬°
purge ¥¨¶°¦W1, ¥¨¶°¦W2, ¥¨¶°¦W3¡K¡K
±µ¦b purge ¤§«áªº´N¬On¨Ï¨ä¤£§@¥Îªº¥¨¶°¡C
EXAM03.ASM ³oÓµ{¦¡ùØ¡Aµ{¦¡½X»P¸ê®Æ¤¬¬Û¥æ¤e¡A¬°¤F§ïµ½³oÓ¯ÊÂI¡A¤p¤ì°¸§â display ¥¨¶°¥[¥H§ï¨}¡C©³¤U¬O§ï¨}«áªº¥¨¶°µ{¦¡®w¡G
display macro string local str data segment para public 'data' str db string,'$' data ends code segment para public 'code' mov ah,9 mov dx,offset str int 21h code ends endm exit macro quit_code code segment para public 'code' mov al,quit_code mov ah,4ch int 21h code ends endm initial macro stack segment stack db 128 dup ('stack ') stack ends data segment para public 'data' data ends code segment para public 'code' assume cs:code,ds:data start: push ds sub ax,ax push ax mov ax,data mov ds,ax code ends endm
§â¤Wzµ{¦¡¦s¦¨ MYMAC.INC ¥¨¶°µ{¦¡®w¡A¦Óì©lµ{¦¡Åܦ¨¡G
include mymac.inc initial display 'I learn Macro Assembly.' ;¦L¥X¡yI learn Macro Assembly.¡z¦r¦ê display <0dh,0ah> ;´«¦æ display 'It is very fun!' ;¦L¥X¡yIt is very fun!¡z¦r¦ê exit 0 end start
¤p¤ì°¸§â³oÓµ{¦¡¨ú¦W¬° EXAM04.ASM¡A±z¬Ý³oÓµ{¦¡¤@ÂI¤]¤£¹³²Õ¦X»y¨¥¡A˹³¬O¤@ºØ°ª¶¥»y¨¥¡A¦ý¬O¥¦²ÕĶ«á¥i°õ¦æÀɤj«o«Ü¤p¡A¥Î DEBUG Æ[¹î¡A§¹§¹¥þ¥þ¬O²Õ¦X»y¨¥¡A³o´N¬O¤p¤ì°¸¦b¥»³¹¤@¶}©l»¡¡A¥¨¶°Â²¤Æ¤F²Õ¦X»y¨¥¡A¨Ï²Õ¦X»y¨¥»yªkÁͦV°ª¶¥»y¨¥¡C¤£¹L©O¡A±z±o°O±o¡A³o¥u¬Oµ{«×¤Wªº°ÝÃD¡A¨Æ¹ê¤Wn¥Î¥¨¶°¨Ï²Õ¦X»y¨¥¯à§¹¥þ¹³°ª¶¥»y¨¥¤@¼Ë¡AÁÙ¦³¦n¤j¤@¬q¶ZÂ÷¡AÁÙ±o°t¦X¡y±ø¥ó²ÕĶ¡z¤~¯à±µªñ³oӥتº¡Cª`·N¡I¤p¤ì°¸¥u»¡¡y±µªñ¡z¦Ó¤w¡A¨Ã¨S¦³»¡¯à§¹¥þ¹³°ª¶¥»y¨¥¤@¼Ë¡C¦n§a¡I©³¤U§Ú̬ݬݳoÓµ{¦¡»P¥¨¶°®w¡C
¦b³oÓ¥¨¶°ùØ¡A¤p¤ì°¸¥Î¤F©³¤Uªº¤@ÓÆ[©À¡C·í§Ú̦bµ{¦¡¤¤©w¸q¤@ӰϬq®É¡A¥i¥H§â³oӰϬq¤À´²¶}¨Ó¡A¥un¦b¦X¨Ö§Î¦¡»PÃþ§O¦W¥[¥H¾A·íªº©w¸q¡A³sµ²¾¹´N·|¦Û°Ê¦a§â³oÓ¤À´²©óì©lµ{¦¡¦U³Bªº°Ï¬q¤ù¬q¡A¦X¦¨¤@Ó³sÄòªº°Ï¬q¡A½Ð°Ñ¦Ò²Ä 11 ³¹¦³Ãö segment °²«ü¥Oªº»¡©ú¡A¥H³oÓµ{¦¡¦Ó¨¥¡A¤p¤ì°¸§â©Ò¦³¤À´²¦U³Bªº data °Ï¬q¤§Ãþ§O¦W¨ú¦W¬°¡ydata¡z¡Acode °Ï¬q¨ú¦W¬°¡ycode¡z¡A¨Ã¥B¦X¨Ö§Î¦¡«ü©w¬°¡ypublic¡z¡Aªí¥Ü¬Û¦P¤§Ãþ§O¦W»P°Ï¬q¦W¦X¦¨¤@³sÄò°Ï¬q¡C¦p¤U¹Ï¡A¥ªÃä¬O®i¶}«áªºì©lµ{¦¡¡A¦Ó¥kÃä¬O³sµ²¾¹¦X¨Ö«áªº¥i°õ¦æÀɤºªºµ{¦¡½X¡C
stack segment stack db 128 dup ('stack ') stack ends data segment para public 'data' data ends code segment para public 'code' assume cs:code,ds:data start: push ds sub ax,ax push ax mov ax,data mov ds,ax code ends data segment para public 'data' ??0000 db 'I learn Macro Assembly.','$' data ends code segment para public 'code' mov ah,9 mov dx,offset ??0000 int 21h code ends data segment para public 'data' ??0001 db 0dh,0ah,'$' data ends code segment para public 'code' mov ah,9 mov dx,offset ??0001 int 21h code ends data segment para public 'data' ??0002 db 'It is very fun!','$' data ends code segment para public 'code' mov ah,9 mov dx,offset ??0002 int 21h code ends code segment para public 'code' mov al,0 mov ah,4ch int 21h code ends |
stack segment stack db 128 dup ('stack ') stack ends data segment para public 'data' ??0000 db 'I learn Macro Assembly.','$' ??0001 db 0dh,0ah,'$' ??0002 db 'It is very fun!','$' data ends code segment para public 'code' start: push ds sub ax,ax push ax mov ax,data mov ds,ax mov ah,9 mov dx,offset ??0000 int 21h mov ah,9 mov dx,offset ??0001 int 21h mov ah,9 mov dx,offset ??0002 int 21h mov al,0 mov ah,4ch int 21h code ends |
°ïÅ|¬q¥u¦³¤@Ó¡A¤£»P¨ä¥L°Ï¬q¦X¨Ö¡Fµ{¦¡½X°Ï¬q¤À´² 5 ³B¡A¤p¤ì°¸¥H¶À¦âªí¥Ü¡F¸ê®Æ°Ï¬q¤À´² 4 ³B¡A¥HÂŦâªí¥Ü¡C³sµ²«á¡A5 ³Bµ{¦¡½X°Ï¬q·|¦X¨Ö¦¨¤@Ó³sÄòªº°Ï¬q¡A4 ³B¸ê®Æ°Ï¬q¤]·|¦X¨Ö¦¨¤@Ó³sÄòªº°Ï¬q¡C
¤p¤ì°¸·Q¡A±z¥i¯à¤w¸g²q±oµÛ¡A³o¹ï¨¤¬A¸¹ªº·N«ä¬O¨Ï¦b¨¤¬A¸¹¤ºªº©Ò¦³¹Bºâ¤¸Åܦ¨¤@Ó¦r¦êÅܼơA%¡B&¡B;;¡B! µ¥¯S®í¦r³£·|¥¢¥h®Ä¤O¡AÅܦ¨¦r¤¸¡A©M¨¤¬A¸¹ªº¨ä¥L¦rÅܦ¨¤@Ó¦r¦ê¡C¦b³oÓ¨Ò¤lùØ¡A°²¦p±z¥Î
display 0dh,0ah
ªº¸Ü¡Aµ²ªG¥u¦³ 0dh ³QÅã¥Ü©ó¿Ã¥ú¹õ¤W¡A³o¬O¦]¬° display ¥¨¶°¥u¦³¤@Ӥ޼ơA©Ò¥Hµ²ªG¨Ã¤£¬O§ÚÌ·Qnªº¡C©³¤U¦A¤¶²Ð´XºØ¦b¥¨¶°ùر`¥Îªº¤å¦r¹Bºâ¤l¡C
& ¬O±j¢¨Ï¿é¤J¤Þ¼Æ¨ú¥N¡y&¡z«á±ªº¹Bºâ¤¸¡A¦Ó¥B¤£ºÞ & ¥X²{¦b¨ºùØ¡C¨Ò¦p¦³Ó¥¨¶°¬O
error_code macro x,y err&x db 'Error &x : &y' endm
Y¬O¥Î¤U±±Ôz¨Ï¥Î¦¹¥¨¶°
error_code 5,<ºÏºÐ¾÷µLªkŪ¨ú>
®i¶}«áÅܦ¨
err5 db 'Error 5 : ºÏºÐ¾÷µLªkŪ¨ú'
Âù¤À¸¹¤§«áªº¤å¦r·|³Q²ÕĶ¾¹©¿²¤¡A¨Ã¥B¦b *.LST Àɤ¤®i¶}¥¨¶°®É¤£·|¥X²{¡A¥u¦³¦b©w¸q¥¨¶°®É¤~¥X²{¡A¦]¦¹±`¦b¥¨¶°¤¤³Q¥Î¨Ó°µ¬°µù¸Ñ¡C·íµM¡A¦b¥¨¶°¤¤±z¤]¥i¥H¨Ï¥Î¡y;¡z°µ¬°µù¸Ñ¡A¦ý¬O¡y;¡z¦b©w¸q¥¨¶°¥H¤Î®i¶}¥¨¶°®É³£·|¥X²{µù¸Ñ¡C
³oÓ¹Bºâ¤l¬O¨Ï¨ä«á©Ò±µªº¹Bºâ¦¡ºâ¥X¨Ó¡A¨Ï¥¦±a¶i¥¨¶°ªº¤Þ¼ÆùØ¡A¤]´N¬O»¡¡A¡y%¡z¹Bºâ¤l¥u¯à¥Î¦b¥¨¶°¤Þ¼Æ¦CùØ¡C
³oÓ¹Bºâ¤l¨Ï¨ä«á±µªº¤@Ó¦r¤¸¤£ºÞ¬O¤£¬O¯S®í¦r¤¸ ( ¨Ò¦p <¡B>¡B%¡B&¡B;¡B! ) ³£¬Ý¦¨¬O¤@Ó´¶³qªº¦r¤¸¡C¨Ò¦p¨Ï¥Î¤W¨Ò¥¨¶°
error_code 103,<¹Bºâ¤¸ !> 255 >
®i¶}«áÅܦ¨
err103 db 'Error 103 : ¹Bºâ¤¸ > 255 '
¦b¼¶¼gµ{¦¡®É¡A±`±`·|n©w¸q¸ê®Æ¡A¨Ò¦p©w¸q^¤å¦r¥À¡A³Ìª½±µªº¤èªk¬O¡G
alpha db 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
¦ý¬O¡A¦pªG¸ê®Æ¤Óªø®É¡A´N«Ü¤£¤è«K¡A³o®É¥i¥H¥Î¡y«½Æ°Ï¶ô¡z¨Ó©w¸q¡CMASM ´£¨Ñªº«½Æ°Ï¶ô¦³¤TºØ¡A¤£ºÞ¬O¨º¤@ºØ«½Æ°Ï¶ô¡A³£¨S¦³¦W¦r¡A¦]¦¹¤£¯à³Qµ{¦¡¡y©I¥s¡z¡A¤@¯ë¦Ó¨¥¡A«½Æ°Ï¶ô³£¬Oª½±µ¤º´O©óµ{¦¡¤¤¡A©Î¥H¥t¤@Ó¥¨¶°¥]§t°_¨Ó¡C
³o¬O¥Î¨Ó«Ø¥ß¦³³W«hªº«½Æ°Ï¶ô¡A¦³³W«hªº·N«ä¬O«ü¨C¦¸ªºÅܤƶq³£¬O¬Û¦Pªº¡C¨ä»yªk¬O¡G
REPT ¼Æ¾Ç¦¡ ¡K¡K ±Ôz ¡K¡K ENDM
¼Æ¾Ç¦¡ªº¹Bºâµ²ªG¥²¶·¬O¤@Ó 16 ¦ì¤¸ªº¥¿¼Æ¡A¥¦¥Nªí¥Ñ REPT ¨ì ENDM ¤§¶¡ªº«½Æ¦¸¼Æ¡CREPT ¹ê»Ú¤W¦b¨Ï¥Î®É¡A¨C¤@¦¸ªº±¡§Î±`±`¬O©M¤W¤@¦¸¤£¦P¡A¦]¦¹±`±`n³]¤@ÓÅܼƨӰO¿ý³oÓÈ¡A¦Ó³oÓÅܼƨ䣷|¦b°O¾ÐÅéùئû¾Ú¤@¶ôªÅ¶¡¡A©Ò¥HºÙ¬°¡yµêÀÀÅܼơz¡A¨Æ¹ê¤W¥¨¶°¤Þ¼Æ¤]¬O¤@ºØµêÀÀÅܼơC¦n§a¡I¦^¹LÀY¨ÓÄ~Äò»¡©ú REPT ªº¨Ï¥Î¤èªk¡A³oÓµêÀÀÅܼƪº°_©lÈ¥²¶·n¦b REPT¡KENDM °Ï¶ô¤§«e¥ý³]©w¡AµM«á¦b°Ï¶ô¤¤¥[¥H§ïÅܳoÓµêÀÀÅܼƤ§È¡C
¥Î¨Ó³]©w³oÓµêÀÀÅܼƪº«ü¥O¬O¡y=¡z¡A¥L©M EQU °²«ü¥O¤£¦Pªº¦a¤è¬O¡AEQU ©Ò³]©w¤§ª½¬O±`¼Æ¡AµLªk¦A§ó§ï¡Q¦Ó¥Î¡y=¡z©Ò«ü©wªºÅܼƬOÁÙ¥i¥H¦A§ó§ïªº¡A³o¨âÓ°²«ü¥O¬Û¦P³B«K¬O¸ÓÅܼƳ£¤£·|¦û¾Ú°O¾ÐÅé¡C= ªº»yªk¬O
ÅܼƦW = ¼Æ¾Ç¦¡
©³¤U³oÓ¥¨¶°¬O¥Î¨Ó¦b°O¾ÐÅ餤©w¸q 41H¡B42H¡B43H¡B44H¡K¡K5AH¡A¤]´N¬O
db 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
·íµM¤W±¬O³Ìª½±µªº¤èªk¡A¦ý¤]¥i¥H¥Î¤U±ªº¤èªk
x = 0 REPT 26 db 'A'+x x = x+1 ENDM
¤p¤ì°¸§â¤Wz«½Æ°Ï¶ô¼g¦¨¤@Ó§¹¾ãªºµ{¦¡¡G
include mymac.inc alpha MACRO data segment para public 'data' x = 0 ;05 ³]©wµêÀÀÅܼư_©lÈ letters EQU THIS BYTE ;06 ©w¸q'ABC¡KZ'¦r¦ê¤§¦ì§} REPT 26 ;07 ¦@¦³ 26 Ó^¤å¦r¥À db 'A'+x ;08 ©w¸q¨C¤@Ó^¤å¦r¥À x = x+1 ;09 ³]©w¤U¤@¦¸¤§µêÀÀÅÜ¼Æ ENDM ;10 «½Æ°Ï¶ôµ²§ô db '$' ;11 'ABC¡KZ'¦r¦êµ²§ô data ends ENDM ;13 alpha ¥¨¶°µ²§ô print MACRO string code segment para public 'code' mov ah,9 mov dx,offset string int 21h code ends ENDM initial alpha print letters exit 0 end start
³oÓµ{¦¡¦b²ÕĶ»P³sµ²«á¡A°õ¦æ®É·|¦b¿Ã¹õ¤W¦L¥X¡yABCDEFGHIJKLMNOPQRSTUVWXYZ¡z26 Ó^¤å¦r¥À¡C
IRP ³QºÙ¬°¤£©w«½Æ ( indefinite repeat )¡A¥Nªí¨C¦¸«½ÆªºµêÀÀÅܼƨ䣳W«h¡A¨ä»yªk¬O
IRP °Ñ¼Æ,<¤Þ¼Æ1, ¤Þ¼Æ2, ¤Þ¼Æ3¡K¡K> ¡K¡K¡K ±Ôz ¡K¡K¡K ENDM
·í MASM ¹J¨ì IRP °²«ü¥O®É¡Aº¥ý·|¥H¡y¤Þ¼Æ1¡z¤§È¥N¤J°Ñ¼ÆùزÕĶ¡A¤@ª½¹J¨ì ENDM ®É¡A¦A¥H¡y¤Þ¼Æ2¡z¥N¤J°Ñ¼Æ²ÕĶ¡K¡K¦p¦¹«½Æª½¨ì©Ò¦³ªº¤Þ¼Æµ²§ô¬°¤î¡C¦p¦¹¤@¨Ó¡A¨C¤@¦¸²ÕĶ±¡§Î¦]¬°¿é¤J¤Þ¼Æ¥i¥H¥Ñ³]pªÌ¦Û¥Ñ¨M©w¡A©Ò¥H¥i¥H¬O¨S¦³³W«hªº¡C
»yªk¬°
IRPC °Ñ¼Æ¡A¦r¦ê ¡K¡K¡K ±Ôz ¡K¡K¡K ENDM
·í MASM ¹J¨£ IRPC °Ï¶ô®É¡Aº¥ý·|¥H¦r¦êªº²Ä¤@Ó¦r¤¸¥N¤J°Ñ¼Æ¤¤²ÕĶ¨ä«áªº±Ôz¡Aª½¨ì¹J¨£ ENDM¡AµM«á¦A¥H¦r¦êªº²Ä¤GÓ¦r¤¸¥N¤J°Ñ¼Æ¤¤²ÕĶ¡K¡K¡Aª½¨ì¦r¦ê¤¤ªº©Ò¦³¦r¤¸³£³B²z¹L¡C¥¦±`±`¥Î¨ÓÀˬd¦r¦êùجO§_§t¦³¬Y¨Ç¦r¤¸¡C¨Ò¦p©³¤Uªºµ{¦¡¤ù¬q¡G
IRPC letter,ABCDE db '&letter' db '&letter'+20h ENDM
¨ä¹ê´N¬O
db 'ABCDE' db 'abcde'
¦³Ãö IRP¡BIRPC ÁÙ¦³§ó¦³¥Îªº¨Ò¤l¡A½Ð¬Ý¤U¤@³¹ªº³q¥Î±À¤J°ïÅ|¥¨¶°¡C
PAGE ¬O¤@Ó°²«ü¥O¡A¨ä§@¥Î±±¨î¦CªíÀɪºªø«×¥H¤Î¼e«×¡C²Õ¦X»y¨¥ªº¦CªíÀɨC¤@¦æªø«×±`±`¶W¹L 80 Ó¦r¥À¡A¦ý¦´Á¿Ã¹õªº¤å¦r¼Ò¦¡¨C¤@¦æ³Ì¦h¥u¯à¦³ 80 Ó^¤å¦r¥À¡A¦]¦¹¦h¥X¨Óªº±`±`·|¨ì¤U¤@¦æ¡A¤£©öÆ[¹î¡C¦Ó¦Cªí¾÷¥i¥H¹F 132 Ó¦r¥À¡A¤ñ¸û¤è«K¡A¦]¦¹¥Î page ¨Ó±±¨î¦CªíÀɪºªø«×¥H¤Î¼e«×¡A»yªk¦p¤U¡G
page [ªø«×][,¼e«×]
ªø«×¥²¶·¦b 10 ¨ì 255 ¤Q¶i¦ì¾ã¼Æ½d³ò¤º¡A¦pªG¨S³]©wªø«×¡A¤º©wȬO 50¡C¼e«×n¦b 80 ¨ì 132 ¤Q¶i¦ì¾ã¼Æ½d³ò¤º¡A¦pªG¨S³]¼e«×¡A¤º©wȬO 80¡C°²¦p¥u³]©w¼e«×¦Ó¤£³]©wªø«×¡A¥²¶·¦b«e±¥[¤W¡y,¡z§_«h MASM ·|»~¥H¬°¬Oªø«×¡C°²¦pªø«×»P¼e«×³£¬Ù²¤¡A«h·|±j¢¸õ¶¡C