²Ä¤»³¹¡@¥¨¶°¡]¤G¡^

³o¤@³¹Ä~Äò¤¶²Ð³Ñ¤Uªº¨âºØ¥¨¶°¡G¹w¥ý©w¸qªº¥¨¶°¨ç¦¡©M¦r¦ê°²«ü¥O¡B­«½Æ°Ï¶ô¡CµM«áÁÙ­n¤¶²Ð»P¥¨¶°·f°t«á¯à²£¥Í±j¤j¥\¯àªº±ø¥ó²ÕĶ¡C³Ì«á¸ÑªR¤j¯«¯Åªº«e½ú¡A·f°t¥¨¶°»P±ø¥ó²ÕĶ¡A©Ò»s§@¥¨¶°¡Ainvoke¡C¥¦¯à¥H¤@¦æµ{¦¡½X¡A´N¯à¹F¦¨©I¥s Win64 API ªº¥\¯à¡C


¹w¥ý©w¸qªº¥¨¶°¨ç¦¡©M¦r¦ê°²«ü¥O

¦Û MASM 6.0 ª©¶}©l¡A´£¨Ñ¤F¥|­Ó¹w¥ý©w¸qªº¥¨¶°¨ç¦¡¡G①@SizeStr¡B②@SubStr¡B③@InStr¡B④@CatStr¡A¥¦­Ì¦b¥¨¶°¤¤³B²z¦r¦ê«D±`¦n¥Î¡C³o¥|­Ó¹w¥ý©w¸qªº¥¨¶°¨ç¦¡¡A³£¦³¥\¯à¬Û¦Pªº°²«ü¥O»P¤§¹ïÀ³¡A¤À§O¬O¡G①SIZESTR¡B②SUBSTR¡B③INSTR¡B④CATSTR¡C

­nª`·Nªº¤@ÂI¬O¡A¦pªG­ì©lµ{¦¡¦³¡uOPTION CASEMAP:NONE¡v©Î¬O¥H ML64.EXE ²ÕĶ®É¦³¤U¹F¡u/Cp¡v¿ï¶µ°Ï¤À¤j¤p¼g®É¡A¨º»ò¨Ï¥Î¹w¥ýªº¸q¥¨¶°¨ç¦¡¡A¨ç¦¡¦WºÙ­n°Ï¤À¤j¤p¼g¡F¦Ó¦r¦ê°²«ü¥O¤£¨ü­­¨î¡C¦Ó¤£©¯ªº¬O¡A¥H²Õ¦X»y¨¥¼¶¼g Windows µ{¦¡¡A¥²©w·|°Ï¤À¤j¤p¼g¡A©Ò¥H¦b¤Þ¥Î³o¥|­Ó¥¨¶°¨ç¦¡®É¡A¤j¤p¼g¥²¶·¨Ì·Ó«e­±ªº¤è¦¡¡C°£¦¹¤§¥~¡AÅU¦W«ä¸q¡A³o¥|­Ó¹w¥ý©w¸qªº¥¨¶°¨ç¦¡¬°¨ç¦¡¡A¦]¦¹¥²¶·¨Ì¤Þ¥Î¥¨¶°¨ç¦¡ªº³W©w¨Ï¥Î¡A¨ä¤Þ¼Æ¥²¶·¥H¤@¹ï¡u(¡v¡B¡u)¡v¬A°_¨Ó¡C

¹w¥ý©w¸qªº¥¨¶°¨ç¦¡ @SizeStr »P¦r¦ê°²«ü¥O SIZESTR

@SizeStr »P SIZESTR ³£¬O¥Î¨Ó­pºâ¤@­Ó¦r¦ê¦³¦h¤Ö­Ó¦ì¤¸²Õ¡A¥ý»¡ @SizeStr ªº¥Îªk¡A¥¦ªº¨ä»yªk¦p¤U¡G

@SizeStr(string)

@SizeStr ¥¨¶°¨ç¦¡·|§â string ¦r¦ê¸Ì§t¦³¦h¤Ö­Ó¦ì¤¸²Õ§@¬°¦^¶Ç­È¡A¦Ó¥B¦¹¦^¶Ç­È¬O¼Æ­È¦r¦ê¡A¨Ã«D¼Æ­È¡A¨Ï¥Î®É¥²¶·ª`·N¡C

@SizeStr ªº string ¥i¥H¬O¦r¦ê±`¼Æ©Î¦r¦êÅܼơA¤]¥i¥H¬O¦r¦ê¥»¨­¡C¦pªG string ¬O¦r¦ê±`¼Æ©Î¦r¦êÅܼơA¥²¶·¦b¨ä¦WºÙ¤§«e¥[¤W®i¶}¹Bºâ¤l ( ¤]´N¬O¡u%¡v)¡A§_«h±o¨ìªº¬O¦r¦ê±`¼Æ¦WºÙ©Î¦r¦êÅܼƦWºÙªºªø«×¡C¦pªG string ¬O¦r¦ê¥»¨­¡A´N¤£¶·¦A¥[¤W®i¶}¹Bºâ¤l¡A¥i¥H¥H¤@¹ï¡u<¡v¡B¡u>¡v±N¦r¦ê¬A¦í¡A¤]¥i¥H¤£¥Î¬A¦í¡C·íµM¡A¦pªG¦r¦ê¥»¨­¦³¤@¨Ç¯S®í¦r¤¸ ( ¨Ò¦pªÅ¥Õ¡B¤Þ¸¹ (")¡B³r¸¹ (,)¡B³æ¤Þ¸¹ (')¡K¡K¡A¬Æ¦ÜÁÙ­n¥[¤W¦r¤¸¹Bºâ¤l )¡A´N¥²¶·¥H¡u<¡v¡B¡u>¡v±N¦r¦ê¬A¦í¡C¨Ò¦p¡G

beauty  TEXTEQU <³¬¤ë²Ûªá>
len1    TEXTEQU @SizeStr(%beauty)       ;;len1¡×"8"¡A¤@­Ó¤¤¤å¦r¥Nªí¨â­Ó¦ì¤¸²Õ
len2    TEXTEQU @SizeStr(beauty)        ;;len2¡×"6"
len3    TEXTEQU @SizeStr(<³¬¤ë²Ûªá>)     ;;len3¡×"8"
len4    TEXTEQU @SizeStr(³¬¤ë²Ûªá)       ;;len4¡×"8"

¤W­±²Ä¤@¦æµ{¦¡½X«Å§i¤F¦r¦ê±`¼Æ buauty µ¥©ó¡u³¬¤ë²Ûªá¡v¡Abeauty ¬°¦r¦ê±`¼ÆªºÅܼƦWºÙ¡A¡u³¬¤ë²Ûªá¡v¬°¨ä­È¡C

len1¡G¦b¦r¦êÅÜ¼Æ beauty «e¥[¤W¤F®i¶}¹Bºâ¤l¡A%¡A¥Nªí¨D±o beauty ¤§­È¡C¦]¦¹ @SizeStr(%beauty) ·|¨D±o beauty ¤§­È¡A¤]´N¬O¡u³¬¤ë²Ûªá¡v¦³¦h¤Ö¦ì¤¸²Õ¡C
len2¡G@SizeStr ·|§â¡ubeauty¡v·í°µ¦r¦ê¡A¨D±o beauty ¦³¦h¤Ö¦ì¤¸²Õ¡C
len3¡G@SizeStr ·|§â¡u³¬¤ë²Ûªá¡v·í°µ¦r¦ê¡A¨D±o¡u³¬¤ë²Ûªá¡v¦r¦ê¦³¦h¤Ö¦ì¤¸²Õ¡C
len4¡G¦P len3¡C

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

name SIZESTR string

SIZESTR ·|§â name ÅܼƤ§­È³]©w¬° string ¦r¦ê©Ò§tªº¦ì¤¸²Õ­Ó¼Æ¡A³o¸Ìªº name ¬O¼Æ­ÈÅܼơCstring ¥i¥H¬O¦r¦êÅܼơA¤]¥i¥H¬O¦r¦ê¥»¨­¡F¦pªG¬O¦r¦êÅܼơA¤£»Ý­n¥[¤W®i¶}¹Bºâ¤l¡F¦pªG¬O¦r¦ê¥»¨­¡A¥²¶·¥H¤@¹ï¡u<¡v¡B¡u>¡v±N¦r¦ê¬A¦í¡CSIZESTR ªº®ÄªG¦³¨â­Ó¡G①¨D±o¤§«á¹Bºâ¤¸¦³¦h¤Ö¦ì¤¸²Õ¡B②¸ò²Ä¤@³¹¡u=¡vªº®ÄªGÃþ¦ü¡A³£¬O±N¼Æ­È«ü©wµ¹¬Y­Ó¼Æ­ÈÅܼơC©µÄò¤W­±ªº¨Ò¤l¡G

len5    SIZESTR beauty                  ;;len5¡×8
len6    SIZESTR <³¬¤ë²Ûªá>               ;;len6¡×8

¤W­±ªºµ{¦¡½X­pºâ beauty ¦r¦ê¦³¦h¤Ö¦ì¤¸²Õ¡A³o¸Ìªº¦³¦h¤Ö¦ì¤¸²Õ¸ò«e­±¤£¦P¡A¥¦¬O¼Æ­È¡C

¹w¥ý©w¸qªº¥¨¶°¨ç¦¡ @InStr »P¦r¦ê°²«ü¥O INSTR

@InStr »P INSTR ³£¬O¦b¤@­Ó«ü©wªº¦r¦ê¤¤·j¯Á¤@­Ó¸ûµu¦r¦êªº¥X²{¦ì¸m¡A¦¹¸ûµu¦r¦ê¤@¯ëºÙ¬°¡u¤l¦r¦ê¡v¡C¥ý»¡©ú @InStr¡A¥¦ªº»yªk¬O¡G

@InStr( [start], string, short_string )

¤W­±ªº string ¬O«ü©wªº¦r¦ê¡Ashort_string «h¬O­n·j¯Áªº¸ûµu¦r¦ê¡F¦¹¤GªÌ¥i¥H¬O¦r¦ê±`¼Æ©Î¦r¦êÅܼơA¤]¥i¥H¬O¦r¦ê¥»¨­¡C¦pªG¬O¦r¦ê±`¼Æ©Î¦r¦êÅܼƪº¸Ü¡A«e­±­n¥[¤W¡u%¡v¡A§_«h @InStr ·|§â¦r¦êÅܼƪº¦WºÙ·í°µ¦r¦ê¡F¦pªG¬O¦r¦ê¥»¨­¡A¥i¥H¤@¹ï¡u<¡v¡B¡u>¡v±N¦r¦ê¬A¦í¡A¤]¥i¥H¤£¥Î¡A¦ý¦pªG¦r¦ê¥»¨­¦³¯S®í¦r¤¸¡A´N¥²¶·¥H¡u<¡v¡B¡u>¡v±N¦r¦ê¬A¦í¡C

start ªí¥Ü­n¦b string ¦r¦ê¤¤ªº²Ä´X­Ó¦ì¤¸²Õ¶}©l·j¯Á¡A¦¹³B¦r¦ê¶}©l¦ì¸m¬O¤@¡A¨Ã«D²Õ¦X»y¨¥ºD¥Îªº¹s¶}©l¡C¦pªG¬Ù²¤ start¡A«h°²©w¥Ñ¦ì¸m¤@³B¶}©l·j´M¡A¤]´N¬O±qÀY¶}©l·j´M¡A¦¹®É¦b string ¤§«eªº¡u,¡v¤£¥i¬Ù²¤¡C¦pªG @InStr §ä¤£¨ì¸ûµuªº¦r¦ê¡A¨º»ò¦^¶Ç­È¬° 0¡A§_«h´N¬O¦b²Ä´X­Ó¦ì¤¸²Õ§ä¨ì¤F¸ûµu¦r¦ê¡C@InStr ªº¦^¶Ç­È¬O¼Æ­È¦r¦ê¡C

