ªþ¿ý¥|¡@Windows ³B²z¦r¦ê¨ç¦¡

³o­Óªþ¿ý¨Ó»¡¤@»¡¦b Windows ¤¤³B²z¦r¦êªº¨ç¦¡¡C¥»ªþ¿ý¥H¥\¯à¨Ó¤À¦¨¤U¦C´X³¡¤À¡G①¨D¦r¦êªø«×¡B②½Æ»s¦r¦ê¡B③¤ñ¸û¦r¦ê¡B④¦X¨Ö¦r¦ê¡B⑤¨Ì¾Ú®æ¦¡¥Í¦¨¦r¦ê¡B⑥¦b¤@¦r¦ê¤¤´M§ä¬Y­Ó¦r¤¸¡B⑦¦b¤@¦r¦ê¤¤´M§ä¬Y­Ó¦r¦ê¡C


¨D¦r¦êªø«×

strlen API »P wcslen API

strlen »P wcslen ³£¥Î©ó¨D¥X¦r¦êªºªø«×¡A®t§O¬O«eªÌ­pºâ ANSI ¦r¦ê¡]¤]´N¬O ASCII ½s½Xªº¦r¦ê¡^¡A«áªÌ¬O­pºâ¼e¦ì¤¸¦r¦ê¡]´N¬O¸U°ê½X UCS¡Ð2 ½s½Xªº¦r¦ê¡^¡Cstrlen »P wcslen ¬O C »y¨¥µ{¦¡®w¤¤¤º«Øªº¼Ð·Ç¨ç¦¡¡A©I¥s¥¦­Ì®É¥²¶·­n¤Þ¤J MSVCRT.LIB µ{¦¡®w¡C¥¦­Ìªº»yªk¬O¡G

invoke  strlen,\
        pszString       ; address of string to count
invoke  wcslen,\
        pszString       ; address of string to count

strlen¡Bwcslen ³£¥u¦³¤@­Ó°Ñ¼Æ¡ApszString¡A¬O­n­pºâªø«×ªº¦r¦ê©Ò¦b¦ì§}¡A¦¹¦r¦ê¶·¥H¹sµ²§À¡C¥¦­Ìªº¦^¶Ç­È¬O¦r¤¸­Ó¼Æ¡A¤£¥]§tµ²§Àªº¹s¡Cª`·N¡I¥¦­Ìªº¦^¶Ç­È¨Ã«D¦r¦êªº¦ì¤¸²Õ­Ó¼Æ¡A¦ý«Ü®e©ö´«ºâ¡C¹ï strlen ¦Ó¨¥¡A¦r¤¸­Ó¼Æ´N¬O¦ì¤¸²Õ­Ó¼Æ¡F¹ï wcscat ¦Ó¨¥¡A¦r¤¸­Ó¼Æ­¼¥H¤Gµ¥©ó¦ì¤¸²Õ­Ó¼Æ¡C

lstrlen API

lstrlen ¥Î©ó¨D±o¦r¦êªø«×¡A¬O Windows ¤º«Øªº¨ç¦¡¡AWin64 API ªº¤@­û¡A©I¥s®É¥²¶·¤Þ¤J KERNEL32.LIB¡C¸ò¨ä¥L Win64 API ¤@¼Ë¡A¤À¬°¨âºØª©¥»¡GlstrlenA¡BlstrlenW¡A¨Ì§Ç¬O ANSI ª©»P¼e¦r¤¸ª©¡A¨Ì¾Ú¦b­ì©lµ{¦¡¤¤¬O§_´¿«Å§i¡uUNICODE EQU 1¡v©Î¡u__UNICODE__ EQU 1¡v¨M©w¡Clstrlen ¥Îªk¦p¤U¡G

invoke  lstrlen,\
        pszString       ; address of string to count

¦^¶Ç­È¸ò strlen ©Î wcslen ¤@¼Ë¡A³£¬O¦r¤¸­Ó¼Æ¡A¨Ã«D¦ì¤¸²Õ­Ó¼Æ¡C

StringCchLength API

StringCchLength ¤]¬O­pºâ¦r¦êªø«×ªº¨ç¦¡¡A¥¦¬O Windows ¤º«Øªº¨ç¦¡¡A»P«e­z¨ç¦¡¤£¦Pªº¬O StringCchLength ¨ã¦³Ãä¬É³]©w¡A¯à°÷ªý¤îÀb«È§Q¥Î½w½Ä°Ï·¸¦ìªºº|¬}¡A¦Óµo°Êªº§ðÀ»¡CStringCchLength ªº­ì«¬¬O¡G

invoke  StringCchLength,\
        pszString,\     ; address of string to count
        cchMax,\        ; maximum number of characters
        pcch            ; address of a variable

StringCchLength ¨ä¹ê¬O¦b§t¤JÀÉ strsafe.h ¤ºªº¤@­Óµ{¦¡¡A¦pªG­nÀ³¥Î¦b²Õ¦X»y¨¥¤W¡A


½Æ»s¦r¦ê

strcpy API »P wcscpy API

strcpy »P wcscpy ³£¥Î©ó½Æ»s¦r¦ê¡A®t§O¬O«eªÌ¥Î©ó ANSI ¦r¦ê¡A«áªÌ¥Î©ó¼e¦ì¤¸¦r¦ê¡Cstrcpy »P wcscpy ³£¬O C »y¨¥µ{¦¡®w¤¤¤º«Øªº¼Ð·Ç¨ç¦¡¡A©I¥s¥¦­Ì®É¥²¶·­n¤Þ¤J MSVCRT.LIB µ{¦¡®w¡C¥¦­Ìªº»yªk¬O¡G

invoke  strcpy,\
        pszDest,\       ; address of destination string
        pszSrc          ; address of source string
invoke  wcscpy,\
        pszDest,\       ; address of destination string
        pszSrc          ; address of source string

strcpy »P wcscpy ·|§â¦b pszSrc ¦ì§}¤W¡A¥H¹sµ²§Àªº¦r¦ê¡]¥iµø¬°¨Ó·½¦r¦ê¡^½Æ»s¨ì pszDest ¦ì§}¤W¡C¦pªG°õ¦æ¦¨¥\¡A¥¦­Ìªº¦^¶Ç­È¬O pszDest¡A¤]´N¬O½Æ»sªº¦r¦ê¦ì§}¡F¦pªG¥¢±Ñ¡A¨S¦³¦^¶Ç­È¡C

lstrcpy API

lstrlen ¥Î©ó½Æ»s¦r¦ê¡A¬O Windows ¤º«Øªº¨ç¦¡¡AWin64 API ªº¤@­û¡A©I¥s®É¥²¶·¤Þ¤J KERNEL32.LIB¡C¸ò¨ä¥L Win64 API ¤@¼Ë¡A¤À¬°¨âºØª©¥»¡GlstrlenA¡BlstrlenW¡A¨Ì§Ç¬O ANSI ª©»P¼e¦r¤¸ª©¡A¨Ì¾Ú¦b­ì©lµ{¦¡¤¤¬O§_´¿«Å§i¡uUNICODE EQU 1¡v©Î¡u__UNICODE__ EQU 1¡v¨M©w¡Clstrcpy ¥Îªk¦p¤U¡G

invoke  lstrcpy,\
        pszDest,\       ; address of destination string
        pszSrc          ; address of source string

lstrcpy ·|§â¦ì©ó pszSrc ¦ì§}¤W¥H¹sµ²§Àªº¦r¦ê¡A½Æ»s¨ì pszDest ©Ò«üªº¦ì§}¤W¡C¦pªG lstrcpy °õ¦æ¦¨¥\¡A¦^¶Ç­È¬O pszDest¡A¤]´N¬O½Æ»sªº¦r¦ê¦ì§}¡F¦pªG¥¢±Ñ¡A¦^¶Ç­È¬°¹s¡C

StringCchCopy API

StringCchCopy ¤]¬O¥Î¨Ó½Æ»s¦r¦êªº¨ç¦¡¡A¨ä­ì«¬¦p¤U¡G

invoke  StringCchCopy,\
        pszDest,\       ; address of destination string
        cchDest,\       ; size of the destination buffer
        pszSrc          ; address of source string

StringCchCopy »P strcpy¡Bwcscpy¡Blstrcpy ¤£¦Pªº¬O¨ã¦³²Ä¤G­Ó°Ñ¼Æ¡A«ü©w¤F¥Øªº¦r¦êªº¤j¤p¡Aªý¤îÀb«È§Q¥Î½w½Ä°Ï·¸¦ìªºº|¬}¡A¦Óµo°Êªº§ðÀ»¡C


¤ñ¸û¦r¦ê

strcmp API »P wcscmp API

strcmp »P wcscmp ³£¬O¥Î¨Ó¤ñ¸û¦r¦ê¡A®t§O¬O«eªÌ¬O¥Î©ó ANSI ¦r¦ê¡A«áªÌ¥Î©ó¼e¦ì¤¸¦r¦ê¡Cstrcmp »P wcscmp ³£¬O C »y¨¥µ{¦¡®w¤¤¤º«Øªº¼Ð·Ç¨ç¦¡¡A©I¥s¥¦­Ì®É¥²¶·­n¤Þ¤J MSVCRT.LIB µ{¦¡®w¡C¥¦­Ì­ì«¬¬O¡G

invoke  strcmp,\
        pszStr1,\        ; address of string1
        pszStr2          ; address of string2
invoke  wcscmp,\
        pszStr1,\        ; address of string1
        pszStr2          ; address of string2

strcmp »P wcscmp ·|§â¦ì©ó pszStr1¡BpszStr2 ¦ì§}¤W¡A¨â­Ó¥H¹sµ²§Àªº¦r¦ê¡A±qÀY¶}©l§â¨C­Ó¦r¤¸³v¤@¬D¥X¨Ó¤ñ¸û¡Aª½¦Ü¤ñ¥X¤j¤p¬°¤î¡C¤ñ¸ûµ²ªG¦s©ó RAX ¤º¡A¦³¤TºØ±¡§Î¡G①¦pªG¨â¦r¦ê¬Ûµ¥¡ARAX ¬°¹s¡C②¦pªG pszStr1 ©Ò¦bªº¦r¦ê¤ñ¸û¤p¡ARAX ¬°­t­È¡C③¦pªG pszStr1 ©Ò¦bªº¦r¦ê¤ñ¸û¤j¡ARAX ¬°¥¿­È¡C³oùتº¥¿­t­È¨ä¹ê¬O¡Ï1©M¡Ð1¡A¦Ó³oùةҿתº¦r¦ê¤j¤p¨Ã«D¦r¦êªø«×¡A¦Ó¬O«ü¨â¦r¦ê²Ä¤@­Ó¤£¦Pªº¦r¤¸¡A­þ¤@­Ó¦r¦ê¦r¤¸©Ò¥Nªíªº ANSI ½s½X©Î¸U°ê½X½s½Xªº¼Æ­È¤j¤p¡C¨Ò¦p©³¤Uªº¨Ò¤l¡G

str1    DB      "I love assembly.",0
str2    DB      "I Love Assembly Language.",0
  ⁝
invoke  strcmp,OFFSET str1,OFFSET str2

©I¥s strcmp °õ¦æ¤§«á¡Astr1 ¤ñ¸û¤j¡C³o¬O¦]¬°³o¨â­Ó¦r¦êªº²Ä¹s­Ó¦r¤¸³£¬O¡uI¡v¡A²Ä¤@­Ó¦r¤¸³£¬OªÅ¥Õ¡Fª½¨ì²Ä¤G­Ó¦r¤¸¤~¤£¦P¡Astr1 ¬O¡ul¡v¡Astr2 ¬O¡uL¡v¡A¨ä ANSI ½s½X¡A¥ç§Y ASCII ½s½X¤À§O¬O 6CH »P 4CH¡A©Ò¥H str1 ¸û¤j¡C

lstrcmp API

lstrlen ¥Î©ó¤ñ¸û¦r¦ê¡A¬O Windows ¤º«Øªº¨ç¦¡¡AWin64 API ªº¤@­û¡A©I¥s®É¥²¶·¤Þ¤J KERNEL32.LIB¡C¸ò¨ä¥L Win64 API ¤@¼Ë¡A¤À¬°¨âºØª©¥»¡GlstrcmpA¡BlstrcmpW¡A¨Ì§Ç¬O ANSI ª©»P¼e¦r¤¸ª©¡A¨Ì¾Ú¦b­ì©lµ{¦¡¤¤¬O§_´¿«Å§i¡uUNICODE EQU 1¡v©Î¡u__UNICODE__ EQU 1¡v¨M©w¡Clstrcmp ­ì«¬¦p¤U¡G

invoke  lstrcmp,\
        pszStr1,\        ; address of string1
        pszStr2          ; address of string2

lstrcmp ªº¨â­Ó°Ñ¼Æ¡B¦^¶Ç­Èªº·N¸q³£»P¤W­z strcmp¡Bwcscmp ¬Û¦P¡A¤£¦AÂØ­z¡C


¦X¨Ö¦r¦ê

strcat API »P wcscat API

strcat »P wcscat ³£¬O¥Î©ó¦X¨Ö¦r¦ê¡A®t§O¬O«eªÌ¬O¥Î©ó ANSI ¦r¦ê¡A«áªÌ¥Î©ó¼e¦ì¤¸¦r¦ê¡Cstrcat »P wcscat ³£¬O C »y¨¥µ{¦¡®w¤¤¤º«Øªº¼Ð·Ç¨ç¦¡¡A©I¥s¥¦­Ì®É¥²¶·­n¤Þ¤J MSVCRT.LIB µ{¦¡®w¡C¥¦­Ìªº­ì«¬¬O¡G

invoke  strcat,\
        pszDest,\       ; address of destination string
        pszSrc          ; address of source string
invoke  wcscat,\
        pszDest,\       ; address of destination string
        pszSrc          ; address of source string

strcat »P wcscat ·|§â¦ì©ó pszSrc ¦ì§}¤Wªº¦r¦ê¡]¥iµø¬°¨Ó·½¦r¦ê¡^¡A½Æ»s¨ì¦ì©ó pszDest ¦ì§}¤Wªº¦r¦ê¡]¥iµø¬°¥Øªº¦r¦ê¡^§ÀºÝ¡C½Æ»s«e¡A³o¨â­Ó¦r¦ê³£¶·¥H¹sµ²§À¡A·íµM½Æ»s®É·|±N­ì¥ý¦ì©ó pszDest ¦ì§}¤Wªº¦r¦êµ²§Àªº¹s°£¥h¡A¹F¨ì¦X¨Ö¦r¦êªº¥Øªº¡C¦pªG°õ¦æ¦¨¥\¡A¥¦­Ìªº¦^¶Ç­È¬O pszDest¡A¤]´N¬O¥Øªº¦r¦ê¦ì§}¡F¦pªG¥¢±Ñ¡A¨S¦³¦^¶Ç­È

lstrcat API

lstrcat ¥Î©ó¦X¨Ö¦r¦ê¡A¬O Windows ¤º«Øªº¨ç¦¡¡AWin64 API ªº¤@­û¡A©I¥s®É¥²¶·¤Þ¤J KERNEL32.LIB¡C¸ò¨ä¥L Win64 API ¤@¼Ë¡A¤À¬°¨âºØª©¥»¡GlstrcatA¡BlstrcatW¡A¨Ì§Ç¬O ANSI ª©»P¼e¦r¤¸ª©¡A¨Ì¾Ú¦b­ì©lµ{¦¡¤¤¬O§_´¿«Å§i¡uUNICODE EQU 1¡v©Î¡u__UNICODE__ EQU 1¡v¨M©w¡Clstrcmp ­ì«¬¦p¤U¡G

invoke  lstrcat,\
        pszDest,\       ; address of destination string
        pszSrc          ; address of source string

lstrcat ·|§â¦ì©ó pszSrc ¦ì§}¤Wªº¦r¦ê¡]¥iµø¬°¨Ó·½¦r¦ê¡^¡A½Æ»s¨ì¦ì©ó pszDest ¦ì§}¤Wªº¦r¦ê¡]¥iµø¬°¥Øªº¦r¦ê¡^§ÀºÝ¡C½Æ»s«e¡A³o¨â­Ó¦r¦ê³£¶·¥H¹sµ²§À¡A·íµM½Æ»s®É·|±N­ì¥ý¦ì©ó pszDest ¦ì§}¤W¦r¦êµ²§Àªº¹s°£¥h¡A¹F¨ì¦X¨Ö¦r¦êªº¥Øªº¡C¦pªG°õ¦æ¦¨¥\¡A¥¦­Ìªº¦^¶Ç­È¬O pszDest¡A¤]´N¬O¥Øªº¦r¦ê¦ì§}¡F¦pªG¥¢±Ñ¡A¦^¶Ç­È¬°¹s¡C


¨Ì¾Ú®æ¦¡¥Í¦¨¦r¦ê

¨Ì¾Ú®æ¦¡¥Í¦¨¦r¦êªº·N«ä¬O«ü±N¬Y¨ÇÅܼơA¨Ì¾Úµ{¦¡³]­p®v«ü©wªº®æ¦¡±±¨î¦r¦ê¡A¥Í¦¨¦r¦ê¨ÃÀx¦s©ó°O¾ÐÅ餤¡Csprintf API ´N¬O¨ä¤¤¤@­Ó¡A¨Ò¦p©³¤Uªºµ{¦¡¡G

szFmt   DB      "%s is %d years old.",0 ;®æ¦¡±±¨î¦r¦ê
szName  DB      "Mary",0                ;¦r¦êÅܼÆ
age     DD      21                      ;¾ã¼ÆÅܼÆ
szStr   DB      40h DUP ("0")           ;½w½Ä°Ï
  ⁝
invoke  sprintf,OFFSET szStr,OFFSET szFmt,OFFSET szName,age

sprintf ªº²Ä¤@­Ó°Ñ¼Æ¬O¥Í¦¨ªº¦r¦êÀx¦s¦ì§}¡A²Ä¤G­Ó°Ñ¼Æ¬O®æ¦¡±±¨î¦r¦ê¦ì§}¡C¥H«áªº°Ñ¼Æ¬OÅܼƦCªí¡A³o¨ÇÅܼƷ|¨Ì§Ç¥X²{¦b®æ¦¡±±¨î¦r¦ê¤¤¡A®æ¦¡±±¨î¦r¦ê¤¤ªº¡u%¡v³£¥Nªí¤@­ÓÅܼơA¨ä«áªº¡us¡v©Î¡ud¡v¥Nªí¸ê®ÆÃþ«¬¡A¤À§O¬O¦r¦ê»P¤Q¶i¦ì¾ã¼Æ¡A§ó¦hªº¸ê®ÆÃþ«¬¥H¤Î§ó¦hªº®æ¦¡µy«á¦A¤¶²Ð¡C

¦X¦b¤@°_¡A¡u%s¡vªí¥Ü¦r¦êÅܼơA´N¬O sprintf ªº²Ä¤T­Ó°Ñ¼Æ¡A¦r¦êÅܼƶ·¥H¸Ó¦r¦êªº¦ì§}¥N´À¾ã­Ó¦r¦ê¡F¡u%d¡vªí¥Ü¾ã¼ÆÅܼơA´N¬O sprintf ªº²Ä¥|­Ó°Ñ¼Æ¡Aage¡C·í sprintf °õ¦æ®É¡A·|§â¨ä«áªº°Ñ¼Æ¦Cªí¤@¤@¥N¤J®æ¦¡±±¨î¦r¦ê¡A¨Ã¥H¨ä­È´O¤J«áÀx¦s©ó½w½Ä°Ï¤º¡A©Ò¥H³Ì«á szStr ·|Åܦ¨¡uMary is 21 years old.¡v¡C©³¤U¤¶²Ð Windows µ{¦¡³]­p¥i¥H¨Ï¥Îªº¬ÛÃö¨ç¦¡¡C

sprintf API »P swprintf API

sprintf »P swprintf ³£¬O¥Î§âÅܼƨ̾ګü©wªº®æ¦¡±±¨î¦r¦ê¥Í¦¨¦r¦ê¡A®t§O¬O«eªÌ¬O¥Î©ó ANSI ¦r¦ê¡A«áªÌ¥Î©ó¼e¦ì¤¸¦r¦ê¡Csprintf »P swprintf ³£¬O C »y¨¥µ{¦¡®w¤¤¤º«Øªº¼Ð·Ç¨ç¦¡¡A©I¥s¥¦­Ì®É¥²¶·­n¤Þ¤J MSVCRT.LIB µ{¦¡®w¡F°£¦¹¤§¥~¡AWinInc ¤¤ªº§t¤JÀɨS¦³«Å§i³o¨â­Ó¨ç¦¡¡A¦]¦¹»Ý¥ý«Å§i¡C¥¦­Ì­ì«¬¥»¨Ó¬O¡G

invoke  sprintf,\
        pszOut,\        ; pointer to buffer for output
        pszFmt,\        ; pointer to format-control string
        variable_list   ; optional variables
invoke  swprintf,\
        pszOut,\        ; pointer to buffer for output
        pszFmt,\        ; pointer to format-control string
        variable_list   ; optional variables

¨ä¤¤ªº²Ä¤@­Ó°Ñ¼Æ¡ApszOut ¬O«ü©w¥Í¦¨ªº¦r¦ê¦s©ñ¦ì§}¡A¤]´N¬O½w½Ä°Ï¦r¦êªº¦ì§}¡F²Ä¤G­Ó°Ñ¼Æ¡ApszFmt ¬O®æ¦¡±±¨î¦r¦êªº¦ì§}¡F±µ¤U¨Ó¬OÅܼƦCªí¡A¦]¬°ÅܼƦCªí¤¤ªºÅܼƨ䣩T©w¡A©Ò¥H¤@¯ë¤]¥i¥H§â³o¨â­Ó¨ç¦¡«Å§i¦¨¤U­±ªº¼Ë¤l¡G

sprintf  PROTO :VARARG
swprintf PROTO :VARARG

®æ¦¡±±¨î¦r¦ê¤º§t®æ¦¡³W½d¡]format specifications¡^¤Î¨ä¥L¤å¦r¡Asprintf ©Î swprintf ·|¨Ì®æ¦¡³W½dªº¶¶§Ç°t¦XÅܼƦCªí¡A³v¤@±NÅܼƩM¦r¦êÂà´«¦Ó¼g¤J½w½Ä°Ï¦r¦ê¡C®æ¦¡³W½d³£¥H¦Ê¤À¤ñ²Å¸¹¡]%¡^¶}©l¡A¨ä¼Ë¤l¦p¤U¡A¨ä¤¤¥H¤@¹ï¤¤¬A¸¹¬A¦íªº¥i¥H¬Ù²¤¡G

%[-][#][0][width][.precision]type
①¡B%¡G®æ¦¡³W½d¶}©l¡C¦pªG­n§â¡u%¡v¦r¤¸¿é¥X¨ì½w½Ä°Ï¡A¥i¥H¥Î¨â­Ó¡u%%¡v¹F¦¨¡C
②¡B-¡G¦b¿é¥X¥kÃä¶ñ¤WªÅ¥Õ¡A¹ï»ô¥ªÃä¡F¦pªG¬Ù²¤«h¥ªÃä¶ñ¤WªÅ¥Õ¡A¹ï»ô¥kÃä¡C
③¡B#¡G¦b½w½Ä°Ï¿é¥X¤Q¤»¶i¦ì®É¡A¦h¥[¡u0X¡v©Î¡u0x¡v¦rÀY¡A¥²¶··f°t type ¬°¡ux¡v©Î¡uX¡v¡C
④¡B0¡G¥¼º¡ªº¼e«×¥H¡u0¡v¶ñº¡¡A¦pªG¬Ù²¤«h¥ÎªÅ¥Õ¶ñº¡¡C
⑤¡Bwidth¡G«ü©w¿é¥X¦Ü½w½Ä°Ïªº¼e«×¡A¥i¥H¶W¹L¤Q¦ì¡C¦pªG®æ¦¡³W½d¥]§t¡u#¡v¡A¦h¥X¨Óªº¡u0X¡v©Î¡u0x¡v¤]¥]§t¦b width ¤º¡A©Ò¥H¹ê»ÚÅã¥Üªº¼Æ­È·|¤Ö¨â®æ¡C
⑤¡B.precision¡G¥Î©óªí¥Ü¯BÂI¼Æ®É¡A¤p¼ÆÂI«á­±ªº¦ì¼Æ¡A¥u¯à»P¡uf¡v·f°t¨Ï¥Î¡C¤p¼ÆÂI«áªº¦ì¼Æ¥H precision «ü©w¡C
⑥¡Btype¡G«ü©w®æ¦¡³W½dªº¸ê®ÆÃþ«¬¡A¥i¥H¬O¤U­±ªº¨ä¤¤¤@ºØ¡A®æ¦¡³W½d¦³°Ï¤À­^¤å¦r¥Àªº¤j¤p¡A¤@©w­n¨Ì·Ó¤U­±©Ò¦C¥Xªº¡G
⑴¡Bc¡G³æ¤@¤@­Ó ANSI ¦r¤¸¡A»P¡uC¡v¬Û¦P¡C
⑵¡BC¡G»P¡uc¡v¬Û¦P¡C
⑶¡Bs¡G¦r¦ê¡A¦bÅܼƦCªí¬Û¹ïÀ³ªºÅܼƤWÀ³¸Ó¶ñ¦r¦ê¦ì§}¡A¨Ã«D¦r¦ê¥»¨­¡C
⑷¡Bd¡G32 ¦ì¤¸¼Æ­ÈÅܦ¨¤Q¶i¦ì¦³¸¹¼Æ¡]½d³ò¬O -2,147,483,648¡ã2,147,483,647¡^¡A»P¡ui¡v¬Û¦P¡C
⑸¡Bi¡G»P¡ud¡v¬Û¦P¡C
⑹¡Bld¡Bli¡G»P¡ud¡v¬Û¦P¡C
⑺¡Bu¡G32 ¦ì¤¸¼Æ­ÈÅܦ¨¤Q¶i¦ìµL¸¹¼Æ¡]½d³ò¬O 0¡ã4,294,967,295¡^¡C
⑻¡Bo¡G32 ¦ì¤¸¼Æ­ÈÅܦ¨¤K¶i¦ìµL¸¹¼Æ¡]½d³ò¬O 0¡ã37,777,777,777¡^¡C
⑼¡Bx¡BX¡G32 ¦ì¤¸¼Æ­ÈÅܦ¨¤Q¤»¶i¦ì¦³¸¹¼Æ¡A¨Ï¥Î x¡Aªí¥Ü¥Î¤p¼gªº¡ua¡ãf¡v¡A¨Ï¥Î X «hÅܦ¨¤j¼gªº¡uA¡ãF¡v¡C
⑽¡BI64d¡G64 ¦ì¤¸¼Æ­ÈÅܦ¨¤Q¶i¦ì¦³¸¹¼Æ¡]½d³ò¬O -9,223,372,036,854,775,808¡ã9,223,372,036,854,775,807¡^¡C
⑾¡BI64u¡G64 ¦ì¤¸¼Æ­ÈÅܦ¨¤Q¶i¦ìµL¸¹¼Æ¡]½d³ò¬O 0¡ã18,446,744,073,709,551,615¡^¡C
⑿¡BI64o¡G64 ¦ì¤¸¼Æ­ÈÅܦ¨¤K¶i¦ì¼Æ¡]½d³ò¬O 0¡ã1,777,777,777,777,777,777,777¡^
⒀¡BI64x¡BI64X¡G64 ¦ì¤¸¼Æ­ÈÅܦ¨¤Q¤»¶i¦ì¼Æ¡AI64x Åܦ¨¤p¼gªº¡ua¡ãf¡v¡AI64X «hÅܦ¨¤j¼gªº¡uA¡ãF¡v¡C
⒁¡Bf¡G64 ¦ì¤¸¯BÂI¼Æ­È¡C¥i¥H¥Î width «ü©wÁ`¼e«×¡Awidth ¥]§t¡u.¡v¡A¦Ó precision «ü©w¤p¼Æ¦ì¼Æªº¼e«×¡C
¥H¤W¬O¦b®æ¦¡±±¨î¦r¦ê©Ò¯à¨Ï¥Îªº type¡C¦pªG type ¬O d¡Bi¡Bld¡Bli¡Bu¡Bo¡Bx¡BX¡A¬Û¹ïÀ³ªºÅܼƥi¥H¬O DWORD ©Î QWORD¡C¦ý¬O¡A¦pªG¬O«áªÌ¡Asprints¡Bswprintf ·|¦Û°Ê©¿²¤°ªÂù¦r²Õ¡C¦pªG type ¬O I64d¡BI64u¡BI64o¡BI64x¡BI64X¡Bf¡A¬Û¹ïÀ³ªºÅܼƤ@©w¬O QWORD¡C