¨Ò¦p©³¤Uªº¨Ò¤l¬O¦b¡uÂ_¾ô¬Û¬ù¡AIJ¤â¤w¤Æ½º¡C¬Ýº¡¤s¬õ¸­¡A¥i¬OÂ÷¤H²´¤¤¦å¡v¦r¦ê¤¤´M§ä¡u¬Û¬ù¡v¡Cµ{¦¡½X¦p¤U¡G

formless TEXTEQU <Â_¾ô¬Û¬ù¡AIJ¤â¤w¤Æ½º¡C¬Ýº¡¤s¬õ¸­¡A¥i¬OÂ÷¤H²´¤¤¦å>
date1    TEXTEQU @InStr(1,%formless,¬Û¬ù)
date2    TEXTEQU @InStr(,Â_¾ô¬Û¬ù¡AIJ¤â¤w¤Æ½º¡C¬Ýº¡¤s¬õ¸­¡A¥i¬OÂ÷¤H²´¤¤¦å,¬Û¬ù)

¤W­±ªº date1 »P date2 ¬O¤@¼Ëªº¡A³Ì²×¨âªÌ¤§­È§¡¬° "05"¡A¥B§¡¬°¦r¦ê¡C( ª`·N¡I¤@­Ó¤¤¤å¦r¦û¦³¨â­Ó¦ì¤¸²Õ )

¦r¦ê°²«ü¥O INSTR ªº»yªk¬O¡G

name INSTR [start,] string, short_string

INSTR ªº string¡Bshort_string ·N¸q»P @InStr ¬Û¦P¡A³£¥i¥H¬O¦r¦êÅܼƩΦr¦ê¥»¨­¡C¦pªG¬O¦r¦êÅܼơA«e­±¤£¯à¥[¡u%¡v¡A¥[¤F·|²£¥Í¿ù»~¡F¦pªG¬O¦r¦ê¥»¨­¡A¥²©w­n¥H¤@¹ï¡u<¡v¡B¡u>¡v±N¦r¦ê¬A¦í¡A§_«h¤]·|²£¥Í¿ù»~¡C¦pªG¬Ù²¤ start ªº®É­Ô¡A¥Ñ¦r¦ê¶}©l³B·j´M¡A¦P®É start ¤§«áªº¡u,¡v¥²¶·¤@¦P¬Ù²¤¡C³Ì«á©Ò±oªºµ²ªG¡Aname¡A¬O¼Æ­ÈÅܼơA¨Ã«D¼Æ­È¦r¦ê¡C¨Ò¦p©³¤U¨â¦æ¡G

date3   INSTR   formless,<¬Û¬ù>
date4   INSTR   <Â_¾ô¬Û¬ù¡AIJ¤â¤w¤Æ½º¡C¬Ýº¡¤s¬õ¸­¡A¥i¬OÂ÷¤H²´¤¤¦å>,<¬Û¬ù>

date3 »P date4 ³£¬O 5¡A¨âªÌ³£¬O¼Æ­È¡C

¹w¥ý©w¸qªº¥¨¶°¨ç¦¡ @SubStr »P¦r¦ê°²«ü¥O SUBSTR

@SubStr »P SUBSTR ³£¯à±q¤@­Ó¦r¦ê¤¤¡A´£¨ú¨ä¤¤ªº¤@³¡¤À¡A§Î¦¨·sªº¦r¦ê¡C¥ý»¡ @SubStr¡A¥¦ªº»yªk¬O¡G

@SubStr( string, start [, length] )

@SubStr ªº²Ä¤@­Ó°Ñ¼Æ¬O string¡A¥i¥H¬O¦r¦êÅܼƩΦr¦ê±`¼Æ¡A¤]¥i¥H¬O¦r¦ê¥»¨­¡C¦pªG¬O¦r¦ê±`¼Æ©Î¦r¦êÅܼƪº¸Ü¡A«e­±­n¥[¤W¡u%¡v¡A§_«h @SubStr ·|§â¦r¦êÅܼƪº¦WºÙ·í°µ¦r¦ê¡F¦pªG¬O¦r¦ê¥»¨­¡A¥i¥H¤@¹ï¡u<¡v¡B¡u>¡v±N¦r¦ê¬A¦í¡A¤]¥i¥H¤£¥Î¡A¦ý¦pªG¦r¦ê¥»¨­¦³¯S®í¦r¤¸¡A´N¥²¶·¥H¡u<¡v¡B¡u>¡v±N¦r¦ê¬A¦í¡C

@SubStr ·|¦b string ¦r¦ê¤¤¡A¥Ñ start ¶}©l ( string ¤¤ªº°_ÀY¦r¤¸¡A¦ì¸m¬°¤@¡A»P²Õ¦X»y¨¥ºD¥Îªº¶}©l¦ì¸m¬°¹s¤£¦P )¡Aªø length ­Ó¦ì¤¸²Õ¡A§Î¦¨ªº·s¦r¦ê¡Clength ¥i¥H¬Ù²¤¡A¦pªG¬Ù²¤ªº¸Ü¡A·sªº¦r¦ê¥Ñ start ¶}©l¦Ü string µ²§À¡C

¦r¦ê°²«ü¥O SUBSTR ªº»yªk¬O¡G

name SUBSTR string, start[[, length]]

SUBSTR ªº string¡Bstart¡Blength ³£¸ò @SubStr ¤@¼Ë¡C©³¤Uªº¨Ò¤l¡G

spider_man TEXTEQU <With great power, comes great responsibility>
greatp1    TEXTEQU @SubStr(<With great power, comes great responsibility>,6,11)
greatp2    TEXTEQU @SubStr(%spider_man,6,11)
greatr1    SUBSTR  <With great power, comes great responsibility>,25
greatr2    SUBSTR  spider_man,25

¤W­±ªº¨Ò¤l¤¤¡Agreatp1¡Bgreatp2 ³£¬O "great power"¡Fgreatr1¡Bgreatr2 ³£¬O "great responsibility"¡C«Ü©úÅã¡A@SubStr »P SUBSTR ªºµ²ªG¡A³£¬O¦r¦ê¡C

¹w¥ý©w¸qªº¥¨¶°¨ç¦¡ @CatStr »P¦r¦ê°²«ü¥O CATSTR

@CatStr »P CATSTR ³£¯à§â¼Æ­Ó¦r¦ê³s±µ°_¨Ó¡A§Î¦¨¤@­Ó·sªºªø¦r¦ê¡C¥¦­Ìªº»yªk¬O¡G

@CatStr( string1[, string2[, string3...]] )
name CATSTR string1[, string2[, string3...]]

¥¦­Ì³£¯à§â string1¡Bstring2¡Bstring3¡K¡K³s±µ°_¨Ó¡A¦Ó³y¥X·sªº¦r¦ê¡A@CatStr ±N¦¹·sªº¦r¦ê§@¬°¦^¶Ç­È¡FCATSTR §â name ÅܼƤ§­È³]¬°¦¹·sªº¦r¦ê¡C¬Ý©³¤Uªº¨Ò¤l¡G

peom1   MACRO   string
        .DATA
        DB      @CatStr(<!">,%string,<¤p¾ô¬y¤ô¤H®a¡C!">)
ENDM

peom2   MACRO   string
        .DATA
        temp    CATSTR  <!"¥j¹D¦è­·½G°¨¡A>,<&string&>,<Â_¸z¤H¦b¤Ñ²P¡C!">
        DB      temp
ENDM

¦b¸ê®Æ°Ï¬q¤¤¥H¤U­±¤è¦¡¤Þ¥Î peom1¡Bpeom2 ¥¨¶°¡G

peom1   <¬\ÃæѾð©ü¾~¡A>
peom2   <¤i¶§¦è¤U¡A>

´N·|¦b¸ê®Æ°Ï¬q¤¤²£¥Í¤@­Ó¦r¦ê¡G

DB      "¬\ÃæѾð©ü¾~¡A¤p¾ô¬y¤ô¤H®a¡C¥j¹D¦è­·½G°¨¡A¤i¶§¦è¤U¡AÂ_¸z¤H¦b¤Ñ²P¡C"

­È±o¤@´£ªº¬O¡A¦b¤W­±¥H¤@¹ï¡u<¡v¡B¡u>¡v¬A¦íªº¦r¦ê¤¤¡A¦pªG¦³¤Þ¸¹¡A¤]´N¬O¡u"¡v¡A»Ý¦b«e­±¥[¤W¡u!¡v¡A¤£µMªº¸Üªº¡u"¡v·|Åý²ÕĶ¾¹¥H¬°¦r¦êµ²§ô¡C¦P¼Ëªº¡A¡u'¡v¤]¬O¦p¦¹¡C

¾ã²z¹w¥ý©w¸qªº¥¨¶°¨ç¦¡»P¦r¦ê°²«ü¥O

¦b¥¨¶°¤¤¨Ï¥Î³o¥|­Ó¹w¥ý©w¸qªº¥¨¶°¨ç¦¡»P¦r¦ê°²«ü¥O«Ü³Â·Ð¡A¤×¨ä¬O¨Ï¥ÎÅܼơB°Ñ¼Æªº¤è¦¡¤£¦P¡A¨äµ²ªGªº¸ê®ÆÃþ«¬¤]¤£¦P¡C¤p¤ì°¸¤]¤£ª¾¹D¬°¦ó­n³o»ò³Â·Ð¡A¦]¦¹¾ã²z¦¨¤Uªí¡G

ÅܼưѼƦr¦êµ²ªG
¥¨¶°¨ç¦¡¡G
@SizeStr
@InStr
@SubStr
@CatStr
¥²¶·¦bÅܼƦWºÙ«e¥[¡u%¡v ¥i¥Hª½±µ¨Ï¥Î¡A©Î¦b°Ñ¼Æ¦WºÙ«e¥[¡u%¡v ¥i¥Hª½±µ¨Ï¥Î¡A¦ý¦r¦ê§t¦³¯S®í¦r¤¸´N¥²¶·¥H¡u<¡v¡B¡u>¡v±N¦r¦ê¬A¦í§¡¬°¦r¦ê
¦r¦ê°²«ü¥O¡G
SIZESTR
INSTR
SUBSTR
CATSTR
ª½±µ¨Ï¥Î¥²¶·¥H¡u<¡v¡B¡u>¡v±N°Ñ¼Æ¦WºÙ¬A¦í¡F©ÎªÌ¥H¡u<¡v¡B¡u>¡v±N°Ñ¼Æ¦WºÙ¬A¦í¥~¡AÁÙ­n¦b°Ñ¼Æ¦WºÙ«e«á¥[¤W¡u&¡v¥²¶·¥H¡u<¡v¡B¡u>¡v±N¦r¦ê¬A¦í SIZESTR¡BINSTR¬°¼Æ­È
SUBSTR¡BCATSTR¬°¦r¦ê

­«½Æ°Ï¶ô

ML64.EXE ¥i¨Ï¥Îªº­«½Æ°Ï¶ô¦³¡G①WHILE/ENDM¡B②REPEAT/ENDM¡B③FOR/ENDM¡B④FORC/ENDM¡A¦@¥|ºØ¡C

WHILE/ENDM °²«ü¥O

WHILE/ENDM ªº»yªk¬O¡G

WHILE §PÂ_¦¡
  ±Ô­z
ENDM

WHILE/ENDM ·|¥ýÀˬd§PÂ_¦¡¬O§_¬°¯u¡A°²¦p¬°°²´N¸õ¨ì ENDM ¤§«á¡F°²¦p¬°¯u´N²ÕĶ WHILE »P ENDM ¤§¶¡ªº±Ô­z¡A¦Ü±Ô­zªº³Ì«á¤@¦æ¡AµM«á¦^¨ì WHILE ³B¡A¦A«×Àˬd§PÂ_¦¡¬O§_¬°¯u¡A¨Ì¨ä¯u°²§PÂ_¬O§_­«½Æ¡F¦p¦¹¤@ª½¨ì§PÂ_¦¡¬°°²®É¡A¤~¸õ¥X WHILE/ENDM °j°é¡C¤W­±ªº±Ô­z¥i¥H¬O x86 «ü¥O©Î¬O²Å¦X²Õ¦X»y¨¥»yªkªº°²«ü¥O¡C

§PÂ_¦¡¦³¤TºØ§Î¦¡¡G

①¡G¥i¥H¬O¼Æ­ÈÃö«Y¦¡¡A¨ä§Î¦¡¬°¡G

number1 ¤ñ¸û¹Bºâ¤l number2

number1 »P number2 ¥i¥H¬Oºâ³N¹Bºâ¦¡©Î¬O²ÕĶ®É´ÁªºÅܼơB±`¼Æ¡C±`¥Îªº¤ñ¸û¹Bºâ¤l¦³¤U¦C¤»ºØ¡G

LT¡@¤p©ó¡@¡@¡@¡@¡@¡@¡@¡@NE¡@¤£µ¥©ó¡@¡@¡@¡@¡@¡@¡@LE¡@¤p©ó©Îµ¥©ó
GT¡@¤j©ó¡@¡@¡@¡@¡@¡@¡@¡@EQ¡@µ¥©ó¡@¡@¡@¡@¡@¡@¡@¡@GE¡@¤j©ó©Îµ¥©ó

②¡G¥i¥H¬O¼Æ­ÈÃö«Y¦¡¤§¶¡¡A¦A°µ½ÆÂøªºÅÞ¿è¹Bºâ¡A¥i¥ÎªºÅÞ¿è¹Bºâ¤l¦³ AND¡BOR ¤Î XOR¡C( ¦¹¤T­ÓÅÞ¿è¹Bºâ¤l¨Ã«D x86 «ü¥O¡A¶È¥Î©ó§PÂ_¦¡¸Ì­± )¡C

③¡G¥i¥H¬O¤@­Ó²ÕĶ®É´ÁªºÅܼƩμƾǹBºâ¦¡¡C¨Æ¹ê¤W¡A·í²ÕĶ¾¹¹ï§PÂ_¦¡¶i¦æ§PÂ_®É¡A¦pªG³Ì«áµ²ªG¬°¯u¡A¬O¥H«D¹s­È¥Nªí ( ³q±`¬O¤@ )¡F¦pªG³Ì«áµ²ªG¬°°²¡A¥H¹s¥Nªí¡C

¨Ò¦p©³¤Uªº Fibonacci ¥¨¶°¡A´N¯à¦b¸ê®Æ°Ï¬q¤º©w¸q¤@­Ó¤£¶W¹L«ü©w¼Æ­Èªº¶O¦¡¼Æ¦C ( Fibonacci Sequence )¡A­Y¦¹¼Æ­È¶W¹L¤@¸U¡A¥H¤@¸U¬°­­¡C©Ò¿×ªº¶O¤ó¼Æ¦Cªº«e¨â¶µ¬O 0¡B1¡A±q²Ä¤T¶µ¶}©l¡A¨C¤@¶µ³£¬O«e¨â¶µ¤§©M¡C¶O¤ó¼Æ¦Cªº«e¤Q¶µ¬O 0¡B1¡B1¡B2¡B3¡B5¡B8¡B13¡B21¡B34¡A¥i¥H¤@ª½µL½a©µ¦ù¡A¬OµL½a¼Æ¦C¡C

©³¤U¬O Fibonacci ¥¨¶°ªº¤º®e¡G

Fibonacci  MACRO number
           x=0
           y=1
           z=x+y
f_sequence DW      x,y
  WHILE (z LE number) AND (z LT 10000)  ;;·íz¤p©ó©Îµ¥©ónumber¥Bz¤p©ó¤@¸U¡A¤~²ÕĶWHILE¦ÜENDM¤§¶¡ªºµ{¦¡½X
           DW      z
           x=y
           y=z
           z=x+y
  ENDM
ENDM

¦pªG¥H¤U­±¤è¦¡¤Þ¥Î

.DATA
Fibonacci 100

´N·|¦b¸ê®Æ°Ï¬q¤º²£¥Í¡uf_sequence DW 0,1,1,2,3,5,8,13,21,34,55,89¡vµ{¦¡½X¡C¦pªG¥H¡uFibonacci 15000¡v¤Þ¥Î¡A¨º»ò³o¸Ìªº¶O¤ó¼Æ¦C³Ì¦h¤]¥u¯à¨ì 6765¡C

¤W­±ªº Fibonacci ªº§PÂ_¦¡¤£¼g¦¨¡uz LE number¡v¡A¦Ó¼g¦¨¤W­±¨º¼Ëªº­ì¦]¡A¨ä¥D­n¥Øªº´N¬O­­¨î³Ì¦h¤£¥i¶W¹L 10000¡C·íµM§A¥i¥H§â³o­Ó¼Æ§ï¤j¤@ÂI¡A¥u»Ý±N 10000 §ï¦¨¤j¤@ÂIªº¼Æ§Y¥i¡C

µyµy¦a¸ÑÄÀ WHILE »P ENDM ¤§¶¡ªºµ{¦¡¡C¦]¬°¶O¤ó¼Æ¦C±q²Ä¤T¶µ¶}©l¡A¨C¤@¶µ³£¬O«e¨â¶µ¤§©M¡A©Ò¥H±q²Ä¤T¶µ¤§«áªº¨C¤@¶µ´N¸ò«e¨â¶µ¦³Ãö¡C·í­pºâ§¹¬Y¤@¶µ ( ²Ä n ¶µ ) ¤§«á¡A­n­pºâ¤U¤@¶µ ( ²Ä n+1 ¶µ )¡A´N¥u¸ò¦¹¶µ ( ²Ä n ¶µ ) »P«e¤@¶µ ( ²Ä n-1 ¶µ ) ¦³Ãö¡C¤]´N¬O»¡¡A¦b­pºâ²Ä n+1 ¶µ®É¡A²Ä n-2 ¶µ´N¯à©ß±ó¡C

³oºØ±¡§Î¡A´N«Ü¹³½ñµÛ¤@±ÆÅS¥X¤ô­±ªº¥ÛÀY¹Lªe¤@¼Ë¡A§Aªº¨â°¦¸}½ñµÛ¨â¶ô¥ÛÀY¡A¨C«e¶i¤@¨B´N±Ë±ó«á­±ªº¥ÛÀY¡A©Ò»Ýªº¥ÛÀY©¹«e²¾¤@®æ¡C¦b WHILE »P ENDM ¤§¶¡ªºµ{¦¡¤]¬O¦p¦¹¡A¨C­pºâ§¹¤@¶µ¡A«e¤@¶µ´NÅܳo¤@¶µ¡Aµ{¦¡¤¤ªº x=y¡By=z ´N¬O¥Î¨Ó©¹«e²¾¤@®æªº¡A·sªº¤@¶µ´N¬O¥Ñ z=x+y ²£¥Íªº¡C

REPEAT/ENDM °²«ü¥O

REPEAT/ENDM ªº»yªk¬O¡G

REPEAT ºâ³N¹Bºâ¦¡
  ±Ô­z
ENDM

ºâ³N¹Bºâ¦¡¥i¥H¬O±`¼Æ©Î±`¼Æ¤§¶¡¹Bºâ«áªºµ²ªG¡A¥¦¥Nªí­«½Æ¦¸¼Æ¡F¤]´N¬O»¡ REPEAT »P ENDM ¤§¶¡ªº±Ô­z·|­«½Æ«Ü¦h¦¸¡A­«½Æ¦¸¼Æ¥Ñºâ³N¹Bºâ¦¡¨M©w¡C½Ð¬Ý©³¤Uªº¨Ò¤l¡G