©³¤UÂǵۨҤl»¡©ú®æ¦¡±±¨î¦r¦ê¡B®æ¦¡³W½d¥H¤Î¦p¦ó©I¥s sprintf¡G

szFmt   DB      "%s»¡¡G¡u%d­¼¥H%dµ¥©ó%04d¡A´«ºâ¦¨¤Q¤»¶i¦ì¬O%#06X¡C¡v",0
szName  DB      "§d¦Ñ®v",0
n1      DD      20
n2      DD      37
n3      DQ      20*37
szStr   DB      80h DUP ("0")
 ⁝
invoke  sprintf,OFFSET szStr.OFFSET szFmt,OFFSET szName,n1,n2,n3,n3

°õ¦æ«á szStr ·|Åܦ¨“"§d¦Ñ®v»¡¡G¡u20­¼¥H37µ¥©ó0740¡A´«ºâ¦¨¤Q¤»¶i¦ì¬O0X02E4¡C¡v",0”¡C¦b®æ¦¡±±¨î¦r¦êªº²Ä¤@­Ó®æ¦¡³W½d¬O¡u%s¡v¡Aªí©ú°Ñ¼Æ¦Cªí¤¤ªº²Ä¤@­ÓÅܼƬO¦r¦ê¡A¦r¦ê¥²¶·¥H¦ì§}¥N´À¦r¦ê¡A¥Î OFFSET ¹Bºâ¤l±o¨ì szName ¦ì§}¤Wªº¬O¡u§d¦Ñ®v¡v¡A©Ò¥H²Ä¤@­Ó®æ¦¡³W½d·|¦b szStr ¦r¦ê¤º¶ñ¤J¡u§d¦Ñ®v¡v¡C

²Ä¤G­Ó®æ¦¡³W½d¬O¡u%d¡v¡Aªí¥ÜÅܼƦCªí¤¤ªº²Ä¤G­ÓÅܼƬO 32 ¦ì¤¸¤Q¶i¦ì¼Æ¼Æ­È¡A¸ÓÅÜ¼Æ n1¡A¨ä­È¬° 20¡A·|³Q sprintf Âà´«¦¨¤@¦êªü©Ô§B¼Æ¦rªº¦r¤¸Àx¦s¦b szStr ¦r¦ê¤º¡C¦b°O¾ÐÅ餤³o¦êªü©Ô§B¼Æ¦r¬O¥H ANSI ½s½X¤è¦¡Àx¦s©ó szStr ©Ò¦b°O¾ÐÅ餺¡A¥¦¬O 30h¡B32h¡C²Ä¤T­Ó®æ¦¡³W½d»P²Ä¤G­ÓÃþ¦ü¡A¤£²Ó»¡¡C²Ä¥|­Ó®æ¦¡³W½d¬O¡u%04d¡v¡A¥Nªí¦³¥|¦ì¼Æ¡A¦pªG¤£¨ì¥|¦ì¼Æ¥ª°¼¥H¡u0¡v¶ñº¡¡C²Ä¤­­Ó®æ¦¡³W½d¬O¡u%#06X¡v¡Aªí¥ÜÁ`¦@¦³¤»¦ì¡A¦ý«ü©w¤F¡u#¡v¤Î¡uX¡v¡A©Ò¥H·|¥H¡u0X¡v§@¬°°_ÀY¡A³o¼Ë¦û¥Î¤F¨â¦ì¡A©Ò¥H¹ê»Ú¤W¼Æ­È¥u¦³¥|¦ì¡A¦pªG¤£º¡´N¥Î¡u0¡v±N¥¦¸É¨¬¡A©Ò¥Hµ²ªG¬O¡u0X02E4¡v¡C