number  LABEL   DWORD
        x=1
REPEAT  5
        DD      x DUP (x)
        x=x+1
ENDM

¤W­±ªºµ{¦¡·|²£¥Í©³¤Uªºµ{¦¡½X ( ¦³Ãö LABEL °²«ü¥Oªº»¡©ú½Ð°Ñ¾\µù¤@ )¡G

number  DD  1,2,2,3,3,3,4,4,4,4,5,5,5,5,5

FOR/ENDM °²«ü¥O

FOR/ENDM ªº»yªk¬O¡G

FOR °Ñ¼Æ,<¤Þ¼Æ¤@,¤Þ¼Æ¤G,¤Þ¼Æ¤T,¡K¡K>
        ±Ô­z
ENDM

²ÕĶ¾¹·|±N¤Þ¼Æ¤@¥N¤J°Ñ¼Æ¡A²ÕĶ FOR »P ENDM ¤§¶¡ªº±Ô­z¡FµM«á¦A¥H¤Þ¼Æ¤G¥N¤J°Ñ¼Æ¡A²ÕĶ FOR »P ENDM ¤§¶¡ªº±Ô­z¡K¡K¦p¦¹¤@ª½­«½Æ¡Aª½¨ì¡u<¡v¡B¡u>¡v¤ºªº¤Þ¼Æ¥þ³£¥N¤J¹L¬°¤î¡C

©³¤Uªºµ{¦¡½X¡A¥i¥H³sÄò¨ú±o¼Ð·Ç¿é¤J¸Ë¸m¥N½X¡B¼Ð·Ç¿é¥X¸Ë¸m¥N½X¡B¼Ð·Ç¿ù»~¸Ë¸m¥N½X¡A¨Ã¤À§O¦s¤J hInput¡BhOutput¡BhError ¤T­ÓÅÜ¼Æ¸Ì ( ³o¤T­ÓÅܼƥ²¶·³sÄò¡A¥B¶¶§Ç¤£¯à¿ù¶Ã )¡G

hInput  DQ      ?
hOutput DQ      ?
hError  DQ      ?
        ⁝
        lea     r8,hInput
FOR     nStd,<STD_INPUT_HANDLE,STD_OUTPUT_HANDLE,STD_ERROR_HANDLE>
        mov     rcx,nStd
        call    GetStdHandle
        mov     [r8],rax
        add     r8,SIZEOF QWORD
ENDM

­º¥ý§â hInput ªº¦ì§}¦s¤J R8 ¼È¦s¾¹¡AµM«á¶i¤J FOR/ENDM ­«½Æ°Ï¶ô¡C²Ä¤@¦¸ nStd ¬O¥H STD_INPUT_HANDLE ¥N¤J¡A±o¨ì¼Ð·Ç¿é¤J¸Ë¸m¥N½X¡A¦s¤J R8 ©Ò«üªº¦ì§}¡A¦¹¦ì§}¤]¬O hInput ÅܼƩҦb¦ì§}¡CµM«á R8 ¥[¤W QWORD ªº¤j¤p¡A¥ç§Y«ü¦V¤U¤@­ÓÅÜ¼Æ hOutput ªº¦ì§}¡AµM«á¥N¤J¤U­Ó¤Þ¼Æ¶i¦æ²Ä¤G¦¸´`Àô¡C²Ä¤G¦¸ nStd ¥H STD_OUTPUT_HANDLE¡A¦p¦¹­«½Æ¡K¡Kª½¨ì²Ä¤T­Ó¤Þ¼Æ³B²z§¹¡A¤~Â÷¶} FOR/ENDM¡C

¤W­±³o¬qµ{¦¡¦³­Ó¯ÊÂI¡A¤@¯ë¦Ó¨¥¡A©I¥s Win64 API ¤§«á¡AR8 ¼È¦s¾¹¥i¯à·|³Q­×§ï¡A³o¼Ëªº¸Ü¤W­±ªº¥¨¶°´N¤£¯à¥Î¤F¡C¤£¹L¤p¤ì°¸¸Õ¹L¦b Windows 10 ¬O¨S°ÝÃDªº¡A¦ý¨ä¥L´N¤£´±«OÃÒ¤F¡C

¤W­±ªº FOR/ENDM °j°é¤]¥i¥H¥Î¤£½T©w°Ñ¼Æ¼Æ¶qªº¤è¦¡§ï¼g¡A¦p¤U¡G

hInput  DQ      ?
hOutput DQ      ?
hError  DQ      ?
        ⁝
GetHdl  MACRO   arg:VARARG
        lea     r8,hInput
  FOR nStd,<arg>
        mov     rcx,nStd
        call    GetStdHandle
        mov     [r8],rax
        add     r8,SIZEOF QWORD
  ENDM
ENDM

¤Þ¥Î GetHdl ªº¤èªk¦p¤U¡G

GetHdl  STD_INPUT_HANDLE,STD_OUTPUT_HANDLE,STD_ERROR_HANDLE

FORC/ENDM °²«ü¥O

FORC/ENDM ªº¥Îªk©M FOR/ENDM Ãþ¦ü¡A¦ý¬O¨ä¤Þ¼Æ¬°¦r¦ê¦Ó¤£¬O¤Þ¼Æ¦Cªí¡CFORC/ENDM ªº»yªk¬O¡G

FORC °Ñ¼Æ,<¦r¦ê>
        ±Ô­z
ENDM

FORC ±q¡u<¡v¡B¡u>¡v¤ºªº¦r¦ê¤¤¡A¨C¦¸¨ú¥X¤@­Ó¦r¤¸¡A¥Ñ²Ä¤@­Ó¦r¤¸¶}©l¥N¤J¡A²ÕĶ FORC ¨ì ENDM ¤§¶¡ªº±Ô­z¡FµM«á¦A¸õ¦^¨ì FORC ³B¨ú¥X¦r¦êªº²Ä¤G­Ó¦r¤¸²ÕĶ¡K¡K¤@ª½­«½Æ¡Aª½¨ì¦r¦êªº³Ì«á¤@¦r¤¸³B²z§¹²¦¤~ºâ§¹¦¨¡C°²¦p FORC/ENDM ¬O¦b¥t¤@­Ó¥¨¶°¤º¡A¦Ó FORC «á­±±µµÛªº¦r¦ê¬O¸Ó¥¨¶°ªºÅܼơA¨º»ò´N­n¦b FORC «e­±¥[¤W¡u%¡v¡Aªí¥Ü¥¦¬O¨ú¥X¦r¦ê¤§­È¡C¦pªG¤£¥[¤W %¡Aµ²ªG·|¬OÅܼƦWºÙ¡A¨Ã«D¦r¦ê¤º®e¡A¨Ò¤l¨£¤U­±¥ªÃä¡C°²¦p FORC/ENDM ¦b¥t¤@­Ó¥¨¶°¤º¡A¦Ó FORC «á­±±µµÛªº¦r¦ê«ê¦n¬O¸Ó¥¨¶°ªº°Ñ¼Æ¡A¨º´N¤£¶·¦b FORC ¤§«e¥[¤W %¡A¨Ò¤l¨£¤U­±¥kÃä¡C

Tibetan1 MACRO   lyrics1,lyrics2
  i=0
  lyrics CATSTR <lyrics1>,<lyrics2>
 %FORC  char,<lyrics>
    j=i AND 1     ;¨Ïj¦b0¡B1¤§¶¡¤Á´«¡A³o¬O¦]¬°¤¤¤å¦r¥Ñ¨â­Ó
    IF j EQ 0     ;¦ì¤¸²Õ²Õ¦¨¡A²Ä¤@¦¸¥uÀx¦s¡A²Ä¤G¦¸¦X¨Ö¦L¥X
      temp TEXTEQU <char>
    ELSE
      temp1 CATSTR temp,<char>
      %ECHO temp1 ;·íjµ¥©ó1®É¡A¤~¦L¥Xtemp1
    ENDIF
    i=i+1
  ENDM
ENDM
  ⁝
Tibetan1 <¬O½Ö±a¨Ó»·¥jªº©I³ê¡H>,<¬O½Ö¯d¤U¤d¦~ªº¬è¬ß¡H>
Tibetan2 MACRO   lyrics
  i=0
  FORC  char,<lyrics>
    j=i AND 1
    IF j EQ 0
      temp TEXTEQU <char>
    ELSE
      temp1 CATSTR temp,<char>
      %ECHO temp1
    ENDIF
    i=i+1
  ENDM
ENDM
  ⁝
Tibetan2 <Ãø¹D»¡ÁÙ¦³µL¨¥ªººq¡H>

°õ¦æ§¹ Tibetan1¡BTibetan2 ¤§«á¡A·|¦b¿Ã¹õ¤W««ª½¦C¥X«CÂðª­ìªººqµü¡C

±µ¤U¨Ó¦AÁ|­Ó FORC/ENDM ªº¨Ò¤l»¡©ú¡A¦ý³o­Ó¨Ò¤l»P¸U°ê½X¦³Ãö¡A©Ò¥H¥ý²Ê²Lªº»¡»¡¸U°ê½Xªº½s½X¤è¦¡¡C¸U°ê½X ( Unicode ) ¬O¤@ºØ¦r¤¸½s½X¡A¥¦ªº¥ø¹Ï¤ß«Ü¤j¡A¥´ºâ§â¥þ²y©Ò¦³¤å¦r³£½s¦¨¼Æ­È¡AÂÇ¥H¥æ´«¡BÅã¥Ü¡B³B²z¥þ²y¤å¦r¡C¨Ï¥Î¸U°ê½X¤w¬O¥@¬ÉªºÁͶաA±N¨ÓªºÀɮ׳£·|±Ä¨ú³oºØ½s½X¤è¦¡¡C

¸U°ê½X¤]¦³³\¦hºØ½s½X¤è¦¡¡A¨ä¤¤ªº UTF¡Ð16 »P UTF¡Ð8 ¬O³Ì±`¨£ªº½s½X¤è¦¡¡C¹ï­^¤å¦r¥À¡Bªü©Ô§B¼Æ¦rµ¥¦r¤¸¦Ó¨¥¡AUTF¡Ð16 ¥u¬O§â ASCII ½s½X¤è¦¡¡A¥Ñ¤@­Ó¦ì¤¸²ÕÅܦ¨¤@­Ó¦r²Õ¡A°ª¦ì¤¸²Õ§¡¬°¹s¥B§C¦ì¤¸²Õ´N¬O ASCII ½X¡C¨Ò¦p­^¤å¦r¥Àªº¡uA¡v¡A¨ä ASCII ½X¬° 41H¡A¶È¤@­Ó¦ì¤¸²Õ¡F¦Ó¨ä UFT¡Ð16 ½X«h¬° 0041H¡C©³¤Uªº WSTR ¥¨¶°¡A§Q¥Î FORC/ENDM ±N¶È§t­^¤å¦r¥À¡Bªü©Ô§B¼Æ¦rµ¥¦r¤¸ªº ASCII ¦r¦êÂà´«¬° UTF¡Ð16 ½s½X¤è¦¡¡C

WSTR    MACRO   str_name,ascii_str
;WSTR¥¨¶°¯à§â­^¤å¦r¥À©Îªü©Ô§B¼Æ¦r²Õ¦¨ªºascii_str¦r¦êÅܦ¨¸U°ê½X¦r¦ê¡C¨Ò¦p
;WSTR   szText,"Love"
;·|Åܦ¨
;szText DB "L",0,"o",0,"v",0,"e",0,0,0
;str_name¡Ð¦r¦ê¦WºÙ
;ascii_str¡Ð¦r¦ê¤º®e
  str_len=@SizeStr(ascii_str)
  str_name LABEL  WORD
  temp SUBSTR <ascii_str>,2,str_len-2   ;¥h°£ÀY§Àªº¡u"¡v
  %FORC char,<temp>
     DB "&char&",0
   ENDM
   DW 0
ENDM