wsprintf API

wsprintf ¯à¨Ì¾Ú®æ¦¡±±¨î¦r¦ê²£¥Í¦r¦ê¡A¬O Windows ¤º«Øªº¨ç¦¡¡AWin64 API ªº¤@­û¡A©I¥s®É¥²¶·¤Þ¤J USER32.LIB¡C¸ò¨ä¥L Win64 API ¤@¼Ë¡A¤À¬°¨âºØª©¥»¡GwsprintfA¡BwsprintfW¡A¨Ì§Ç¬O ANSI ª©»P¼e¦r¤¸ª©¡A¨Ì¾Ú¦b­ì©lµ{¦¡¤¤¬O§_´¿«Å§i¡uUNICODE EQU 1¡v©Î¡u__UNICODE__ EQU 1¡v¨M©w¡Cwsprintf ­ì«¬¦p¤U¡G

invoke  wsprintf,\
        pszOut,\        ; pointer to buffer for output
        pszFmt,\        ; pointer to format-control string
        variable_list   ; optional variables

wsprintf »P sprintf¡Bswprintf ªº°Ñ¼Æ¬Û¦P¡A²Ä¤@­Ó°Ñ¼Æ¬O½w½Ä°Ï¦ì§}¡A²Ä¤G­Ó°Ñ¼Æ¬O®æ¦¡±±¨î¦r¦ê¦ì§}¡A²Ä¤T­Ó¤Î¨ä¥H«á³£¬OÅܼƦCªí¡C®æ¦¡±±¨î¦r¦êªº¥Îªk¤]»P sprintf¡Bswprintf ¤j¦P¤p²§¡A©³¤U¦C¥X¤£¦P¤§³B¡G

  1. wsprintf ©ó WinInc ªº¤º§tÀɤ¤ªº WINUSER.INC «Å§i¡A¦Ó¦b WINDOWSINC ·|¦Û¦æ¸ü¤J WINUSER.INC¡F©Ò¥H¤£¶·¦b­ì©lµ{¦¡¤¤«Å§i wsprintf¡A¥u»Ý¥Î INCLUDE °²«ü¥O§t¤J WINDOWS.INC §Y¥i¡C
  2. wsprintf ªº®æ¦¡³W½d¨Ã¨S¦³¡uo¡v¡A¤]¨S¦³¡uI64o¡v¡A¤]´N¬O¤£¯à¿é¥X¤K¶i¦ì¼Æ­È¦r¦ê¡C
  3. wsprintf ªº®æ¦¡³W½d¨Ã¨S¦³¡uf¡v¡A¤]´N¬O¤£¯à¿é¥X¯BÂI¼Æªº¼Æ­È¦r¦ê¡C
  4. ¦pªG®æ¦¡³W½d¤¤«ü©w¡uX¡v©Î¡ux¡v¿é¥X¤Q¤»¶i¦ì¼Æ­È¦r¦ê¡A¦Ó¥B¦P®É¡uwidth¡v¤Î¡u#¡v¡A³o®É­Ôªº width ¨Ã¤£¥]§t¡u0X¡v©Î¡u0x¡v¡C¤]´N¬O»¡¡A«e­±¡u§d¦Ñ®v»¡¡vªº¨Ò¤l¤¤¡A©Ò¦³±ø¥ó¤£ÅÜ¡A¦ý§ï¦¨¡G
    invoke  wsprintf,OFFSET szStr.OFFSET szFmt,OFFSET szName,n1,n2,n3,n3
    µ²ªG¬O“"§d¦Ñ®v»¡¡G¡u20­¼¥H37µ¥©ó0740¡A´«ºâ¦¨¤Q¤»¶i¦ì¬O0X0002E4¡C¡v",0”