¤W­±ªº ascii_str ¬O¶È§t­^¤å¦r¥À¡Bªü©Ô§B¼Æ¦rµ¥¦r¤¸ªº ASCII ¦r¦ê¡CWSTR ¥¨¶°·|¦b²ÕĶ®É´Á¡A±N ascii_string ¦r¦êÂà´«¦¨ UTF¡Ð16 ¦r¦ê¡A¦s©ó str_name ¦r¦êÅܼÆùØ¡A¨Ã¥B·|¦Û°Ê¦b³Ì«á­±²K¥[¤@­Ó¦r²Õªº 0¡Aªí¥Üµ²§À¡C¨Ò¦p¦b¸ê®Æ°Ï¬q¤º¡A¥H¤U­±¤è¦¡¤Þ¥Î WSTR ¥¨¶°¡G

WSTR    szLove,"I love you"

´N·|¦b¸ê®Æ°Ï¬q²£¥Í©³¤Uªºµ{¦¡½X¡G

szLove  DB      "I",0," ",0,"l",0,"o",0,"v",0,"e",0," ",0,"y",0,"o",0,"u",0,0,0

¦Ü¦¹¡A¤p¤ì°¸¤w±N¥¨¶°¤¶²Ð§¹²¦¡A©³¤U¤¶²Ð±ø¥ó²ÕĶ¡C


±ø¥ó²ÕĶ

±ø¥ó²ÕĶ¬O«ü¦b¬Y¨Ç±ø¥ó¤U¡AÅý²ÕĶ¾¹²ÕĶ¬Y¬qµ{¦¡¡A©ÎªÌ¤£²ÕĶ¬Y¬qµ{¦¡¡C²ÕĶ¬Y¬qµ{¦¡¡A´N·N¨ýµÛ·|²£¥Í¾÷±ñ½X¡B¨Ì°²«ü¥O«ü¥Ü²ÕĶ¡A¨Ã²£¥Í²ÕĶ®É´ÁªºÅܼƨ̦¹ÅܼƵ²ªG²ÕĶ¡AµM«á±N¤W­z©Ò¦³µ²ªG¼g¤J¥ØªºÀɤΥi°õ¦æÀɸ̭± ( ·íµM²ÕĶ®É´ÁªºÅܼơA¨Ã¤£·|¼g¤J¥ØªºÀɤΥi°õ¦æÀɤº )¡F¤Ï¤§¡A¤£²ÕĶ¬Y¬qµ{¦¡¡A´N·N¨ýµÛ¤£²£¥Í¾÷±ñ½X¡B¤]¨S¨Ì°²«ü¥O«ü¥Ü²ÕĶ¡A¤]¤£²£¥Í²ÕĶ®É´ÁªºÅܼơA·íµM¤]¤£·|¼g¤J¥ØªºÀɤΥi°õ¦æÀɸ̭±¡C±ø¥ó²ÕĶªº°²«ü¥O¦³¦n´XºØ¡A¥ý¤¶²Ð³Ì±`¨£ªº IF/ELSE/ENDIF¡C

°²«ü¥O¡GIF/ELSE/ENDIF »P IFE/ELSE/ENDIF

IF/ELSE/ENDIF ¤j·§¬O³Ì±`¨£ªº±ø¥ó²ÕĶ¤F¡A¥¦ªº»yªk¦³¨âºØ¡A¤À§O¤¶²Ð¦p¤U¡G

IF §PÂ_¦¡
    µ{¦¡¤ù¬q
ENDIF

¤W­±ªºµ{¦¡½X¬O»¡¡A¦pªG§PÂ_¦¡¬°¯u¡A¨º»ò´N²ÕĶµ{¦¡¤ù¬q¤¤ªºµ{¦¡¡A§_«h´N¤£²ÕĶ¡C¨Ì¾Ú»Ý­n¡AIF ¤]¥i¥H·f°t ELSEIF¡BELSE¡A»yªk¬°¡G

IF §PÂ_¦¡¤@
    µ{¦¡¤ù¬q¤@
ELSEIF §PÂ_¦¡¤G
    µ{¦¡¤ù¬q¤G
ELSEIF §PÂ_¦¡¤T
    µ{¦¡¤ù¬q¤T
  ⁝
ELSE
    µ{¦¡¤ù¬q
ENDIF

¤W­±ªºµ{¦¡½X¬O»¡¡A¦pªG§PÂ_¦¡¤@¬°¯u¡A¨º»ò´N²ÕĶµ{¦¡¤ù¬q¤@¤¤ªºµ{¦¡¡F¦pªG§PÂ_¦¡¤G¬°¯u¡A¨º»ò´N²ÕĶµ{¦¡¤ù¬q¤G¤¤ªºµ{¦¡¡F¦pªG§PÂ_¦¡¤T¬°¯u¡A¨º»ò´N²ÕĶµ{¦¡¤ù¬q¤T¤¤ªºµ{¦¡¡K¡K¡F¦pªG³£¨S²Å¦X¥H¤W§PÂ_¦¡ªº±ø¥ó¡A´N²ÕĶµ{¦¡¤ù¬q¤¤ªºµ{¦¡¡C¦pªG¤£»Ý­n§PÂ_³o»ò¦h±ø¥ó¡AELSEIF ¥i¥Hµø±¡ªp«O¯d¡A¤]¥i¥H§â¨ì ELSE ¤§«eªº±Ô­z¡A³£¬Ù²¤¡C§PÂ_¦¡ªº¼gªk»P«e­z´£¤Îªº WHILE/ENDM ¤@¼Ë¡A½Ð¦Û¦æ°Ñ¦Ò¡C

©³¤UÁ|¨â­Ó¨Ò¤l»¡©ú IF/ELSEIF/ELSE/ENDIF ªºÀ³¥Î¡C²Ä¤@­Ó¨Ò¤l¥i¥H¦b¦L¥X°Ñ¼Æªº¸ê®ÆÃþ«¬¡C

prn_type MACRO   argument
         temp TEXTEQU <argument>
         IF (TYPE temp) EQ 0
           arg_type TEXTEQU <UNKNOWN>
         ELSEIF (TYPE temp) EQ 1
           arg_type TEXTEQU <BYTE>
         ELSEIF (TYPE temp) EQ 2
           arg_type TEXTEQU <WORD>
         ELSEIF (TYPE temp) EQ 4
           arg_type TEXTEQU <DWORD>
         ELSEIF (TYPE temp) EQ 8
           arg_type TEXTEQU <QWORD>
         ENDIF
         %ECHO arg_type
ENDM
  ⁝
number   DD      10h,20h,30h,40h
  ⁝
prn_type number[rax*4+4]

¦b¤¶²Ð²Ä¤G­Ó¨Ò¤l¤§«e¡A¥ý¨Ó¤¶²Ð SetConsoleCursorPosition Win64 API¡CSetConsoleCursorPosition ¬O³]©w©R¥O´£¥Ü¦r¤¸ªº´å¼Ð¦ì¸m¡C¦pªG¨S¦³½Õ¾ã¡A¨º»ò©R¥O´£¥Ü¦r¤¸¦³ 80 ­Ó¦r¤¸¼e¡A25 ­Ó¦r¤¸°ª¡C¼e¥i¥H¬Ý¦¨¬O X ®y¼Ð¡A¥Ñ 0 ¦Ü 79¡F°ª¬O Y ®y¼Ð¡A¥Ñ 0 ¦Ü 24¡C¥Ñ¥ª¤W¨¤®y¼Ð¬° ( 0,0 )¡A¶V©¹¥k X ®y¼Ð¶V¤j¡A¶V©¹¤U Y ®y¼Ð¶V¤j ( ³o»P¼Æ¾Ç¤Wªºª½¨¤®y¼Ð¨t¬Û¤Ï )¡C

SetConsoleCursorPosition ªº­ì«¬¬O¡G

invoke  SetConsoleCursorPosition,\
        hConsoleOutput,     ; handle of console screen buffer
        dwCursorPosition    ; new cursor position coordinates

hConsoleOutput ¬O¼Ð·Ç¿é¥X¸Ë¸m¥N½X¡A¥i¥Ñ¥Î STD_OUTPUT_HANDLE ¬°°Ñ¼Æ©I¥s GetStdHandle ªº¦^¶Ç­È±o¨ì¡CdwCursorPosition ¬O­n³]©w´å¼Ðªº¦ì¸m¡AdwCursorPosition ªº 0¡ã15 ¦ì¤¸¬O X ®y¼Ð¡A16¡ã31 ¦ì¤¸¬O Y ®y¼Ð¡C­nª`·Nªº¬O¡A·í©R¥O´£¥Ü¦r¤¸µøµ¡µe­±¶ñº¡¦r¤¸«á¡A¦pªG¦A¦³¦r¤¸¿é¥X¨ì¸Óµøµ¡¡A¨º»ò´N·|©¹¤W±²°Ê¡C°²³]¥u©¹¤W±²°Ê¤@¦C¡A³o®É­Ô¡Aµøµ¡¤º¥ª¤W¨¤ªº®y¼Ð¬O ( 0,1 )¡A¦Ó ( 0,0 ) ¤w¸gÁô¨S¦bµøµ¡¤§¥~¤F¡C¦pªG©R¥O´£¥Ü¦r¤¸¤w¸g©¹¤W±²°Ê¡A¤£½×±²°Ê´X¦C¡A³o®É¦A¥Î SetConsoleCursorPosition ±N´å¼Ð³]¸m¦b²Ä 0 ¦C¡A¨º»ò SetConsoleCursorPosition ÁÙ¬O¥i¥H±N²Ä 0 ¦CÅã¥Ü©ó©R¥O´£¥Ü¦r¤¸ªºµøµ¡³Ì¤W­±¤@¦C¡C

©³¤Uªº GotoXY ¥¨¶°§Q¥Î IF/ELSE/ENDIF ¦b©I¥s SetConsoleCursorPosition ¤§«e¡A¥ýÀˬd X ®y¼Ð¬O§_¦b 0¡ã79¡AY ®y¼Ð¬O§_¦b 0¡ã24¡C¦pªG§¡¦b¦¹½d³ò¡A¨º»ò´N©I¥s SetConsoleCursorPosition¡A¦pªG¤£¦b³o½d³ò¤º¡A¦b²ÕĶ®É´Á´N¦L¥X¡uCursor position is out of range.¡v°T®§¡C©³¤U¬O GotoXY ¥¨¶°¤º®e¡G

GotoXY  MACRO   handle,x,y
  IF (x GE 0) AND (x LE 79) AND (y GE 0) AND (y LE 24)
        mov     rcx,handle
        mov     rdx,y
        shl     rdx,10h
        add     rdx,x
        call    SetConsoleCursorPosition
  ELSE
        ECHO Cursor position is out of range.
  ENDIF
ENDM

¦pªG¥Î«á­±¤è¦¡¤Þ¥Î GotoXY ªº¸Ü¡G¡uGotoXY hOutput,0,100¡v¡A¨º»ò ML64.EXE ¨Ã¤£·|²ÕĶ IF ¦Ü ELSE ¤§¶¡ªº¤º®e¡A¤Ï¦Ó·|¦b²ÕĶ®É´Á©ó©R¥O´£¥Ü¦r¤¸¤º¦L¥X¡uCursor position is out of range.¡v¨Ó¡C¦ý³o¨Ã¤£¯à¥Nªí¿ù»~¡A²ÕĶ¾¹¤´·|Ä~Äò²ÕĶ­ì©lµ{¦¡³Ñ¤U¨Óªº³¡¤À¡A¤]¯à»s³y¥X¥i°õ¦æÀɨӡC¦pªG­n±j­¢²ÕĶ¾¹²×¤î²ÕĶ¡A¥i¥H¦b ECHO ¤§«áºò±µµÛ¨Ï¥Î¡u.ERR¡v±ø¥ó¿ù»~°²«ü¥O¡C

IFE ªº·N¸q»P IF ¬Û¤Ï¡A¨ä»yªk¬O¡G

IFE §PÂ_¦¡
    µ{¦¡¤ù¬q
ENDIF

IFE ªº·N«ä¬O¦pªG§PÂ_¦¡¬°°²¡A«h²ÕĶµ{¦¡¤ù¬q¤¤ªºµ{¦¡¡CIFE ¤]¥i¥H·f°t ELSE ¨Ï¥Î¡A¨ä»yªk¬O¡G

IFE §PÂ_¦¡
    µ{¦¡¤ù¬q¤@
ELSE
    µ{¦¡¤ù¬q¤G
ENDIF

¤W­±ªºµ{¦¡¬O»¡¡A¦pªG§PÂ_¦¡¬°°²¡A«h²ÕĶµ{¦¡¤ù¬q¤@¡F§_«h²ÕĶµ{¦¡¤ù¬q¤G¡C

°²«ü¥O¡GIFB/ELSE/ENDIF »P IFNB/ELSE/ENDIF

IFB/ELSE/ENDIF »P IFNB/ELSE/ENDIF ¤]¬O±`¨£ªº±ø¥ó²ÕĶ°²«ü¥O¡A¥¦­Ì¤@¯ë¥Î¦b¥¨¶°¤¤¡AÀˬd¤Þ¥Î¥¨¶°®É¬O§_¦³°Ñ¼Æ§Ñ¤F¿é¤J¡C¥ý¨Ó¬Ý¬Ý IFB/ELSE/ENDIF¡A¥¦¤]¦³¨âºØ»yªk¡A²Ä¤@ºØ¬O¡G

IFB <°Ñ¼Æ>
    µ{¦¡¤ù¬q
ENDIF

IFB ¬O if blank ªº·N«ä¡A°Ñ¼Æ¥²¶·¦b¤@¹ï¡u<¡v¡B¡u>¡v¤§¶¡¡C¾ã¬qµ{¦¡¥Nªí¦pªG°Ñ¼Æ¬OªÅªº¸Ü ( ¤]´N¬O¨S¿é¤J³o­Ó°Ñ¼Æ )¡A¨º»ò´N²ÕĶµ{¦¡¤ù¬q¡C¤]¯àµø»Ý­n§ï¦¨²Ä¤GºØ»yªk¡A¦p¤U¡G

IFB <°Ñ¼Æ>
    µ{¦¡¤ù¬q¤@
ELSE
    µ{¦¡¤ù¬q¤G
ENDIF

¾ã¬qµ{¦¡¬O»¡¡A¦pªG¨S¿é¤J°Ñ¼Æªº¸Ü¡A¨º»ò´N²ÕĶµ{¦¡¤ù¬q¤@¡F§_«h²ÕĶµ{¦¡¤ù¬q¤G¡C

»P IFB/ELSE/ENDIF ¬Û¤Ïªº¬O IFNB/ELSE/ENDIF¡CIFNB/ELSE/ENDIF ¤]¦³¨âºØ»yªk¡A²Ä¤@ºØ¬O¡G

IFNB <°Ñ¼Æ>
    µ{¦¡¤ù¬q
ENDIF

IFNB ¬O if not blank¡A¾ã¬qµ{¦¡¥Nªí¦pªG°Ñ¼Æ¤£¬OªÅ¥Õªº¸Ü ( ¤]´N¦³¿é¤J³o­Ó°Ñ¼Æ )¡A¨º»ò´N²ÕĶµ{¦¡¤ù¬q¡C¤]¯àµø»Ý­n§ï¦¨²Ä¤GºØ»yªk¡G

IFNB <°Ñ¼Æ>
    µ{¦¡¤ù¬q¤@
ELSE
    µ{¦¡¤ù¬q¤G
ENDIF

¤W­zµ{¦¡¥Nªí¦pªG¦³¿é¤J°Ñ¼Æªº¸Ü¡A´N²ÕĶµ{¦¡¤ù¬q¤@¡F§_«h²ÕĶµ{¦¡¤ù¬q¤G¡CIFB/ELSE/ENDIF »P IFNB/ELSE/ENDIF °£¤FÀˬd¦b¤Þ¥Î¥¨¶°®É¡A¬O§_¿òº|°Ñ¼Æ¦Ó°µ¸É±Ï¤§¥~¡A¤]¥i¥H¥Î¨ÓÀˬd¬Y­Ó¦r¦êÅܼƬO§_¬°ªÅªº¡C¦b«á­±³oºØ±¡ªp¤U¡A°Ñ¼Æ¥H¦r¦êÅܼƦWºÙ¥N´À¡A¨Ã¥B¤£¥i¥H¥Î¤@¹ï¡u<¡v¡B¡u>¡v¬A¦í¡C©³¤Uªº TSTIFB.ASM µ{¦¡¡G

;TEST IFB¡G´ú¸ÕIFB°²«ü¥Oªºµ{¦¡
OPTION     CASEMAP:NONE
EXTRN      ExitProcess:PROC
INCLUDELIB e:\masm32\lib64\kernel32.lib
TestIFB MACRO   p1,p2
        var_str TEXTEQU <>    ;;var_str¬°ªÅ¦r¦ê
  ;;Àˬdp1°Ñ¼Æ¬O§_¬°ªÅªº
  IFB   <p1>
        result1 EQU <Parameter 1 is blank.>
  ELSE
        result1 EQU <Parameter 1 is not blank.>
  ENDIF
  ;;Àˬdp2°Ñ¼Æ¬O§_¬°ªÅªº
  IFNB  <p2>
        result2 EQU <Parameter 2 is not blank.>
  ELSE
        result2 EQU <Parameter 2 is blank.>
  ENDIF
  ;;Àˬdvar_str¦r¦êÅܼƬO§_¬°ªÅªº
  IFB   var_str
        result3 EQU <Variable is blank.>
  ELSE
        result3 EQU <Variable is not blank.>
  ENDIF
        %ECHO   result1 result2 result3
ENDM
;*************************************************
.CODE
;-------------------------------------------------
main    PROC
        TestIFB ,0
        xor     rcx,rcx
        call    ExitProcess
main    ENDP
;*************************************************
END

§O¬Ý³o­Óµ{¦¡¤p´N¬Ý»´¥¦¡A¥¦¬O­Ó§¹¾ãªºµ{¦¡¥i¥H¥¿±`²ÕĶ¡A¦Ó¥BÁÙ¯à°õ¦æ¡C¦b²ÕĶ®É¡A·|¦L¥X¡uParameter 1 is blank. Parameter 2 is not blank. Variable is blank.¡v¡A³o¬O¦]¬°¦b main °Æµ{¦¡ªº²Ä¤@¦æ¡A¤Þ¥Î TestIFB ®É¡A¨S¦³¿é¤J²Ä¤@­Ó°Ñ¼Æ¡A¦ý¦³¿é¤J²Ä¤G­Ó°Ñ¼Æ¡A¥t¥~¦b¥¨¶°ªº²Ä¤@¦æ«Å§i var_str ¦r¦êÅܼƬ°ªÅªº¡A¦]¦¹¤~·|¦³³o¼Ëªºµ²ªG¡C­nª`·Nªº¬O¡A¡u0¡v¤]¬O¥Nªí¦³¿é¤J°Ñ¼Æ¡A­nªÅªº¤~ºâ¬O¨S¿é¤J¡C¤U¹Ï¬O²ÕĶ TSTIFB.ASM ªº¹Lµ{¡G

°²«ü¥O¡GIFIDN/ELSE/ENDIF »P IFIDNI/ELSE/ENDIF

IFIDN/ELSE/ENDIF ªº»yªk¤]¦³¨âºØ¡A¸û²³æªº¬O

IFIDN <°Ñ¼Æ1>,<°Ñ¼Æ2>
    µ{¦¡¤ù¬q
ENDIF

IFIDN ¤¤ªº IDN ¬O¡uidentical¡vªº·N«ä¡A°Ñ¼Æ1 »P°Ñ¼Æ2 ³£¥²¶·¥H¤@¹ï¡u<¡v¡B¡u>¡v¬A°_¨Ó¤¤¶¡¥H¡u,¡v¹j¶}¡C¤W­zµ{¦¡´Nªí¥Ü¦pªG°Ñ¼Æ1 ©M°Ñ¼Æ2 ¬Û¦Pªº¸Ü¡A´N²ÕĶµ{¦¡¤ù¬q¡C¤]¥i¥Hµø»Ý­n¦Ó¨Ï¥Î²Ä¤GºØ»yªk¡G

IFIDN <°Ñ¼Æ1>,<°Ñ¼Æ2>
    µ{¦¡¤ù¬q¤@
ELSE
    µ{¦¡¤ù¬q¤G
ENDIF

¤W­zµ{¦¡´Nªí¥Ü¦pªG°Ñ¼Æ1 ©M°Ñ¼Æ2 ¬Û¦Pªº¸Ü¡A´N²ÕĶµ{¦¡¤ù¬q¤@¡F§_«h²ÕĶµ{¦¡¤ù¬q¤G¡C

IFIDNI/ELSE/ENDIF ¤ñ IFIDN/ELSE/ENDIF ¦h¤F¤@­Ó¡uI¡v¡A¬Oªí¥Ü¦b¤ñ¸û°Ñ¼Æ1 ©M°Ñ¼Æ2 ®É¡A©¿²¤­^¤å¦r¥À¤j¤p¼gªº¤£¦P¡A¨ä¥L¤è­±³£¤@¼Ë¡C¥t¥~¡A¸ò IFB/ELSE/ENDIF ¤@¼Ë¡AIFIDN/ELSE/ENDIF »P IFIDNI/ELSE/ENDIF ¤]¥i¥H¥Î©ó¤ñ¸û¦r¦êÅܼƬO§_¬Ûµ¥¡A¦pªG¬O¥Î©ó¤ñ¸û¦r¦êÅܼƪº¸Ü¡A¨º»ò¦r¦êÅܼƪº¦WºÙ¤£¥i¥Î¤@¹ï¡u<¡v¡B¡u>¡v¬A°_¨Ó¡C¨Ò¦p©³¤Uªº¨Ò¤l¡G

REGARG  MACRO   arg,register
        lead    SUBSTR <arg>,1,5    ;;lead¦r¦ê¬°argªº«e¤­­Ó¦r¤¸
  IFIDNI lead,<ADDR >               ;;Àˬdlead¦r¦ê¬O§_¬° "ADDR "¡A¤£ºÞ¤j¤p¼g¡A­Ylead¬° "Addr " ¤]ºâ¬Ûµ¥
        pointer SUBSTR <arg>,6      ;;­Y¬Ûµ¥¡A³]pointer¬°arg²Ä¤»­Ó¦r¤¸¤§«áªº¦r¦ê
        lea     register,pointer
  ELSE
        mov     register,arg
  ENDIF
ENDM

REGARG ¥¨¶°¥i¥Î©ó©I¥s Win64 API ®É¡A¶Ç»¼«e¥|­Ó°Ñ¼Æ¡C¥Ñ«e­±ªº ReadConsole¡BWriteConsole ª¾¹D¡A³o¨Ç°Ñ¼Æ¦³¨Ç¬O±`¼Æ¡B¦³¨Ç¬OÅܼơB¦³¨Ç¬O¦ì§}¡A¦pªG¬O«e¤GªÌ¥u»Ý¥Î MOV «ü¥O¡A±N¨ä¦s¤J¹ïÀ³ªº¼È¦s¾¹§Y¥i¡F¦ý¦pªG¬O¦ì§}¡A¥»¨Ó¥i¥H¥Î¡uMOV ¼È¦s¾¹,OFFSET¡v«ü¥O¡A¦ý¬O OFFSET ¤§«á©Ò±µªºÅܼƥu¯à¦b¸ê®Æ°Ï¬q¤º¡A¦ý©¹«á·|¦³³\¦h±¡§Î·|¨Ï¥Î°Ï°ìÅܼơA¦]¦¹³Ì¦n¬O¨Ï¥Î LEA «ü¥O¨D±o¦ì§}¡C§Ú­Ì¥Î¡u¦Û»sªº¹Bºâ¤l¡v¡AADDR¡A¨Ó¥Nªí¨ú±oÅܼƪº¦ì§}¡A´N¦¨¤F¤W­±ªº¥¨¶°¡C

°²«ü¥O¡GIFDIF/ELSE/ENDIF »P IFDIFI/ELSE/ENDIF

IFDIF/ELSE/ENDIF ªº»yªk¤]¬O¡G

IFDIF <°Ñ¼Æ1>,<°Ñ¼Æ2>
    µ{¦¡¤ù¬q
ENDIF

IFDIF ¤¤ªº DIF ¬O¡udifferent¡vªº·N«ä¡A°Ñ¼Æ1 »P°Ñ¼Æ2 ³£¥²¶·¥H¤@¹ï¡u<¡v¡B¡u>¡v¬A°_¨Ó¤¤¶¡¥H¡u,¡v¹j¶}¡C¤W­zµ{¦¡´Nªí¥Ü¦pªG°Ñ¼Æ1 ©M°Ñ¼Æ2 ¤£¦Pªº¸Ü¡A´N²ÕĶµ{¦¡¤ù¬q¡C¤]¥i¥Hµø»Ý­n¦¨¥[±jª©¡G

IFDIF <°Ñ¼Æ1>,<°Ñ¼Æ2>
    µ{¦¡¤ù¬q¤@
ELSE
    µ{¦¡¤ù¬q¤G
ENDIF

­zµ{¦¡´Nªí¥Ü¦pªG°Ñ¼Æ1 ©M°Ñ¼Æ2 ¤£¦Pªº¸Ü¡A´N²ÕĶµ{¦¡¤ù¬q¤@¡F¦pªG¬Û¦Pªº¸Ü¡A´N²ÕĶµ{¦¡¤ù¬q¤G¡CIFDIFI/ELSE/ENDIF ¤ñ IFDIF/ELSE/ENDIF ¦h¤F¤@­Ó¡uI¡v¡A¬Oªí¥Ü¦b¤ñ¸û°Ñ¼Æ1 ©M°Ñ¼Æ2 ®É¡A©¿²¤­^¤å¦r¥À¤j¤p¼gªº¤£¦P¡A¨ä¥L¤è­±³£¤@¼Ë¡C

°²«ü¥O¡GIFDEF/ELSE/ENDIF »P IFNDEF/ELSE/ENDIF

IFDEF/ELSE/ENDIF ªº»yªk¬O¡G

IFDEF ²Å¸¹
    µ{¦¡¤ù¬q
ENDIF

IFDEF ¬O if defined ªº·N«ä¡A©Ò¥H¤W­±ªºµ{¦¡¬O»¡¡A¦pªG²Å¸¹¤w©w¸q©Î¤w«Å§i¡A´N²ÕĶµ{¦¡¤ù¬q¡C¤]¥i¥H¨Ì»Ý­n¡A§â IFDEF ¼g¦¨¥[±jª©¡G

IFDEF ²Å¸¹
    µ{¦¡¤ù¬q¤@
ELSE
    µ{¦¡¤ù¬q¤G
ENDIF

¤W­±ªºµ{¦¡¬O»¡¡A¦pªG²Å¸¹¤w©w¸q©Î¤w«Å§i¡A´N²ÕĶµ{¦¡¤ù¬q¤@¡F§_«h²ÕĶµ{¦¡¤ù¬q¤G¡C

IFNDEF/ELSE/ENDIF ¤¤¡AIFNDEF ªº¡uN¡v¬O not ªº·N«ä¡A©Ò¥H IFNDEF ¦X°_¨Ó´N¬O if not defined¡C¥Nªí¦pªG²Å¸¹¥¼©w¸q©Î¥¼«Å§iªº¸Ü¡A«h²ÕĶ IFNDEF ¦Ü ELSE ¤§¶¡ªºµ{¦¡½X¡A§_«h²ÕĶ ELSE ¦Ü ENDIF ¤§¶¡ªºµ{¦¡½X¡C¥¦ªº»yªk¤]¦³¨âºØ¡A¦p¤U¡G

IFNDEF ²Å¸¹
    µ{¦¡¤ù¬q
ENDIF

©Î

IFNDEF ²Å¸¹
    µ{¦¡¤ù¬q¤@
ELSE
    µ{¦¡¤ù¬q¤G
ENDIF

©³¤Uªºµ{¦¡ TSTIFDEF.ASM ¥i¥H¦b²ÕĶ®É¡AÅý ML64.EXE ¨Ì¾Ú¬O§_«Å§i UNICODE ÅܼƨӨM©w²ÕĶ¦¨¸U°ê½Xªºª©¥»©Î¬O ASCII ª©¥»¡C¥ý¬Ý§¹¾ãªºµ{¦¡½X¡G

;TEST IFDEF¡G´ú¸ÕIFDEF°²«ü¥Oªºµ{¦¡
INCLUDE    GREETING1.INC
EXTRN      WriteConsoleW:PROC

IFDEF   UNICODE
  WriteConsole  TEXTEQU <WriteConsoleW>
ELSE
  WriteConsole  TEXTEQU <WriteConsoleA>
ENDIF

WStr    MACRO    str_name,len_name,ascii_string
        len_name DQ     @SizeStr(ascii_string)
        str_name LABEL  WORD
   FORC char,<ascii_string>
        DB       "&char&",0
   ENDM
        DB       0,0
ENDM

;string¥¨¶°¥i¨Ì¬O§_©w¸qUNICODE¡A§â¦r¦êÂà´«¦¨ASCII¦r¦ê©Î¸U°ê½X¦r¦ê(¶È­­©ó­^¤å
;¦r¥À¡Bªü©Ô§B¼Æ¦r¡K¡Kµ¥)¡CÂà´««áªº®æ¦¡¬O¡G
;len_nam DQ ¦r¦êªø«×
;strname DB ¦r¦ê¤º®e
;¨Ò¦p¤Þ¥Î®É¡G¡ustring  sStr,cChr,<I love you>¡v¡A·|³y¦¨©³¤Uµ{¦¡½X
;¡@ASCII¡GcChr DQ 10
;¡@¡@¡@¡@ sStr DB "I love you",0
;UNICODE¡GcChr DQ 10
;¡@¡@¡@¡@ sStr DB "I",0," ",0,"l",0,"o",0,"v",0,"e",0," ",0,"y",0,"o",0,"u",0,0,0
string  MACRO   strname,len_nam,sentence
 IFNDEF UNICODE
        len_nam DQ   @SizeStr(sentence)
        strname DB   "&sentence&",0     ;;ASCII¦r¦ê¨â®Ç­n¥[¡u"¡v
        ECHO    MAKE ASCII EDITION      ;;²ÕĶ®É¡AÅã¥Ü²£¥ÍASCIIª©
 ELSE
        WStr    strname,len_nam,sentence
        ECHO    MAKE UNICODE EDITION    ;;²ÕĶ®É¡AÅã¥Ü²£¥ÍUNICODEª©
 ENDIF
ENDM
;*******************************************************************************
.DATA
hOutput DQ      ?
chrWrt  DQ      ?
string  sStr,cChr,<I love you>
;*******************************************************************************
.CODE
;-------------------------------------------------------------------------------
main    PROC
        GetStdH STD_OUTPUT_HANDLE,hOutput
        mov     rcx,hOutput
        lea     rdx,sStr
        mov     r8,cChr
        mov     r9,OFFSET chrWrt
        mov     QWORD PTR [rsp+20h],0
        call    WriteConsole
exit:   Quit
main    ENDP
;*******************************************************************************
END

«Å§i²Å¸¹ªº¦a¤è³q±`¬O¦b­ì©lµ{¦¡¸Ì¡A¦Ó¥B¤j³¡¤À±¡ªp¤U³£¬O¦b­ì©lµ{¦¡«e­±¡A¨Ï¥Î EQU¡B=¡BTEXTEQU µ¥°²«ü¥O«Å§i¡F©Î¬O©ñ¦b¥]§tÀɤ¤¡A¥H INCLUDE °²«ü¥O±N¸Ó¥]§tÀÉ¥[¤J¡C°£¦¹¤§¥~¡A¤]¥i¥H¦b²ÕĶ®É´Á«Å§i¡A½Ð¨£¤U­±ªº»¡©ú¡C

·L³nªº¥¨¶°²ÕĶ¾¹¦³­Ó¿ï¶µ¡u/D¡v( ¤]¥i¥H¼g¦¨¡u-D¡v)¡A¯à°÷¦b©R¥O´£¥Ü¦r¤¸©³¤U¿é¤J«ü¥O®É¡A¦P®É«Å§i²Å¸¹¤Î¨äªì©l­È¡C«Å§iªº²Å¸¹¤Îªì©l­È¡Aª½±µ±µ¦b¡u/D¡vªº«á­±¡A¤¤¶¡¤£¥i¦³ªÅ¥Õ¡A³o¼Ë´N¬Û·í©ó¦b­ì©lµ{¦¡«Å§i¤F³o­Ó²Å¸¹¡C

¥Ñ¥H¤Wªº»¡©ú¡A­n²ÕĶ TSTIFDEF.ASM ¥i¤À¬°¨âºØ¤£¦Pªº±¡ªp¡G

⑴¡G¦b²ÕĶ®É¡A¤U¹F¡u/DUNICODE=0¡v«Å§i UNICODE ÅܼơA¦p¦¹·|²£¥Í¸U°ê½Xªº¦r¦ê¡A¦P®É¤]·|©I¥s¼e¦r¤¸ª©ªº Win64 API¡C¦p¤U¹Ï¼Ð¥Ü①ªº«ü¥O¡A²ÕĶ¹Lµ{·|Åã¥Ü¡uMAKE UNICODE EDITION¡v¡A§i¶D¨Ï¥ÎªÌ«Ø¥ß¸U°ê½Xª©¥»ªºµ{¦¡¡A¥iª½±µ°õ¦æ¡A¦p②¼Ð¥Ü³B¡C
⑵¡G²ÕĶ®É¡A¨S¦³¡u/D¡v¿ï¶µ¡A¦b­ì©lµ{¦¡¤Î¥]§tÀɤ]³£¨S¦³©w¸q UNICODE ÅܼơA¨º»ò UNICODE ´N¬O¥¼©w¸q¡A³o¼Ë·|²£¥Í ASCII ¦r¦ê¡A©I¥s ASCII ª©ªº Win64 API¡A¦p¤U¹Ï¼Ð¥Ü③ªº«ü¥O¡A¥t¥~²ÕĶ¹Lµ{¤]·|Åã¥Ü¡uMAKE ASCII EDITION¡v¡C²ÕĶ§¹¦¨¥iª½±µ°õ¦æ¡A¦p¤U¹Ï④¼Ð¥Ü³B¡C

¤U¹Ï¤¤¡A³£¦³¾Þ§@³o¨âºØ±¡ªp¡G

  1. ML64.EXE ªº¿ï¶µ¡u/nologo¡v( ©Î¡u-nologo¡v¡A¥²¶·¬O¤p¼g ) ¨Ï²ÕĶ®É¡A¤£Åã¥Üª©Åv°T®§¡C³o¼Ë°µªº¥Øªº¥u¬O¦]¬°¡A¦pªGÅã¥Üª©Åv°T®§ªº¸Ü¡A·|Åý¤@­Óµøµ¡µLªk®e¯Ç¡C¶¶±a¤@´£¡ALINK.EXE ¤]¦³¡u/NOLOGO¡v¿ï¶µ¡A¨ä§@¥Î¤]¬O¤£Åã¥Üª©Åv°T®§¡A¦ý¥²¶·¤j¼g¡C
  2. ¦b string ¥¨¶°¤¤¡A¥Î¨â¦¸ ECHO °²«ü¥O¡A§i¶D¨Ï¥ÎªÌ©Ò²ÕĶ¥X¨Óªº¬O­þ¤@ºØª©¥»¡A©ÒÅã¥Üªºª©¥»¥H¬õ¾í¦â®Ø½u®Ø¦í¡C
  3. ¤W­±¥H¨âºØ¤£¦Pª¬ªp²ÕĶ¡A°õ¦æµ²ªG§¡Åã¥Ü¬Û¦P¦r¦ê ( ¤W¹Ïºñ¦â®Ø )¡A¦ý³o¨â¦¸²£¥Íªºµ{¦¡½X»P¦r¦ê§¡¤£¬Û¦P¡A§Y¨Ï¬Ý°_¨Ó¨S¤°»ò¤£¤@¼Ë¡A¦ý°©¤l¸Ì«o¤j¤j¤£¦P¡C¤£«Hªº¸Ü¡A¥i¥H¥Î x64dbg ¸ü¤JÆ[¹î´Nª¾¹D¤F¡C

°²«ü¥O¡GGOTO

GOTO ¤@¯ë¥Î©ó¥¨¶°¤§¤¤¡AµL±ø¥ó¸õÅD¦Ü¥¨¶°¼Ð°O³B²ÕĶ¡A¥¨¶°ªº¼Ð°O¤]¨Ï¥Î¡u:¡v²Å¸¹§@¬°ÃѧO¡A¨ä«á±µ¤å¦r¡C³oÂI»P x64 «ü¥Oªº JMP¡BJZ¡K¡K¸õÅD«ü¥Oªº¥Ø¼Ð¤£¤@¼Ëªº¡Ax64 «ü¥Oªº¼Ð°O¬O¤å¦r¤§«á¤~±µ¡u:¡v¡C¨Ò¦p©³¤Uªº¨Ò¤l¡G

NullStr MACRO   str_name,string
  len   TEXTEQU @SizeStr(string)
  IFIDN len,<02>        ;;¦]¬°"¤]ºâ¦r¤¸¡A¬G¦³¨â­Ó
    GOTO quit
  ENDIF
  str_name DB string
:quit
ENDM

.CONST
NullStr str1,""
NullStr str2,"¯É­¸¿P¡AÁcªáµº¡Aºì©ñÆA¦p¥P¡C"

NullStr ¥Î¨ÓÀˬdÀ³¥Îµ{¦¡©w¸qªº¦r¦ê¬O§_¬°ªÅªº¡A¤W­±ªº str1 ´N¤£·|³Q²ÕĶ¾¹©w¸q©ó .CONST °Ï¬q¡Astr2 «h·|¡C


±ø¥ó¿ù»~°²«ü¥O

±ø¥ó¿ù»~°²«ü¥O¥i¥H¥Î©ó°£¿ù¡AÀˬd²ÕĶ®É´Áªº¿ù»~¡C³o¨Ç°²«ü¥O¤]¥i¥H¥Î©ó¥¨¶°¤¤¡A¥¦­Ì¦³ .ERR¡B.ERRE¡B.ERRNZ¡B.ERRDEF¡B.ERRNDEF¡B.ERRB¡B.ERRNB¡B.ERRIDN¡B.ERRIDNI¡B.ERRDIF¡B.ERRDIFI¡C

.ERR

µL±ø¥ó±j¨î²£¥Í¿ù»~¡A¨Ã²×¤î²ÕĶ¡A©ó¿Ã¹õ¤W¦L¥X¡uerror A2052:forced error¡v°T®§¡C

.ERRE »P .ERRNZ

.ERRE »P .ERRNZ ªº»yªk¬O

.ERRE   §PÂ_¦¡
.ERRNZ  §PÂ_¦¡

.ERRE ¬O«ü¦pªG§PÂ_¦¡¬°°²¡A´Nµo¥Í¿ù»~¡A¨Ã²×¤î²ÕĶ¡A©ó¿Ã¹õ¤W¦L¥X¡uerror A2053:forced error : value equal to 0¡v¡C.ERRNZ ¬O«ü¦pªG§PÂ_¦¡¬°¯u¡A´Nµo¥Í¿ù»~¡A¨Ã²×¤î²ÕĶ¡A©ó¿Ã¹õ¤W¦L¥X¡uerror A2054:forced error : value not equal to 0¡v¡C

.ERRDEF »P .ERRNDEF

.ERRDEF »P .ERRNDEF ªº»yªk¬O

.ERRDEF     ²Å¸¹
.ERRNDEF    ²Å¸¹

.ERRDEF ¬O«ü­Y²Å¸¹¤w©w¸q¡A´Nµo¥Í¿ù»~¡A¨Ã²×¤î²ÕĶ¡A©ó¿Ã¹õ¤W¦L¥X¡uerror A2056:forced error : symbol defined¡v¡C.ERRNDEF ¬O«ü­Y²Å¸¹¥¼©w¸q¡A´Nµo¥Í¿ù»~¡A¨Ã²×¤î²ÕĶ¡A©ó¿Ã¹õ¤W¦L¥X¡uerror A2055:forced error : symbol not defined¡v¡C¦¹³Bªº²Å¸¹¥]§tÅܼƦWºÙ¡B°Æµ{¦¡¦WºÙ¡B¼Ð°Oµ¥¡C

.ERRB »P .ERRNB

.ERRB »P .ERRNB ªº»yªk¬O

.ERRB   <¤Þ¼Æ>
.ERRNB  <¤Þ¼Æ>

³o¨â­Ó°²«ü¥O¥Î¦b¥¨¶°¤¤¡A¥Î©óÀË´ú¶Ç»¼¹L¨Óªº¤Þ¼Æ¬O§_ªÅªº¡C¡u¤Þ¼Æ¬OªÅªº¡vªº·N«ä¬O«ü¤Þ¥Î¥¨¶°®É¡A¨S¦³¶Ç»¼¬Y¨Ç¤Þ¼Æ¡C.ERRB ¬O«ü¦pªG¸Ó¤Þ¼Æ¬OªÅªº¡A´Nµo¥Í¿ù»~¡F.ERRNB ¬O«ü¦pªG¸Ó¤Þ¼Æ¦s¦b¡A´Nµo¥Í¿ù»~¡C

.ERRIDN¡B.ERRIDNI¡B.ERRDIF »P .ERRDIFI

³o¥|­Ó°²«ü¥Oªº»yªk¦p¤U¡G

.ERRIDN     <¤Þ¼Æ1>,<¤Þ¼Æ2>
.ERRIDNI    <¤Þ¼Æ1>,<¤Þ¼Æ2>
.ERRDIF     <¤Þ¼Æ1>,<¤Þ¼Æ2>
.ERRDIFI    <¤Þ¼Æ1>,<¤Þ¼Æ2>

³o¥|­Ó°²«ü¥O¬O¤ñ¸û¤Þ¼Æ1 »P¤Þ¼Æ2 ¬O§_¬Û¦P¡A¡uIDN¡v¬O¬Û¦Pªº·N«ä¡A¡uDIF¡v¬O¤£¦Pªº·N«ä¡C¦]¦¹¡u.ERRIDN <¤Þ¼Æ1>,<¤Þ¼Æ2>¡v¬O»¡¡A¦pªG¤Þ¼Æ1 »P¤Þ¼Æ2 ¬Û¦P¡A´N·|µo¥Í¿ù»~¡A¨Ã²×¤î²ÕĶ¡A©ó¿Ã¹õ¤W¦L¥X¡uerror A2059:forced error : strings equal¡v¡C¡u.ERRDIF <¤Þ¼Æ1>,<¤Þ¼Æ2>¡v¬O»¡¡A¦pªG¤Þ¼Æ1 »P¤Þ¼Æ2 ¤£¦P¡A´N·|µo¥Í¿ù»~¡A¨Ã²×¤î²ÕĶ¡A©ó¿Ã¹õ¤W¦L¥X¡uerror A2060:forced error : strings not equal¡v¡C

°²«ü¥O³Ì«á¦³²K¥[¡uI¡v¡Aªí¥Ü¤ñ¸û®É¤j¤p¼g¬Ý¦¨¤@¼Ë¡A¤]´N¬O¤£°Ï¤À¤j¤p¼g¡A¨Ò¦p¡uRAX¡v¸ò¡urax¡vµø¬°¬Û¦P¡C³o¥|­Ó°²«ü¥O³q±`¥Î©ó¥¨¶°¤¤¡AÀˬd¶Ç»¼¶i¨Óªº¤Þ¼Æ¬O§_»P¹w³]ªº¤@¼Ë¡C


¥¨¶°ªºÀ³¥Î¡Ginvoke

¸g¹L²Ä¤­¡B¤»¨â³¹º©ªøªº¤¶²Ð¡A²{¦b²×©ó­n¶i¤J­«¶bÀ¸¤F¡Ð¡Ð¥¨¶°¦³¦ó¥Î¡H¤p¤ì°¸·Q¦Ü¤Ö¦³¨â­Ó¡G①­×¥¿²ÕĶ¾¹¿ù»~¡A°Ñ¦Òªþ¿ý¤G¡B②¼W¥[²ÕĶ¾¹¥\¯à¡A¨Ò¦p invoke¡C¥»³¹¶È»¡©ú«áªÌ¡Cinvoke ¬O¥ý¶i§Q¥Î¥¨¶°¥H¤Î±ø¥ó²ÕĶ¥´³y¥X¨Óªº¡A¥¦¿í¦u x64 ©I¥sºD¨Ò¡A¥i¥H¥Î¨Ó©I¥s Win64 API¡A³o¼Ë´N¯à²¤Æ©I¥s¬yµ{¡C¦b»¡©ú¦p¦ó¥´³y invoke ¤§«e¡A¥ý»¡»¡¥¦ªº¾ú¥v¡C

¦b·L³nµo°â MASM 6.x ªº®É­Ô¡A¥¿¬O 16 ¦ì¤¸ªº§@·~¨t²Î MS¡ÐDOS ¥\¦¨¨­°h¡A32 ¦ì¤¸ªº Windows 95/98 ¹ñÅSÀY¨¤¤§»Ú¡C¨º®Éªº²ÕĶ¾¹ºÙ¬° ML.EXE¡A¯à¶}µo 16 ¦ì¤¸ªº MS¡ÐDOS µ{¦¡¥H¤Î 32 ¦ì¤¸ªº Windows µ{¦¡¡C·L³n¤]¬O¦b¦¹®É¡A§â invoke °²«ü¥O¥[¤J¨ì ML.EXE ²ÕĶ¾¹¤§¤¤¡A¤§«eª©¥»¨Ã¤£¤ä´© invoke¡CWin32 API ©I¥sºD¨ÒºÙ¬° STDCALL¡Ainvoke ¶È»Ý¤@¦æ´N¯à©I¥s Win32 API¡Aµo´§¤F«Ü¦nªº¥\¥Î¡C¨ì¤F 64 ¦ì¤¸ªº Win64 ®É¥N¡A¶}µo 64 ¦ì¤¸µ{¦¡ªº²ÕĶ¾¹¬O ML64.EXE¡A¦Ó·L³n«o§â invoke ±q ML64.EXE §R±¼¤F¡A©Ò¥H«e´X³¹¸Ì¤~·|¥Î«Ü³Â·Ðªº¤èªk©I¥s Win64 API¡C¤p¤ì°¸¥´ºâ¥ý»¡»¡ ML.EXE ¤¤ invoke ªº¥Îªk¡A¥H¤Î¦³¤°»ò¥\¯à¡A¦A¨Ó¤¶²Ð¥ý¶i¦p¦ó¥Î¥¨¶°¥H¤Î±ø¥ó²ÕĶ¨Ó¼ÒÀÀ¥¦¡C

¦b ML.EXE ¤¤²ÕĶ Win32 µ{¦¡®É¡Ainvoke ªº»yªk¬O¡G

invoke  °Æµ{¦¡¦WºÙ,°Ñ¼Æ¦Cªí

¨ä¤¤°Æµ{¦¡¦WºÙ¥i¥H¬O Windows API ªº¦WºÙ¡A¤]¥i¥H¬Oµ{¦¡³]­p®v©Ò©w¸qªº°Æµ{¦¡¦WºÙ¡C·íµM³o¨Ç¦WºÙ³£·|³Q²ÕĶ¾¹Âà´«¦¨ Windows API ¦ì§}©Î°Æµ{¦¡ªº¦ì§}¡C§Ú­Ìª¾¹D¡A¨Æ¹ê¤W°Æµ{¦¡¦WºÙ¨ä¹ê´N¬O¥¦ªº¦ì§}¡A©Ò¥H¦b¤Ö¼Æ±¡§Î¤U¡A°Æµ{¦¡¦WºÙ¤]¥i¥H¬O¶¡±µ©w§}©Ò«üªº¦ì§}¡C°Ñ¼Æ¦Cªí¤¤¡A¥i¯à¦³³\¦h°Ñ¼Æ¡A¥¦­Ì¤§¶¡¥H¡u,¡v¤À¹j¡C³o¨Ç°Ñ¼Æ¥i¤À¬°¥|Ãþ¡G①¼È¦s¾¹¡B②±`¼Æ¡B③ÅܼƤ§¼Æ­È¡B④ÅܼƤ§¦ì§}¡C«e¤TÃþ¸û¬°³æ¯Âª½±µ¼g¥X¨Ó§Y¥i¡A¤ñ¸û³Â·Ðªº¬O³Ì«á¤@Ãþ¡C

ADDR ¹Bºâ¤l

¥H invoke ©I¥s°Æµ{¦¡®É¡A¦pªG­n¥H¬Y­ÓÅܼƦì§}·í¦¨°Ñ¼Æªº¸Ü¡A¥²¶·¦bÅܼƫe­±¥[¤W ADDR ¹Bºâ¤l¡AADDR ±Mªù¥Î©ó invoke ªº°Ñ¼Æ¦Cªí¤¤¡A¨D¥XÅܼƪº¦ì§}¡C¨Ò¦p¥Î invoke ©I¥s WriteConsole ®É¡A²Ä¤G­Ó°Ñ¼Æ¬O­n¦L¥Xªº¦r¦ê¦ì§}¡B²Ä¥|­Ó°Ñ¼Æ¬OÅܼƦì§}¡AWriteConsole ·|±N¹ê»Ú¤W¦L¥X´X­Ó¦r¤¸¦s¤J¸ÓÅܼƤ¤¡A³o¨â­Ó°Ñ¼Æ³£¥²¶·¥Î¨ì ADDR ¹Bºâ¤l¡C¦p¤U¦¡¡G

        invoke  WriteConsole,hOutput,ADDR string,SIZEOF string,ADDR chrWrt,0

¤@¥ØÁAµM¡A¦Ó¥B¤@¦æ´N¸Ñ¨M¤F¡A¬O¤£¬O«Ü²³æ¡C¦ý¬O¡A³o¬O 32 ¦ì¤¸ªº Windows µ{¦¡¡F¦p­n¶}µo 64 ¦ì¤¸ªº Windows µ{¦¡¡A¨º¥i¨S invoke ¥i¥Î¡C¦pªG­n¥H¥¨¶°¡B±ø¥ó²ÕĶ­«·s¥´³y¤@­Ó invoke ¥¨¶°¡AÅý ML64.EXE «ì´_¦b 32 ¦ì¤¸®É¥Nªº invoke ¥\¯à¡A¨º»ò¥¦ªº¥Îªk³Ì¦n¤]¸ò¤W­±¤@¼Ë¡C¤]´N¬O»¡¡A­«·s¥´³yªº invoke ­nÅý ML64.EXE ¤ä´©¹³¤W­±ªº¤è¦¡©I¥s Win64 API ©Î¬O¦Û¦æ©w¸qªº°Æµ{¦¡¡A¨º´N±o­n§â¡uinvoke WriteConsole,hOutput,ADDR string,SIZEOF string,ADDR chrWrt,0¡v®i¶}«áÅܦ¨¡G

        mov     rcx,Output
        lea     rdx,string
        mov     r8,SIZEOF string
        lea     r9,chrWrt
        mov     QWORP PTR [rsp+32],0
        call    WriteConsole

±q®i¶}«áªºµ²ªG¨Ó¬Ý¡AADDR ¨ä¹ê¬O¨Ï¥Î¤F LEA «ü¥O¡A¨Ó¨D±o¦ì§}¡A»¡¬ï¤F¤@ÂI¤]¤£µ}©_¡C

¤ÀªR invoke ¥¨¶°

¨º»ò¡A¤S­n¦p¦ó¤~¿ì¨ì±N invoke ®i¶}¦¨³o¼Ë¤lªº©O¡H©³¤U¤p¤ì°¸¸ÕµÛ¨Ó¸ÑŪ¥]§tÀɤ¤ªº invoke ¥¨¶°¡C­º¥ý­n§ä¨ì invoke ¥¨¶°¦b­þ¨à¡H®Ú¾Ú MASM64 ªº»¡ªk¡A­ì©lµ{¦¡ªº²Ä¤@¦æ³q±`¬O¡uinclude \masm32\include64\masm64rt.inc¡v¡A¦]¦¹¥Î¤å®Ñ³B²z³nÅé¡A¨Ò¦p UltraEdit32¡A¶}±Ò masm64rt.inc Æ[¹î«e´X¦æ¡A¦p¤U¡G

OPTION DOTNAME                          ; required for macro files
option casemap:none                     ; case sensitive

include \masm32\include64\win64.inc     ; main include file
include \masm32\macros64\vasily.inc     ; main macro file
include \masm32\macros64\macros64.inc   ; auxillary macro file

«Ü©¯¹Bªº¡A§Q¥Î·j´M¡uinvoke MACRO¡v¡A«Ü§Ö´N¦b macros64.inc ´N§ä¨ì¤F©w¸q invoke ¥¨¶°ªº¦a¤è¡A©w¸qªº¤è¦¡¤U¡G

invoke MACRO fname:REQ,args:VARARG
  procedure_call fname,args
ENDM

«Ü©úÅã¡Ainvoke ªº²Ä¤@­Ó°Ñ¼Æ¬O¥²­nªº¡A³o·íµM¡A¦]¬°³o¬O­n©I¥s Win64 API ªº¦WºÙ¡A¦Ó«á­±ªº°Ñ¼Æ¼Æ¶q«h¤£©T©w¡C¦Ó invoke ªº¤º®e¶È¶È¤@±ø¡A¤Þ¥Î¥t¤@­Ó¥¨¶°¡Aprocedure_call¡C³o­Ë¬O¥X¥G·N®Æ¤§¥~¡A¥»·Q invoke À³¸Ó«Ü½ÆÂø¡A¨S·Q¨ì«o¬O¤Þ¥Î¥t¤@­Ó¥¨¶°¡C©ó¬O¦A¥h´M§ä¡uprocedure_call¡v¡A¤]«Ü©¯¹B¡A¦b macros64.inc ¤º§äµÛ¤F¡A¨ä«Å§i¤è¦¡¦p¤U¡G

procedure_call MACRO fname:REQ,a1,a2,a3,a4,a5,a6,a7,a8,a9,a10, \
                               a11,a12,a13,a14,a15,a16,a17,a18, \
                               a19,a20,a21,a22,a23,a24,a25

LOCAL lead,wrd2,ssize,sreg,svar

;; ********************
;; argument count limit
;; ********************
  IFNB <a25>
    % echo ????************************************
    % echo ????argument limit exceeded in procedure -> fname
    % echo ????argument count limit of 24 arguments
    % echo ????************************************
    .err
    goto function_call
  ENDIF

;; **************************
;; first 4 register arguments
;; **************************
  IFNB <a1>
    REGISTER a1,cl,cx,ecx,rcx
  ENDIF

  IFNB <a2>
    REGISTER a2,dl,dx,edx,rdx
  ENDIF

  IFNB <a3>
    REGISTER a3,r8b,r8w,r8d,r8
  ENDIF

  IFNB <a4>
    REGISTER a4,r9b,r9w,r9d,r9
  ENDIF
;; **************************
;; following stack arguments
;; **************************
  IFNB <a5>
    STACKARG a5,32
  ENDIF

  IFNB <a6>
    STACKARG a6,40
  ENDIF

  IFNB <a7>
    STACKARG a7,48
  ENDIF
  ⁝
  IFNB <a24>
    STACKARG a24,184
  ENDIF

:function_call
call fname

ENDM

¥J²ÓÆ[¹î«á¡A·|µo²{ procedure_call ¤j­P¤À¦¨¤T³¡¤À¡G①¬õ¦â³¡¤ÀÀˬd¬O§_¶W¹L 24 ­Ó°Ñ¼Æ¡A¦pªG¶W¹L´Nµo¥Í¿ù»~¡C②ÂŦⳡ¤À³B²z«e¥|­Ó°Ñ¼Æ¡C③ºñ¦â³¡¤À³B²z²Ä¤­­Ó¤Î¨ä¥H«áªº°Ñ¼Æ¡C

procedure_call ¥Î IFNB/ENDIF Àˬd²Ä 25 ­Ó°Ñ¼Æ¬O§_¦s¦b¡A¦pªG¦s¦b´Nªí¥Ü¶W¹L 24 ­Ó°Ñ¼Æ¡A¨º»ò´Nµo¥Í¿ù»~¡C¤p¤ì°¸¤£ª¾¹D¬°¦ó¥HÀˬd¬O§_¶W¹L 24 ­Ó°Ñ¼Æ·í°µ¿ù»~¡A²q·Q¥i¯à¬O Win64 API °Ñ¼Æ³Ì¦hªº¬O 24 ­Ó§a¡C

²Ä¤G³¡¤À¡A¤Þ¥Î REGISTER ³B²z«e¥|­Ó°Ñ¼Æ¡C¨C¦¸¤Þ¥Î³o¥|­Ó°Ñ¼Æªº¤è¦¡³£¬O¤@¼Ë¡G

REGISTER    °Ñ¼Æ,¤K¦ì¤¸ªº¼È¦s¾¹,¤Q¤»¦ì¤¸ªº¼È¦s¾¹,¤T¤Q¤G¦ì¤¸ªº¼È¦s¾¹,¤»¤Q¥|¦ì¤¸ªº¼È¦s¾¹

REGISTER ¥¨¶°¤]¬O¦b macros64.inc ¸Ì­±¡A¦ý­­©ó½g´T¥u¦C¥X³¡¤À¤º®e¡A³o³¡¤À¤º®e¦b¤U­±ÂŦâ®Ø¤º¡CREGISTER ·|Àˬd±q procedure_call ¶Ç¨Óªº°Ñ¼Æ¡A¤]´N¬O anum¡A¬Ý¬Ý¥¦ªº«e´X­Ó¦r¤¸¬O§_¬°⑴¡uADDR¡v¡B⑵¡u"¡v¡B⑶¡uBYTE PTR¡v¡B⑷¡uWORD PTR¡v¡B⑸¡uDWORD PTR¡v¡B⑹¡uQWORD PTR¡v

REGISTER MACRO anum,breg,wreg,dreg,qreg
  ⁝
  ssize SIZESTR <anum>
  ⁝
  IF ssize GT 4                             ;; handle ADDR notation
    lead SUBSTR <anum>,1,4
    IFIDNI lead,<ADDR>
      wrd2 SUBSTR <anum>,6
      lea qreg, wrd2
      goto elbl
    ENDIF
  ENDIF
  
  IF ssize GT 1                             ;; handle quoted text
    lead SUBSTR <anum>,1,1
    IFIDNI lead,<">
      mov qreg, reparg(anum)
      goto elbl
    ENDIF
  ENDIFIF getattr(anum) EQ IMM                   ;; IMMEDIATE
    mov qreg, anum
    goto elbl
  ENDIF
  ⁝
ENDM
¡A¦AÀˬdanum ¬O§_¬°⑺±`¼Æ¡B⑻¼È¦s¾¹¡B⑼°O¾ÐÅéÅܼơAµM«á¤Àªù§OÃþ³B²z¡C

⑴¡G­n´ú¸Õ«e´X­Ó¦r¤¸¬O§_¬°¡uADDR¡v¡A¨º»ò¥ýÀˬd°Ñ¼Æ¬O§_¶W¹L¥| ( ¦]¬° ADDR ¦³¥|­Ó¦r¤¸¡A¨ä«á¥²©wÁÙ¦³¨ä¥L¦r¤¸¡A¬G¤@©w¶W¹L¥| )¡C¦pªG¶W¹L¡A¦AÀˬd«e¥|­Ó¦r¤¸¬O§_¬°¡uADDR¡v¡A¦pªG¬O¡A¨º»ò¨Ï wrd2 ¬°¦©°£¡uADDR ¡v¤§«áªº¦r¦ê¡A¤]´N¬O wrd2 ¬°°Ñ¼Æ²Ä¤»­Ó¦r¤¸¶}©l¨ìµ²§À©Ò§Î¦¨ªº¦r¦ê ( ¦]¬°²Ä¤­­Ó¦r¤¸¬OªÅ¥Õ )¡C±µµÛ´N¬O¥Î LEA «ü¥O¨D¥X wrd2 ªº¦ì§}¡A¦s©ó¼È¦s¾¹¤º¡Cµ{¦¡½X¦p¥k¥Õ¦â³¡¤À¡C

⑵¡GÀˬd°Ñ¼Æ¬O§_¬°¤@¦r¦ê¡A¤]´N¬O¥H¡u"¡v°_ÀY¡C¸ò¤W­±¨BÆJ´X¥G¤@¼Ë¡A¥ýÀˬd°Ñ¼Æªø«×¬O§_¶W¹L¤@¡A¦pªG¶W¹L¨º»ò­n¤Þ¥Î reparg ¥¨¶°¨ç¦¡¡Cµ{¦¡½X¦p¥k¬õ¦â³¡¤À¡C

¤U­±¶À¦â³¡¤Àªºµ{¦¡½X¬O reparg ¥¨¶°¨ç¦¡¡C«e­±´X¦æ¬OÀˬd°Ñ¼Æªº²Ä¤@­Ó¦r¤¸¬O§_¬°¡u"¡v¡A¦pªG¬Oªº¸Üªí¥Ü°Ñ¼Æ¬°¤@¦r¦ê¡A¥ý¦b¸ê®Æ°Ï¬q¤¤«Ø¥ß¦¹¦r¦ê¡A¨ä¦WºÙ¬° nustr¡AµM«á¦b¦¹ nustr ¦r¦ê¤§«á¦A³]¥ß¤@­Ó pnu ÅܼơA¡upnu DQ nustr¡v¡A¨Æ¹ê¤W¡Apnu Åܼƪº¤º®e´N¬O nustr ¤§¦ì§}¡AµM«á±N¦¹¦ì§}·í°µ¦^¶Ç­Èªð¦^¡C

reparg MACRO arg
  LOCAL nustr,pnu
  LOCAL quot
    quot SUBSTR <arg>,1,1
  IFIDN quot,<">                ;; if 1st char = "
    .data
      align 16
      nustr db arg,0            ;; write arg to .DATA section
      pnu dq nustr              ;; get pointer to it
    .code
    EXITM <pnu>                 ;; return the pointer
  ELSE
    EXITM <arg>                 ;; else return arg unmodified
  ENDIF
ENDM

⑶¡ã⑹¡G»P⑴¡B⑵ªº¹Lµ{®t¤£¦h¡A´N¤£¸Ô­z¡C

⑺¡GÀˬd°Ñ¼Æ¬O§_¬°±`¼Æ ( ¦b²Õ¦X»y¨¥¤¤±`±`§â±`¼ÆºÙ¬°¥ß§Y­È¡Aimmediate )¡C³o¥²¶·­n§Q¥Î OPATTR ¹Bºâ¤l¡C¦ý¬O REGISTER «o¬O¤Þ¥Î getattr ¥¨¶°¨ç¦¡¡A¨£¤W­±ÂŦâ®ØÂŦⳡ¤Àªºµ{¦¡½X¡C¦ý¦pªG¯uªº¥h·j´M getattr¡A·|µo²{¥¦¥u¦³¤@¹D«ü¥O¡uEXITM % opattr(arg)¡v¡Aarg ¬°¨ä°Ñ¼Æ¡C¦pªG¦^¶Ç­È¬O 36 ( IMM ¦b macros64.inc ¦³©w¸q¡A¨ä­È¬°¡u36¡v)¡Aªí¥Ü¬°±`¼Æ¡Aª½±µ±N¦¹±`¼Æ²¾¤J¼È¦s¾¹§Y¥i¡C

⑻¡ã⑼¡G»P⑺ªº¹Lµ{®t¤£¦h¡A´N¤£¸Ô­z¡C

invoke ªºÀ³¥Î

¤j­PÁA¸Ñ¥¨¶°ªº¹B§@¤§«á¡A±µ¤U¨Ó´N¬O¹ê§@¤F¡C§Q¥Î MASM64 SDK ©Ò´£¨Ñªº¥]§tÀÉ¡A´N¯à¹ê²{¦b MASM 6.x ª©ªº invoke °ª¶¥»yªk¡A¤£¥²¦A¶O¤ß¥h­pºâ°ïÅ|¡B©I¥s¤è¦¡µ¥·Ð¤Hªº°ÝÃD¡C¦b©¹«áªº´X³¹¸Ì¡A³£·|±Ä¥Î³oºØ¤è¦¡¼¶¼g Win64 µ{¦¡¡C

¥H MASM64 SDK ªº¥]§tÀɼ¶¼g²Õ¦X»y¨¥µ{¦¡¡Aºâ¬O«D±`®e©öªº¡A¥u­n¦b­ì©lµ{¦¡ªº²Ä¤@¦æ¼g¤W¡uINCLUDE \masm32\include64\masm64rt.inc¡v¡A©Ò¦³¥]§tÀÉ¡B¶×¤Jµ{¦¡®w¥H¤Î©Ò¦³³]©w³£¦Û°Ê§¹¦¨¡C©³¤U´N¬O§â²Ä¤T³¹ªº GREETING.ASM ¥H MASM64 SDK ¤è¦¡§ï¼g¡G

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
INCLUDE \masm32\include64\masm64rt.inc
MAX_NAME        EQU     4*2+2   ;¤¤¤å©m¦W³Ì¦h¥|­Ó¤¤¤å¦r¡A¨C­Ó¤¤¤å¦r¦û¨â­Ó¦ì¤¸²Õ¡A¦A¥[¤W0dH¡B0aH
;***************************************************************************************************
.CONST
sName           DB      "½Ð¿é¤J±zªº©m¦W¡]³Ì¦h¥|­Ó¤¤¤å¦r¡^¡G"
sHowAreYou      DB      "¡A±z¦n¶Ü¡H"
;***************************************************************************************************
.DATA
hOutput         DQ      ?               ;¼Ð·Ç¿é¥X¸Ë¸m¥N½X
hInput          DQ      ?               ;¼Ð·Ç¿é¤J¸Ë¸m¥N½X
qWritten        DQ      ?
qRead           DQ      ?
sBuffer         DB      MAX_NAME+SIZEOF sHowAreYou DUP (0)
;***************************************************************************************************
.CODE
;---------------------------------------------------------------------------------------------------
main    PROC
;Àò±o¼Ð·Ç¿é¥X/¿é¤J¸Ë¸m¥N½X¡A¤À§O¦s¤JhOutput¡BhInputÅܼƤ¤
        invoke  GetStdHandle,STD_OUTPUT_HANDLE
        cmp     rax,INVALID_HANDLE_VALUE
        je      exit
        mov     hOutput,rax
        invoke  GetStdHandle,STD_INPUT_HANDLE
        cmp     rax,INVALID_HANDLE_VALUE
        je      exit
        mov     hInput,rax

;¦b¼Ð·Ç¿é¥X¸Ë¸m¤W¡A¦L¥XsName¦r¦ê¡A·í°µ´£¥ÜÅý¨Ï¥ÎªÌ©ú¥Õ¸Ó¿é¤J¤°»ò
        invoke  WriteConsole,hOutput,ADDR sName,SIZEOF sName,ADDR qWritten,0

;¦b¼Ð·Ç¿é¤J¸Ë¸m¤WŪ¨ú¦r¦ê¡C³Ì¦hŪ¨ú (MAX_NAME-2) ­Ó¦ì¤¸²Õ¡A¹ê»ÚŪ¨ú¦r¦êªº¦ì¤¸²Õ­Ó¼Æ¦s©óqReadÅܼƤ¤
        invoke  ReadConsole,hInput,ADDR sBuffer,MAX_NAME,ADDR qRead,0

;§âsHowAreYou¦r¦ê·h²¾¨ì¨Ï¥ÎªÌ¿é¤Jªº©m¦W¤§«áªº¦ì§}
        sub     qRead,2                 ;¹ê»ÚŪ¨ú¦r¦êªº¦ì¤¸²Õ­Ó¼Æ¡A¤£¥]§t0dH¡B0aH
        mov     rdi,OFFSET sBuffer
        add     rdi,qRead               ;RDI¡×¨Ï¥ÎªÌ¿é¤Jªº©m¦W¤§«áªº¦ì§}
        mov     rcx,SIZEOF sHowAreYou
        mov     rsi,OFFSET sHowAreYou
        mov     r8,rcx
        cld
        rep     movsb

        add     r8,qRead                ;R8¡×sHowAreYou¦r¦êªø«×¥[¤W¤£¥]§t0dH¡B0aHªº©m¦Wªø«×
        invoke  WriteConsole,hOutput,ADDR sBuffer,r8,ADDR qWritten,0

exit:   invoke  ExitProcess,0
main    ENDP
;***************************************************************************************************
END

§â¤W­±­ì©lµ{¦¡Àx¦s¦¨ GREETING2.ASM¡A¥H¤U­±¤è¦¡²ÕĶ¤Î³sµ²¡G

E:\HomePage\SOURCE\Win64>SET LINK=/SUBSYSTEM:CONSOLE /ENTRY:main [Enter]

E:\HomePage\SOURCE\Win64>PATH E:\masm32\bin64;%path% [Enter]

E:\HomePage\SOURCE\Win64>cd CONSOLE [Enter]

E:\HomePage\SOURCE\Win64\CONSOLE>ml64 greeting2.asm [Enter]
Microsoft (R) Macro Assembler (x64) Version 14.25.28614.0
Copyright (C) Microsoft Corporation.  All rights reserved.

 Assembling: greeting2.asm
Microsoft (R) Incremental Linker Version 14.25.28614.0
Copyright (C) Microsoft Corporation.  All rights reserved.

/SUBSYSTEM:CONSOLE /ENTRY:main
/OUT:greeting2.exe
greeting2.obj

E:\HomePage\SOURCE\Win64\CONSOLE>greeting2 [Enter]
½Ð¿é¤J±zªº©m¦W¡]³Ì¦h¥|­Ó¤¤¤å¦r¡^¡G¤p¤ì°¸ [Enter]
¤p¤ì°¸¡A±z¦n¶Ü¡H
E:\HomePage\SOURCE\Win64\CONSOLE>

invoke ¥¨¶°ªº¥Îªk

©³¤U»¡©ú¦b MASM64 SDK ¤¤¡A¥ý¶i©Ò¥´³yªº invoke ¥¨¶°¤§¥Îªk¡C¥ý¨Ó¬Ý¬Ý¥¦ªº»yªk¡G

invoke  °Æµ{¦¡¦W©Î Windows API ¦WºÙ,°Ñ¼Æ¦Cªí

°Ñ¼Æ¦Cªí¤¤ªº°Ñ¼Æ­Ó¼Æ¨Ã¤£©T©w¡A¨Ì¾Ú°Æµ{¦¡©Î Windows API ªº»Ý­n¡A°Ñ¼Æ¤§¶¡¥H¡u,¡v¤À¹j¡C°Ñ¼Æ¦Cªí¤§¤¤ªº°Ñ¼Æ¡A¥i¤À¬°´XÃþ¡G①±`¼Æ¡]©Î¥ß§Y­È¡^¡B②Åܼơ]¥]§t¥þ°ìÅܼƸò°Ï°ìÅܼơ^¡B③¼È¦s¾¹¡B④±`¼Æ©ÎÅܼƪº¦ì§}¡B⑤¦r¦ê¡C«e¤TÃþ³£¥i¥Hª½±µ¼g¦b°Ñ¼Æ¦Cªí¤§¤¤¡C²Ä④Ãþ¥²¶·¦b¥Nªí¦ì§}ªº±`¼Æ©ÎÅܼƦWºÙ«e¥[¤W¡uADDR¡v¡F²Ä⑤Ãþ¬O¦r¦ê¡A¥²¶·¥H¤@¹ï¡u"¡v±N¦r¦ê¬A¦í¡C¨Ò¦p©³¤Uªº¨Ò¤l¡]greeting2.asm ²Ä 29 ¦æ¡^¡G

invoke  WriteConsole,hOutput,ADDR sName,SIZEOF sName,ADDR qWritten,0

²Ä¤@­Ó°Ñ¼Æ¡AhOutput ¬OÅܼơAª½±µ¼g¦b°Ñ¼Æ¦Cªí¤¤¡F²Ä¤G­Ó°Ñ¼Æ¬O¦r¦ê±`¼Æ¡AsName¡Aªº¦ì§}¡A«e­±¥[¡uADDR¡v¡F²Ä¤T­Ó°Ñ¼Æ¬O sName ªºªø«×¡A¥ý¥Î¡uSIZEOF¡v¨D¥X¨Ó¡AµM«á¥iµø¬°±`¼Æ¡A¦]¦¹¼g¦¨¡uSIZEOF sName¡v¡F±µ¤U¨Óªº°Ñ¼Æ¬OÅܼƦì§}¡A¬G­n¥[¤W¡uADDR¡v¡F³Ì«á¤@­Ó°Ñ¼Æ¬O±`¼Æ¡Aª½±µ¼g¤W§Y¥i¡C


¤ñ¸û°Æµ{¦¡»P¥¨¶°

°Æµ{¦¡»P¥¨¶°³£¥i¥HÅý­ì©lµ{¦¡Åܱoºë²¡A¬Ý°_¨Ó§ó¬°²M·¡¡C¦ý¬O¥¦­Ì¤§¶¡ÁÙ¬O¦³¨Ç¤£¦P¡A³o¸Ì¦C¥X¤U­±´XÂI¤£¦P¡G

①¡B°Æµ{¦¡ªº¤º®e¥²¶·§¨¦b PROC »P ENDP ¤§¶¡¤@¼Ë¡A°Æµ{¦¡µ²§ô®É¡A¦b ENDP «e­n¼g¤W°Æµ{¦¡ªº¦WºÙ¡F¥¨¶°¤º®e§¨¦b MACRO »P ENDM ¤§¶¡¡A¦ý¬O¥¨¶°µ²§ôªº ENDM «e¤£»Ý­n§â¥¨¶°¦WºÙ¦A­«½Æ¼g¥X¨Ó¡C
②¡B©w¸q°Æµ{¦¡®É¡A´N¦b¸Ó³B²£¥Í¹ê»Úªº¾÷±ñ½X¡A¦Ó¦b©I¥s°Æµ{¦¡®É¡A¶È¶È²£¥Í¡uCALL¡v«ü¥O¡F«Å§i¥¨¶°®É¡A¦b¸Ó³B¤£²£¥Í¹ê»Úªº¾÷±ñ½X¡A¦Ó¬O¦b¤Þ¥Î¥¨¶°ªº¦a¤è²£¥Í¾÷±ñ½X¡A¨Ã¥B¨C¤Þ¥Î¤@¦¸¡A´N²£¥Í¤@¦¸¾÷±ñ½X¡C
③¡B©w¸q°Æµ{¦¡©Ò¦bªºµ{¦¡½X¬O¦bµ{¦¡°õ¦æ®É´Á¹B¦æ¡F«Å§i¥¨¶°©Ò¦bªºµ{¦¡½X¬O¦b­ì©lµ{¦¡²ÕĶ®É¡A©ó¥¨¶°¤Þ¥Î®É­Ô¹B¦æ¡C
④¡B©I¥s°Æµ{¦¡®É¡A¥²¶·¥Î¡uCALL¡v«ü¥O¡A¨ä«á­n¥[¤W°Æµ{¦¡¦WºÙ¡A¦Ü©ó°Ñ¼Æ¥²¶·¦b°õ¦æ¡uCALL¡v«ü¥O¤§«e¥ý³]©w¦n¡F¨Ï¥Î¥¨¶°®É¡Aª½±µ¼g¤W¥¨¶°¦WºÙ§Y¥i¡A¥¨¶°¦WºÙ¤§«á±µµÛ°Ñ¼Æ¡C

¤W­±ªº´X­Ó¶µ¥Ø¤¤¡A¥i¯à¦³¨ÇÃø¥H´y­z¡A¤]¤£®e©öÅé·|¡C¦ý¨SÃö«Y¡AÀHµÛ¸gÅç¼W¥[¡A·|ºCºCÁA¸Ñ¡C¤U­±´X³¹ªºµ{¦¡½d¨Ò¡A³£·|¥HML64.EXE ·f°t MASM64 SDK ¥]§tÀÉ¡A¨Ó¼¶¼g Win64 µ{¦¡¡C


µù¤@¡GLABEL

¦³®É­Ô¤@­ÓÅܼƻݭn¦³¨â­Ó¦WºÙ¡A©Î¬O¥u»Ý­n«ü©w¬Y­Ó¦ì§}®É¡A¥i¥H¥Î¡uLABEL¡v°²«ü¥O¡CLABEL ªº»yªk¬O¡G

²Å¸¹¦W  LABEL   ¸ê®ÆÃþ«¬

LABEL ·|§â²Å¸¹¦W«ü©w¬°«á­±ªº¸ê®ÆÃþ«¬¡A¦ý¬O«o¤£¤À°t°O¾ÐÅéªÅ¶¡¡C¤W­±ªº¸ê®ÆÃþ«¬¥i¥H¬O BYTE¡BWORD¡BDWORD¡BQWORD µ¥ MASM ¤w©w¸qªº¸ê®ÆÃþ«¬¡C¨Ò¦p©³¤Uªº¨Ò¤l¡G

.DATA
x       LABEL   DWORD
y       QWORD   1111222233334444h
        ⁝
        mov     eax,x
        mov     rcx,y

x¡By ³o¨â­ÓÅܼƪº¦ì§}³£¬Û¦P¡A¦ý¬O x ªºªø«×¬OÂù¦r²Õ¡Ay ¬O¥|¦r²Õ¡C¦]¦¹¤W­zµ{¦¡°õ¦æ«á¡Ax ¬° 33334444H¡Ay ¬° 1111222233334444H¡C

¦b REPEAT/ENDM °²«ü¥Oªº¨Ò¤l¤¤¡A­ì¥»ªºµ{¦¡½X¬O¡G

letter  ="a"
counter =26
alpha   LABEL   BYTE
REPEAT  counter
        DB      letter
        letter =letter+1
ENDM

²ÕĶ«á¡A²£¥Íªºµ{¦¡½X¬O¡G

alpha   LABEL   BYTE
        DB  "abcdefghijklmnopqrstuvwxyz"

ÁöµM¦b DB °²«ü¥O¤§«e¡A¨S¦³¼g¥X¦r¦êªº¦WºÙ¡A¦ý¬O¤W¤@¦æªº¡ualpha LABEL BYTE¡v«Å§i¤F alpha Åܼƪº¦ì§}´N¬O»P DB ©w¸qªº¦r¦ê¦ì§}¬Û¦P¡C¦]¦¹¦b©¹«áªº­ì©lµ{¦¡¤¤¡A´£¨ì alpha¡A¨ä¹ê´N¬O³o­Ó¦r¦ê¡C