²Ä25³¹¡@²L½Í¥¨¶°»P±ø¥ó²ÕĶ

x86 ®a±Úªº CPU ¦Û¥Á°ê 67 ¦~¡]¦è¤¸ 1978 ¦~¡^µo®i¦Ü¤µ¡A¸g¾ú¹L³\¦h¦¸§ï­²¡A²K¥[¤F³\¦h·sªº«ü¥O¡C¦ý¬OÀôÅU¥«­±¤W½Í½×²Õ¦X»y¨¥ªº®ÑÄy¡A©Ò¤¶²Ðªº x86 «ü¥O¤´µM°±¯d¦b·íªì¨î©wªº 8086/8088 «ü¥O¡A¹ï©ó·s²Kªº«ü¥OÁצӤ£½Í¡C¦³¤@ºØ­ì¦]¡A¥i¯à¬O¥L­Ì©Ò¨Ï¥Îªº²ÕĶ¾¹¡AMASM 6.11d ¬O¥Á°ê 84 ¦~µoªíªº¡A¨Ã¤£¤ä´©«á¨Ó·s¥[¤Jªº«ü¥O¡C¦Ó¥L­Ì¤]§OµL¿ï¾Ü¡A¦]¬° MASM 6.11d ¡AÁöµM«Ü¥j¦Ñ¡A¦ý«o¬O·L³n³Ì«á¤@ª©³æ¿W³c°âªº²ÕĶ¾¹¡C

»¡¹ê¦bªº¡A³oªº½T¤]¤£¯à©Ç¥L­Ì¡C¦ý¬O¦³¨S¦³¥i¯à¡A¥i¥H¦bªº MASM 6.11 ²K¥[·sªº«ü¥O¡A¦ÓÅý³o¨Ç·sªº«ü¥O¤]¯à¦b MS¡ÐDOS §@·~¨t²Î¤U²ÕĶ¡B³sµ²¦¨¥\¡A¨Ã¥BÁÙ¯à°õ¦æ¦¨¥\©O¡Hµª®×¬OªÖ©wªº¡A§Ú­Ì¥i¥HÂǥѡu¥¨¶°¡v¥H¤Î¡u±ø¥ó²ÕĶ¡v¡AÅý¤£¤ä´©·s«ü¥Oªº²ÕĶ¾¹¡A¤]¯à¶¶§Q²ÕĶ³o¨Ç·s«ü¥O¡A¤]¯à³sµ²¦¨¥\¡A³Ì«á¤]¥i¥H°õ¦æ¡C§A»¡¡A¬O¤£¬O«Ü©_§®°Ú¡H

¦b³o¤@³¹ùØ­±¡A¤p¤ì°¸´N¥H¦b¥Á°ê 101 ¦~¡]¦è¤¸ 2012 ¦~¡^¤~¦b x86 «ü¥O¶°¤¤·s²K¥[ªº RDRAND ¬°¨Ò¤l¡A¤¶²Ð¦p¦ó¥H¡u¥¨¶°¡v¤Î¡u±ø¥ó²ÕĶ¡v·f°t«e¤@³¹©Ò»¡ªº¡u¾÷±ñ½X¡v¡AÅý MASM 6.11 ¤]¯à¨Ï¥Î RDRAND «ü¥O¡C¦b»¡©ú¤§«e¡A¥ý¤¶²Ð RDRAND «ü¥O¡C

x86 «ü¥O¡GRDRAND

RDRAND ¬O read random¡A¥ç§YŪ¨ú¶Ã¼Æªº·N«ä¡A¥¦¬O±q¤º«Ø©ó´¹¤ù¤¤ªºæi·½¡]entropy source¡^²£¥Í¶Ã¼ÆºØ¤l¡A¦Ó«á¦A¥Ñ¦¹¶Ã¼ÆºØ¤lªì©l¤ÆµwÅé¶Ã¼Æ²£¥Í¾¹¡A¥H¥Í¦¨¶Ã¼Æ¡C³oºØæi·½¥i¥H¨Ì¾Ú¦UºØÀH¾÷©Êªº¨Ó·½¡A¨Ò¦p·L®zªº¹q¤lÂø°T¡B¼öÂø°T¡B©Î¨ä¥L¨Ó¦ÛµwÅ骺¤£½T©w¥Í¦¨¶Ã¼ÆºØ¤l¡A½T«O¥Í¦¨ªº¶Ã¼Æ¬O¨ã¦³¨}¦nÀH¾÷©Êªº¡CRDRAND ªº»yªk¬O¡G

RDRAND  ¼È¦s¾¹

³oùتº¼È¦s¾¹¥i¥H¬O 16¡B32¡B64 ¦ì¤¸ªº³q¥Î¼È¦s¾¹¡A¨Ò¦p RAX¡BEAX¡BAX µ¥µ¥¡C¶Ã¼Æ²£¥Í¾¹·|¨Ì¾Ú¼È¦s¾¹ªº¤j¤p¡A²£¥Í¬Û¹ïÀ³¤j¤pªº¶Ã¼Æ¡A¨Ã¦s©ó¦¹¼È¦s¾¹¤¤¡C¦pªG«e­z¹Lµ{¶¶§Q§¹¦¨¡ACPU ·|³]©w¶i¦ìºX¼Ð¡A§_«h·|²M°£¶i¦ìºX¼Ð¡CÀ³¥Îµ{¦¡À³¸Ó­nÀˬd¶i¦ìºX¼Ð¡A¥H½T«O¥¿½T©Ê¡C


¥¨¶°¡]Macro¡^

¥¨¶°¬O¤@¨t¦C¤å¦r±Ô­z©Î¤@¨Ç«ü¥Oªº¶°¦X¡]¤j³°§â macro ½Ķ¦¨¡u§»¡v¡^¡C¤@¥¹«Å§i¥¨¶°¤§«á¡A´N¥i¥H¦b­ì©lµ{¦¡¤Þ¥Î¦¹¥¨¶°¡C²ÕĶ¾¹¦b²ÕĶ­ì©lµ{¦¡®É´Á¡A¦pªG¹J¨£¤w«Å§i¹Lªº¥¨¶°¡A·|¹w¥ý³B²z¥¨¶°¡A¡u®i¶}¡v¡]expand¡^¦¨­ì¨Óªº°²«ü¥O©Î x86 «ü¥O¡A¦w´¡¦b¤Þ¥Î¥¨¶°ªº¦a¤è¡C³o¼Ë¥u»Ý«Å§i¤@¦¸¥¨¶°¡A´N¯à­«½Æ¦h¦¸¤Þ¥Î¡A¥H¹F¨ìºë²­ì©lµ{¦¡ªº¥Øªº¡C¦pªG¥¨¶°¦A°t¦X±ø¥ó²ÕĶ»P¥¨¶°¹Bºâ¤l¡A¬Æ¦Ü·|¦³·N·Q¤£¨ìªº®ÄªG¡C

¥¨¶°¤À¦¨¤U­±¤­ºØÃþ«¬¡G

  1. ¥¨¶°µ{§Ç¡]macro procedures¡^¡G¥i¥H±µ¨ü°Ñ¼Æ¡A¦b¤Þ¥Îªº¦a¤è®i¶}¬°¤@¨Ç«ü¥O¡C
  2. ¥¨¶°¨ç¦¡¡]macro functions¡^¡GÃþ¦ü¥¨¶°µ{§Ç¡A¤£¦Pªº¬O¥¨¶°¨ç¦¡µ²§ô®É¦³¦^¶Ç­È¡C
  3. ¤å¦r¥¨¶°¡]text macro¡^¡G¥i¦b­ì©lµ{¦¡¤¤®i¶}¬°­ì¨Óªº¤å¦r¡C
  4. ¹w¥ý©w¸qªº¥¨¶°¨ç¦¡©M¦r¦ê°²«ü¥O¡]predefined macro functions and string directives¡^¡G¥Î©ó³B²z¦r¦ê¡C
  5. ­«½Æ°Ï¶ô¡]repeat blocks¡^¡G¥i¥H®Ú¾Ú«ü©wªº¦¸¼Æ©Î±ø¥ó­«½Æ¦h¦¸¡C

¦b¶}©l¤¶²Ð¥¨¶°¤§«e¡A­n¥ý»¡©ú¨Ï¥Î¥¨¶°ªº³N»y¡C¦b MASM 6.1 ¤â¥U¤¤¡A¨Ï¥Î¥¨¶°ªº¤è¦¡ºÙ¬°¡u©I¥s¡v¡A¦Ó¦b³o­Óºô­¶¤¤¡A§ï¦¨¡u¤Þ¥Î¡v¡A­ì¦]¬O¬°¤FÁקK»P°Æµ{¦¡²V²c¡C¥¨¶°»P°Æµ{¦¡³£¯àºë²­ì©lµ{¦¡¡A¦ý¨âªÌ¨Ã¤£¬Û¦P¡C²ÕĶ¾¹²ÕĶ­ì©lµ{¦¡¤§«á¡A¹ï°Æµ{¦¡¥u·|²£¥Í¤@¥÷¾÷±ñ½X¡A¨C·í¥Dµ{¦¡©I¥s°Æµ{¦¡®É¡A³£·|¸õÅD¨ì°Æµ{¦¡©Ò¦b¤§³B°õ¦æ¡Aµ¥°Æµ{¦¡°õ¦æ§¹²¦¦A¸õ¦^­ì¨Ó¦a¤è¡AÄ~Äò¤U­±ªºµ{¦¡¡C¦ý¬O²ÕĶ¾¹¹ï¥¨¶°«o¤£¬O³o¼Ë¡A¨C¦¸¨Ï¥Î¥¨¶°®É¡A³£·|²£¥Í¤@¥÷¾÷±ñ½X¡A¨ú¥N¨Ï¥Î¥¨¶°ªº¦a¤è¡A§Y¨Ï¬O¨Ï¥Î¦P¤@­Ó¥¨¶°¡C¦Ó·íµ{¦¡°õ¦æ¨ì¥¨¶°®É¡A¤]´N¨Ì·Ó¶¶§Ç°õ¦æ¡A¤£·|µo¥Í¸õÅDªº±¡§Î¡C¦]¦¹ÁöµM MASM 6.1 ¤â¥U¤WºÙ¨Ï¥Î¥¨¶°¬°©I¥s¥¨¶°¡A¦ý¦b³o­Óºô­¶¤¤¡A§ï¦¨¡u¤Þ¥Î¡v¥¨¶°¡C

³o¤@³¹¥u·|´£¨ì»PÅý MASM 6.11 ¯à¨Ï¥Î RDRAND «ü¥O¦³Ãöªº¥¨¶°¡C¦]¦¹ÁöµM¥¨¶°¤À¦¨¤­ºØÃþ«¬¡A¦ý¨Ã¤£·|³£¤¶²Ð¡C¦pªG·QÁA¸Ñ¨ä¥LÃþ«¬¡A©Î¦b¥»³¹¤¤»y²j¤£¸Ôªº¥¨¶°¥Îªk¡A¥i¥H°Ñ¾\ Win64 ²Õ¦X»y¨¥ªº²Ä¤­³¹»P²Ä¤»³¹¡A³o¨â³¹¦³¸û§¹¾ãªº¤¶²Ð¡C


¥¨¶°µ{§Ç¡]Macro Procedures¡^

¥ý¤¶²Ð³Ì²³æ¤]¬O³Ì±`¥Îªº¥¨¶°¡Ð¡Ð¥¨¶°µ{§Ç¡C¦]¬°¥¦¤Ó±`¥Î¤F¡A©Ò¥H¦³®É­Ô¥¨¶°µ{§Ç¤]³QºÙ¬°¥¨¶°¡A·íµM³o«Ü®e©ö²V²c¡A¦³®É¥²¶·¥Ñ¤W¤U¤å¤~¯à¤À±o²M·¡¡C

©w¸q¥¨¶°µ{§Ç¡GMACRO/ENDM °²«ü¥O

¦b­ì©lµ{¦¡¤¤©w¸q¥¨¶°µ{§Çªº¤èªk¬O¨Ï¥Î MACRO/ENDM °²«ü¥O¡A»yªk¦p¤U¡G

¥¨¶°¦WºÙ    MACRO   °Ñ¼Æ¦Cªí
           ±Ô­z
ENDM

¥¨¶°µ{§Çªº§Î¦¡¦p¤W¡A©³¤U¥²¶·¦A§ó¶i¤@¨B»¡©ú¡G

  1. ¤W­±ªº¡u±Ô­z¡v©Ò¦b¤§³B¡A¥Î¦h¹D x86 «ü¥O©Î¬O°²«ü¥O¨ú¥N¡A³o¨Ç´N¬O¥¨¶°¤º®e¡C¤]´N¬O»¡¡A¥¨¶°¤º®e¥²¶·§¨¦b MACRO »P ENDM ¤§¶¡¡C
  2. ¥¨¶°µ²§ôªº¦a¤è¥u»Ý­n¥Î¡uENDM¡v§Y¥i¡A¤£»Ý­n¼g¥X¥¨¶°¦WºÙ¡A¨ä¤¤ªº M¡AÅãµM´N¬O MACRO ªº·N«ä¡C
  3. ¦b MACRO ¤§«áªº¬O°Ñ¼Æ¦Cªí¡A¦pªG¥¨¶°¦³³\¦h°Ñ¼Æªº¸Ü¡A¨C­Ó°Ñ¼Æ¤§¶¡¥H¡u,¡v¹j¶}¡C¥¨¶°ªº°Ñ¼Æ¥u¯à¦b¥¨¶°¤º®e¨Ï¥Î¡A¨ä¥L¦a¤èµL®Ä¡C
  4. ¥¨¶°ªº°Ñ¼Æ¦b¥¨¶°¤¤¡AµLªk§ïÅܨä­È¡C¦pªG¤@©w­n§ïÅÜ¡A¥i¥H³]¤@­ÓÅܼƤ~¨ú¥N°Ñ¼Æ¡C
  5. ­n¤Þ¥Î¥¨¶°®É¡A¥u»Ý­n¼g¤W¥¨¶°¦WºÙ¡A¨ä«á±µ¤W¤Þ¼Æ§Y¥i¡]¤Þ¼Æ¬O¤°»ò¡A½Ð°Ñ¦Ò¡uWin64 ²Õ¦X»y¨¥²Ä¤@³¹¡v¡^¡C

²{¦b¥i¥H¨Ó¸Õ¸Õ¬Ý¥¨¶°¦p¦óºë²­ì©lµ{¦¡¤F¡C¦b²Ä¥|³¹¡A¤¶²Ð¤F¤@­Ó HELLOW1.ASM µ{¦¡¡A¨ä­ì©lµ{¦¡¦p¤U¡G

.MODEL  SMALL,C
.386
.STACK
;***********************************************************
.DATA
msg     DB      "Hellow, World.$"
;***********************************************************
.CODE
        .STARTUP
        mov     dx,OFFSET msg
        mov     ah,9
        int     21h
        .EXIT   0
;***********************************************************
END

HELLOW1.ASM ©I¥s¤F¨â¦¸ DOS ªA°Èµ{¦¡¡G①²Ä¤@¦¸¬O©I¥s¦L¥X¦r¦êªº AH¡×09H/INT 21¡B②²Ä¤G¦¸©I¥s¬O AH¡×4CH/INT 21¡A¦ý¤w¸g²¤Æ¦¨¡u.EXIT 0¡v°²«ü¥O¤F¡A´N¤£¥²¦A¦h¨Æ¤F¡C¦]¦¹§âª`·N¤O¶°¤¤¦b¦p¦óºë² AH¡×09H/INT 21¡A³oùØ©Ò»¡ªººë²¨Ã«Dºë² DOS ¤º³¡¦³Ãö¦¹¤¤Â_ªºµ{¦¡½X¡A¦Ó¬Oºë²­ì©lµ{¦¡¡C°²³]·Q±N AH¡×09H/INT 21 ºë²¦¨Ãþ¦ü°ª¶¥»y¨¥ªº¡udisplay ¦r¦ê¡v³o¼Ëªº«ü¥O¡A¨º»ò display ¥¨¶°¥i¥H¹³©³¤UÂŦâ®Ø¤ºªº³o¼Ë¼g¡G

display MACRO   string          ;;¥¨¶°¶}©l
        LOCAL   temp            ;;±Ntemp³]¬°°Ï°ì©Êªº
.DATA
temp    DB      string,"$"      ;;¦b°Ñ¼Æ string ¤§«á¥[¤W $
.CODE                           ;;¦r¤¸¡A°µ¬°¦r¦êµ²§ô
        mov     ah,9
        mov     dx,OFFSET temp
        int     21h
ENDM                            ;;¥¨¶°µ²§ô

§â¤W­±ÂŦâ®Øªº¤º®e¡A¥H¯Â¤å¦rÀɪº®æ¦¡Àx¦s¦b¡uE:\DOS\MACRO\DOSCALL.INC¡vÀÉ®×ùØ¡C¦p¦¹¤@¨Ó¡A¤£¶È¥»³¹ªºµ{¦¡¥i¥H¨Ï¥Î display ¥¨¶°¡A¥H«áªºµ{¦¡¤]¥i¥H¨Ï¥Î¡A¥u­n¦b­ì©lµ{¦¡¤º¶}©l¤£¤[¡A±N¡uDOSCALL.INC¡v§t¬A¶i¨Ó§Y¥i¡C

­n§â¬Y­Ó¯Â¤å¦rÀɧt¬A¶i­ì©lµ{¦¡¤¤¡A¥²¶·¨Ï¥Î¡uINCLUDE¡v°²«ü¥O¡A¥¦ªº§@¥Î¬Û·í©ó§â¡uINCLUDE¡v¤§«á©Ò±µªº¯Â¤å¦rÀÉ¡A¨ú¥N¾ã±ø¡uINCLUDE¡v°²«ü¥O¡AÅܦ¨­ì©lµ{¦¡ªº¤@³¡¤À¡C¦³Ãö INCLUDE ªº¥Îªk¡A½Ð°Ñ¾\µù¤@¡C¹³³oºØ³Q INCLUDE §t¬A¶i¨ÓªºÀɮ׺٬°¡u¥]§tÀÉ¡v¡C

³o¼Ë­ì©lµ{¦¡´N´X¥G¼g¦¨¤F¡A¦ý¬O³o¼Ë¤S¶û¤Ó²³æ¤F¡A©ó¬O¦A¥[¤WÅã¥Ü¥t¤@­Ó¦r¦ê¡A´NÅܦ¨©³¤Uªº¼Ë¤l¡A±N¥¦¦s©ó¡uE:\DOS\MACRO\HELLOW3.ASM¡v¡G

1
2
3
4
5
6
7
8
9
10
11
12
13
14
.MODEL  SMALL,C
.386

INCLUDE DOSCALL.INC     ;±NDOSCALL.INC§t¬A¶i¨Ó
;*************************************************
.STACK
;*************************************************
.CODE
        .STARTUP
        display <"Hellow, World.",0dh,0ah>
        display "I love assembly language!"
        .EXIT   0
;*************************************************
END

¤W­±ªº­ì©lµ{¦¡¬O¤£¬O«Ü²³æ¡A¬Ý°_¨Ó¤@ÂI¨à³£¤£¹³¬O²Õ¦X»y¨¥¡A¦ý¥¦«o¯uªº¯à²ÕĶ¡B³sµ²¡A¨Ã¥B¤]¯à¶¶§Q°õ¦æ¦¨¥\¡C¨Ì¤U­±¤è¦¡²ÕĶ¡G

E:\DOS\MACRO>ml /Fl hellow3.asm [Enter] ¡÷¿é¤J¡u/Fl¡v¿ï¶µ¥H»s§@¦CªíÀÉ
Microsoft (R) Macro Assembler Version 6.11
Copyright (C) Microsoft Corp 1981-1993.  All rights reserved.

 Assembling: hellow3.asm

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

Object Modules [.obj]: hellow3.obj 
Run File [hellow3.exe]: "hellow3.exe"
List File [nul.map]: NUL
Libraries [.lib]: 
Definitions File [nul.def]:

E:\DOS\MACRO>hellow3 [Enter]
Hellow, World.  ¡÷°õ¦æ¦¨¥\
I love assembly language!
E:\DOS\MACRO>

¬Ý¡I¥i¥H¥¿½T°õ¦æ¡I³o­Óµ{¦¡ÁöµM²³æ¡A¦ý«o¦³³\¦h­È±o»¡ªº¥DÃD¡C¥ý»¡³Ì²³æªº³¡¤À¡C

¥¨¶°ªº±M¥Îµù¸Ñ¡G;;

¦b¥¨¶°¤º¤]¯à¥[¤Wµù¸Ñ¡A¥¨¶°ªºµù¸Ñ¥i¥H¥Î¡u;¡v©Î¡u;;¡v¡C²ÕĶ¾¹³£·|©¿²¤±¼¦b¡u;¡v©Î¡u;;¡v¤§«áªº¤å¦r¡A¦]¦¹¥i¥H¥Î¥¦­Ì§@¬°µù¸Ñªº°_ÀY¡C¡u;¡v»P¡u;;¡vªº®t§O¦b©ó®i¶}¥¨¶°®É¡A¥H¡u;¡v¬°°_ÀYªºµù¸Ñ·|¦C¦b¦CªíÀɸ̭±¡F¦Ó¥H¡u;;¡v¬°°_ÀYªº¤£·|¡A´NÅã±o¤£¨º»òÅo¶Û¡C

­è­è´£¨ì¡u®i¶}¥¨¶°¡v¡A¦b¥»³¹ªº¤@¶}©l´£¨ì¥¨¶°¤À¦¨¤­­ÓÃþ«¬¤§³B¡A¤]´£¹L¡u®i¶}¡v¡A³o¨ì©³¬O¤°»ò©O¡H

®i¶}¥¨¶°¡]Expand Macro¡^

¦b­ì©lµ{¦¡¤¤¡A¦pªG¦³©w¸q¥¨¶°©Î¬O¤Þ¤J¦³¥¨¶°ªº¥]§tÀÉ¡A¨º»ò¦b²ÕĶ®É´Á¹J¨ì¥¨¶°¡A´N·|±N¥¨¶°¦WºÙ¤§«áªº¤Þ¼Æ¤@¤@¥N¤J¨ì¥¨¶°¤ºªº°Ñ¼Æ¤¤¡A¦pªG¦³¨ä¥L«ü¥O¤]·|¤@¨Ö³B²z¡AµM«á±N³o¨Ç³B²z¹Lªºµ{¦¡½X´¡¤J­ì¥ý¤Þ¥Î¥¨¶°ªº¦a¤è¡C¨Ò¦p¦b HELLOW3.ASM ¤¤²Ä 10 ¦æ¤Þ¥Î¤F display ¥¨¶°¡AML.EXE ´N·|¥H¡u<"Hellow, World.",0dh,0ah>¡v¥N¤J string ¤¤¡A©ó¬O´N²£¥Í¦p¤Uªºµ{¦¡½X¡G

        LOCAL   temp           ;;±Ntemp³]¬°°Ï°ì©Êªº
.DATA
temp    DB      "Hellow, World.",0dh,0ah,"$"    ;;¦b°Ñ¼Æ string ¤§«á¥[¤W $
.CODE                                           ;;¦r¤¸¡A°µ¬°¦r¦êµ²§ô
        mov     ah,9
        mov     dx,OFFSET temp
        int     21h

³o¨Çµ{¦¡½X·|³Q ML.EXE ¦w´¡¦b¤Þ¥Î display ¥¨¶°ªº¦a¤è¡A¤]´N¬O¦w´¡¦b²Ä 10 ¦æ¡C¦Ó²Ä 11 ¦æ¤]¤Þ¥Î display ¥¨¶°¡A¤]¤ñ·Ó¿ì²z¡C¤U­±§â­ì©lµ{¦¡»P¦CªíÀɦC¥X¨Ó¡A´N¤@¥ØÁAµM¤F¡C

¬Ý©³¤U HELLOW3.ASM »P HELLOW3.LST ªº¤ñ¸û´N·|µo²{¡A¦b­ì©lµ{¦¡ªº¡uINCLUDE DOSCALL.INC¡v¤§«á´N¬O°ïÅ|°Ï¬q¡A¦Ó¦b¦CªíÀÉ¡uINCLUDE DOSCALL.INC¡v¤§«á¡A«o¬O DOSCALL.INC ªº©Ò¦³¤º®e¡A¨Ã¦b«e­±¥[¤W¡uC¡v¡C¦P¼Ë¦b­ì©lµ{¦¡¡udisplay <"Hellow, World.",0dh,0ah>¡v¤§«á¬O¨ä¥L«ü¥O¡A¦b¦CªíÀɤ¤«o¬O display ¥¨¶°ªº¤º®e¡A¦ý¨C¤@¦æ«e¥[¤W¡u1¡v¡A¨Ã¥B°Ñ¼Æ string ³Q¤Þ¼Æ¡u"Hellow, World.",0dh,0ah¡v©Ò¨ú¥N¡C¹³³o¼Ëªº¹Lµ{´NºÙ¬°¡u®i¶}¥¨¶°¡v¡C

HELLOW3.ASMHELLOW3.LST






.MODEL SMALL,C .386 INCLUDE DOSCALL.INC ;±NDOSCALL.INC§t¬A¶i¨Ó ;************************************************* .STACK ;************************************************* .CODE .STARTUP display <"Hellow, World.",0dh,0ah> display "I love assembly language!" .EXIT 0 ;************************************************* END
Microsoft (R) Macro Assembler Version 6.11                    10/08/23 13:58:39
hellow3.asm                                                   Page 1 - 1


                                .MODEL  SMALL,C
                                .386

                                INCLUDE DOSCALL.INC     ;±NDOSCALL.INC§t¬A¶i¨Ó
                              C display MACRO   string          ;;¥¨¶°¶}©l
                              C         LOCAL   temp            ;;±Ntemp³]¬°°Ï°ì©Êªº
                              C .DATA
                              C temp    DB      string,"$"      ;;¦b°Ñ¼Æstring¤§«á¥[¤W$
                              C .CODE                           ;;¦r¤¸¡A°µ¬°¦r¦êµ²§ô
                              C         mov     ah,9
                              C         mov     dx,OFFSET temp
                              C         int     21h
                              C ENDM                            ;;¥¨¶°µ²§ô
                                ;*************************************************
                                .STACK
                                ;*************************************************
 0000                           .CODE
                                        .STARTUP
                                        display <"Hellow, World.",0dh,0ah>
 0000                         1 .DATA
 0000 48 65 6C 6C 6F 77       1 ??0000  DB      "Hellow, World.",0dh,0ah,"$"      
       2C 20 57 6F 72 6C
       64 2E 0D 0A 24
 0010                         1 .CODE                           
 0010  B4 09                  1         mov     ah,9
 0012  BA 0000 R              1         mov     dx,OFFSET ??0000
 0015  CD 21                  1         int     21h
                                        display "I love assembly language!"
 0011                         1 .DATA
 0011 49 20 6C 6F 76 65       1 ??0001  DB      "I love assembly language!","$"      
       20 61 73 73 65 6D
       62 6C 79 20 6C 61
       6E 67 75 61 67 65
       21 24
 0017                         1 .CODE                           
 0017  B4 09                  1         mov     ah,9
 0019  BA 0011 R              1         mov     dx,OFFSET ??0001
 001C  CD 21                  1         int     21h
                                        .EXIT   0
                                ;*************************************************
                                END
Microsoft (R) Macro Assembler Version 6.11                    10/08/23 13:58:39
hellow3.asm                                                   Symbols 2 - 1



Macros:

                N a m e                 Type

display  . . . . . . . . . . . .        Proc


Segments and Groups:

                N a m e                 Size     Length   Align   Combine Class

DGROUP . . . . . . . . . . . . .        GROUP
_DATA  . . . . . . . . . . . . .        16 Bit   002B     Word    Public  'DATA'
STACK  . . . . . . . . . . . . .        16 Bit   0400     Para    Stack   'STACK'
_TEXT  . . . . . . . . . . . . .        16 Bit   0023     Word    Public  'CODE'


Symbols:

                N a m e                 Type     Value    Attr

??0000 . . . . . . . . . . . . .        Byte     0000     _DATA
??0001 . . . . . . . . . . . . .        Byte     0011     _DATA
@CodeSize  . . . . . . . . . . .        Number   0000h
@DataSize  . . . . . . . . . . .        Number   0000h
@Interface . . . . . . . . . . .        Number   0001h
@Model . . . . . . . . . . . . .        Number   0002h
@Startup . . . . . . . . . . . .        L Near   0000     _TEXT
@code  . . . . . . . . . . . . .        Text     _TEXT
@data  . . . . . . . . . . . . .        Text     DGROUP
@fardata?  . . . . . . . . . . .        Text     FAR_BSS
@fardata . . . . . . . . . . . .        Text     FAR_DATA
@stack . . . . . . . . . . . . .        Text     DGROUP

           0 Warnings
           0 Errors

®i¶}¤§«áªº¥¨¶°¡A·|¶i¤@¨B³Q²ÕĶ¾¹²ÕĶ¡AµM«á¦b¼g¤J¥ØªºÀɤ¤¡A³Ì«á¥Ñ³sµ²¾¹Âà¤Æ¦¨¥i°õ¦æÀÉ¡C¦³Ãö HELLOW3.ASM µ{¦¡ÁÙ¦³´X­Ó¦³½ìªº¦a¤è¡A¥i¥H½Í¤@½Í¡C³o´X­Ó¦a¤è¬O①¤å¦r¤À¹j¹Bºâ¤l¡B②°Ï¬qªº±Æ¦C¡C

¤å¦r¤À¹j¹Bºâ¤l¡G< >

¤@¯ë±N¡u< >¡vºÙ¬°¤å¦r¤À¹j¹Bºâ¤l¡A¦b³o¹ï¡u< >¡v¤§¶¡ªº¤å¦r¡A§Y¨Ï¦³¤À¹j²Å¸¹¡A¹³ªÅ¥Õ¡B³r¸¹ ( , )¡B¤Þ¸¹ ( " )¡B¤À¸¹ ( ; )¡K¡Kµ¥¡A³£·|¥Ñ©ó¤å¦r¤À¹j¹Bºâ¤lªºÃö«Y¡A¦Ó§â³o¨Ç¤À¹j²Å¸¹µø¬°¤@¯ë¦r¤¸¡A¨Ï¾ã¬q¤å¦rÅܬ°¤@­Ó¦r¦ê¡C

¦pªG¦b HELLOW3.ASM ªº²Ä 10 ¦æ§ï¦¨¹³¤U­±ªº¼Ë¤l¡G

        display "Hellow, World.",0dh,0ah

¨º»ò ML.EXE ´N·|§i¶D§A¡Aµo¥Í¿ù»~¡A¦]¬°°Ñ¼Æ¤Ó¦h¤F¡C²z¥Ñ«Ü²³æ¡A¤W­±¤Þ¥Î display ªº¤è¦¡¡A¨C­Ó¡u,¡v³£¬O¤À¹j²Å¸¹¡A©Ò¥HÁ`¦@¦³¤T­Ó°Ñ¼Æ¡C¥²¶·¹³¤U­±¤è¦¡¤~¬O¥¿½Tªº¡G

        display <"Hellow, World.",0dh,0ah>

³o¼Ë¡Adisplay ´N·|±N¤W­±¤À¶}ªº¤T³¡¤À¡A¬Ý¦¨¬O¤@­Ó¦r¦ê¡C

¥æ¿ùªº°Ï¬q¡H

¦b HELLOW3.ASM ¤¤¤Þ¥Î¤F display ¥¨¶°¨â¦¸¡A¥Ñ¦CªíÀɬݰ_¨Óµ{¦¡½X°Ï¬q»P¸ê®Æ°Ï¬q¦ü¥G¥æ¿ùµÛ¤À¥¬¡A¦ý¨ä¹ê¯u¥¿¸ü¤J¨ì°O¾ÐÅ餧«á¡A«o¤£¬O¦p¦¹¡C

³o¬O¦]¬° HELLOW3.ASM ¦b«Å§i°Ï¬q®É¡A±Ä¥Î²©ö¤è¦¡¡C¥H²©ö¤è¦¡«Å§i®É¡A¨Ò¦p .CODE¡B.DATA¡A°Ï¬q¿ï¶µ¤¤ªº¦X¨Ö§Î¦¡¡]combine¡^§¡·|³]©w¬°¤º©w­È¡A¦¹¤º©w­È´N¬O PUBLIC¡A¦Ó PUBLIC ·|¨Ï±o¨ã¦³¬Û¦P¦WºÙ¥B¬Û¦PÃþ§O¦Wªº°Ï¬q¦X¨Ö¦¨¤@­Ó°Ï¬q¡C

¨Ò¦p¦b SMALL ¼Ò¦¡¤U¡A¥H¡u.CODE¡v¤è¦¡«Å§iµ{¦¡½X°Ï¬q¡A¨ä°Ï¬q¦WºÙ§¡¬°¡u_TEXT¡v¡A¦ÓÃþ§O¦WºÙ§¡¬O¡u"CODE"¡v¡A¦]¦¹ÁöµMµ{¦¡½X°Ï¬q¬Ý¦ü¤À¦¨¤T³¡¤À¡A¦ý¹ê«h¦X¨Ö¦b¤@°_¡C¸ê®Æ°Ï¬q¤]¬O¤@¼Ë¡C¦b SMALL ¼Ò¦¡¤U¡A¥H¡u.DATA¡v¤è¦¡«Å§i¸ê®Æ°Ï¬q¡A¨ä°Ï¬q¦WºÙ§¡¬°¡u_DATA¡v¡A¦ÓÃþ§O¦WºÙ¬O¬O¡u"DATA"¡v¡A©Ò¥H¤]¤@¼Ë·|¦X¨Ö¦b¤@°_¡C¦pªG§A¥Î°£¿ù¾¹¸ü¤JÆ[¹î¡A¤]¯àÃÒ¹ê³o¤@ÂI¡C

LOCAL °²«ü¥O

°²¦p¬Y­Ó²Å¸¹ ( ¥]§tÅܼơB¼Ð°O¡K¡K) ¥u¦³¦b¬Y­Ó¥¨¶°¤¤¨Ï¥Î¨ì¡A¨º»ò¥i¥H±N¦¹²Å¸¹³]¬°°Ï°ìªº¡C§â²Å¸¹³]¬°°Ï°ìªº¤èªk¬O¨Ï¥Î LOCAL °²«ü¥O¡A¥¦ªº»yªk¬O

LOCAL  ²Å¸¹¦WºÙ¦Cªí

­nª`·Nªº¬O¡ALOCAL ¥²¶·ºò±µµÛ¦b MACRO ¤U¤@¦æ¡A°£«D¨â¦æ¤§¶¡¬Oµù¸Ñ¦æ¡C¥t¥~¦b¥¨¶°¤¤«Å§i¬Y¨Ç²Å¸¹¬O°Ï°ì©Êªº¡A»P¦b°Æµ{¦¡¤¤«Å§i°Ï°ìÅܼơAÁöµM³£¬O¨Ï¥Î LOCAL¡A¦ý¬O¨âªÌ·N¸q§¹¥þ¤£¦P¡C°Ï¤À¤è¦¡«Ü²³æ¡A«eªÌ¬Oºò±µµÛ MACRO ¤§«á¡F«áªÌºò±µµÛ PROC ¤§«á¡C¦³Ãö¦b°Æµ{¦¡¤¤ªº°Ï°ìÅܼơA½Ð°Ñ¾\²Ä¤E³¹°Ï°ìÅܼơC

¦b¥¨¶°¤¤¡A«Å§i¬Y­Ó²Å¸¹¬O°Ï°ì©Ê«á¡A¨C¦¸¤Þ¥Î¦¹¥¨¶°®É¡A²ÕĶ¾¹·|¦Û°Ê¬°¤w«Å§i¹Lªº°Ï°ì©Ê²Å¸¹²£¥Í·sªº¦WºÙ¡C³o­Ó·sªº²Å¸¹¦WºÙ¤~¬O¦¹°Ï°ìÅܼƯu¥¿ªº¦WºÙ¡A¨ä®æ¦¡¬O¡u??XXXX¡v¡A¨ä¤¤ªº XXXX ¬O±q¹s¶}©lªº¤Q¤»¶i¦ì¼Æ¡C¦]¬°³o¼Ëªº½t¬G¡A©Ò¥Hªí­±¤W¬Ý°_¨Ó¡A¯à¹F¨ì¨Ï²Å¸¹Åܦ¨°Ï°ì©Êªº¥Øªº¡C¦ý¬Oª¾¹Dªº³o¼Ëªº©R¦W³W«h¤§«á¡A´N¥i¥H¥Ñ¥¨¶°¥H¥~ªº¦a¤è¦s¨ú³o¼ËªºÅܼơA©Î¬O¸õÅD¦Ü³o¼Ëªº¼Ð°O³B¡C

¦b HELLOW3.ASM ¤¤ªº display ¥¨¶°¤¤«Å§i¤F¦r¦êÅÜ¼Æ temp §@¬°°Ï°ìÅܼơC·í²Ä¤@¦¸¤Þ¥Î display ®É¡Atemp ¦r¦êÅܼƯu¥¿ªº¦WºÙ¬O ??0000¡F²Ä¤G¦¹¤Þ¥Î®É¡A¯u¥¿ªº¦WºÙ¬O ??0001¡C³o¤@ÂI¯à°÷±q¦CªíÀɤ¤¬Ý¥X¨Ó¡C

¥¨¶°¤¤ªºÅܼÆ

¦b¥¨¶°¤º³¡¡A§K¤£¤F­n¹ï¼Æ­È©Î¬O¦r¦ê°µ¹Bºâ¡A¦]¦¹¦³®É¥²¶·¦b¥¨¶°¤º«Å§iÅܼơC³o¨ÇÅܼưϤÀ¦¨¨âÃþ¡G¼Æ­ÈÅܼƻP¦r¦êÅܼơC¼Æ­ÈÅܼƥi¥H¥Î EQU ©Î = °²«ü¥O«Å§i¡A®t§O¦b©ó¥H«eªÌ«Å§i¤§«áµLªk§ó§ï¨ä¼Æ­È¡F«áªÌ¥i¥H¡C©Ò¥HÄY®æ¨Ó»¡¡AEQU «Å§i±`¼Æ¡A= «Å§iÅܼơA¥¦­Ìªº»yªk¬O¡G

²Å¸¹    EQU     ºâ³N¹Bºâ¦¡
²Å¸¹    =       ºâ³N¹Bºâ¦¡

¨ä¤¤ªº²Å¸¹´N¬OÅܼƦWºÙ©Î±`¼Æ¦WºÙ¡Fºâ³N¹Bºâ¦¡¬O«ü¥i¥H¬O¥Îºâ³N­pºâªº¼Æ¾Ç¦¡¤l¡A¨ä¹Bºâ¤¸À³¸Ó³£¬O¼Æ­È©Î¤w«Å§i¹LªºÅܼơC¥H³o¨âºØ¤è¦¡«Å§iªº²Å¸¹¡A¥u¦³¦b²ÕĶ®É´Á¦³®Ä¡A¦Ó¤£¬O¦b°õ¦æ®É´Á¡C

¦r¦êÅܼƪº«Å§i¤èªk¬O¥Î EQU ©Î TEXTEQU¡A»yªk¦p¤U¡G

²Å¸¹    EQU     <¦r¦ê>
²Å¸¹    TEXTEQU <¦r¦ê>

¤£ºÞ¥Î EQU ÁÙ¬O TEXTEQU «Å§iªº¦r¦ê¡A³£¯à§ó§ïÅܦ¨¥t¤@­Ó¦r¦ê¡A®t§O¬O TEXTEQU ¯à·f°t ECHO °²«ü¥O¤Î¥¨¶°¹Bºâ¤l°µ¹Bºâ¡A¦Ó EQU ¤£¯à¡C¦³Ãö TEXTEQU »P ECHO ªº¥\¯àÁÙ¤£¥u«Å§i¦r¦ê¡AÁÙ¦³³\¦h¡A½Ð°Ñ¦Ò Win64 ²Õ¦X»y¨¥²Ä¤­³¹¤å¦r¥¨¶°¡C


­«½Æ°Ï¶ô

MASM ¥i¨Ï¥Îªº­«½Æ°Ï¶ô¦³¡G①WHILE/ENDM¡B②REPEAT/ENDM¡B③FOR/ENDM¡B④FORC/ENDM¡A¦@¥|ºØ¡A¤£¹L¦b³o¤@³¹¡A¤p¤ì°¸¥u¥´ºâ¤¶²Ð³o¤@³¹·|¥Î±o着ªº²Ä①¤Î③¨âºØ¡A¨ä¾lªº¥i°Ñ¾\ Win64 ²Õ¦X»y¨¥²Ä¤»³¹­«½Æ°Ï¶ô¡C

WHILE/ENDM ­«½Æ°Ï¶ô

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¨Ò¦p©³¤Uªº¨Ò¤l¬O·í x ¤p©ó 25 ¥B y ¤p©ó 80 ¤~·|°õ¦æ­«½Æ°Ï¶ôªºµ{¦¡½X¡G

WHILE ( x LT 80 ) AND ( y LT 25 )
⁝
ENDM

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

Á|­Ó¨Ò¤l¨Ó»¡©ú WHILE/ENDW ªº¥Îªk¡C°²³]¦b­ì©lµ{¦¡½X¤¤­n³]¸m¤@­Ó°}¦C¡A³o­Ó°}¦C¬O±q 1 ¶}©l¡AµM«á¬O 3¡B5¡B7¡B9¡K¡K199¡A¦@ 100 ­Ó©_¼Æ²Õ¦¨ªº°}¦C¡A­Y­n¤@­Ó¤@­Ó¿é¤J¡A«D±`³Â·Ð¡A¥i¥H¥Î WHILE/ENDM ­«½Æ°Ï¶ô¡A¦p¤U­±µ{¦¡½X¡G

        d=2             ;;¤½®t
        an=1            ;;²Ä n ¶µ¡A³Ì¥ýªº¬O­º¶µ
        n=100           ;;¦@ 100 ¶µ
odd_number      LABEL   WORD
WHILE   n
        DW      an      ;;©w¸q²Ä n ¶µ
        an=an+d         ;;¤U¤@¶µ¬°«e¤@¶µ¥[¤½®t
        n=n-1           ;;¶µ¼Æ¤Ö¤@
ENDM

­n¤Þ¥Î¦¹­«½Æ°Ï¶ô®É¡A¥u»Ý±N¤W­zµ{¦¡½X½Æ»s¶K¦b¸ê®Æ°Ï¬q¤¤§Y¥i¡C¤W­zµ{¦¡½X¤¤¡Ad¡Ban¡Bn ³£¬O²ÕĶ®É´ÁÅܼơA¥¦­Ì¦b ML.EXE ²ÕĶ®É¡A©ó°O¾ÐÅ餤«Ø¥ß¡F²ÕĶ®É´Á¡A¥Ñ ML.EXE ­t³dºÞ²z»P­pºâ³o¨ÇÅܼơF·í ML.EXE ²ÕĶ§¹¦¨¤§«á¡A¥¦­Ì´N®ø¥¢¤F¡F·í¨Ï¥ÎªÌ°õ¦æ©Ò²£¥ÍªºÀ³¥Îµ{¦¡¡A¤]¤£·|«Ø¥ß³o¤T­ÓÅܼơC

WHILE/ENDM ­«½Æ°Ï¶ô¥H n ·í°µ§PÂ_¦¡¡A¥u¦³·í n ¤£¬°¹s®É¡A§PÂ_¦¡¬°¯u¡A¤~·|°õ¦æ WHILE »P ENDM ¤§¶¡ªºµ{¦¡½X¡C¦]¬°¦³ 100 ¶µ¡A©Ò¥H¦b­«½Æ°Ï¶ô¶}©l«e¡A§â n ³]¬° 100¡CµM«á°õ¦æ¨ì WHILE¡AWHILE ·|Àˬd§PÂ_¦¡¬O§_¬°¯u¡A­Y¬°¯u´N·|°õ¦æ WHILE »P ENDM ¤§¶¡ªºµ{¦¡½X¡C¦Ó¤@¶}©l n ¬° 100¡A¬G§PÂ_¦¡¬°¯u¡A°õ¦æ WHILE »P ENDM ¤§¶¡ªºµ{¦¡½X¡Cº¸«á¨C°õ¦æ¤@¦¸°Ï¶ô¡An ´î¤@¡Aª½¨ìÅܬ°¹s¤§«e³£·|¦b­«½Æ°Ï¶ô¤º°õ¦æ¡C

¦b WHILE »P ENDM ¤§¶¡ªºµ{¦¡½X«Ü²³æ¡C­º¥ý©w¸q¡uDW an¡v¡A³o¼Ë·|¦b¸ê®Æ°Ï¬q¤¤¯d¤U¤@­Ó¦r²Õ¤j¤pªºªÅ¶¡¡A¤]´N¬O¯d¤U¤@­Ó°}¦C¤¤ªº¤¸¯À¡CµM«á­pºâ¤U¤@¶µ¡A¨Ï an Åܬ° an¡Ïd¡A¨ä¤¤ d ¬O¤½®t¡A¨ä¹ê´N¬O 2¡CµM«á¦A¨Ï¶µ¼Æ´î¤@¡A±µµÛ¹J¨ì ENDM¡A¥¦·|¨Ï±±¨îÅv¦^¨ì WHILE ¤§³B¡AÅý WHILE Àˬd¬O§_Ä~Äò¤U¤@¦¸­«½Æ°Ï¶ô¡C

LABEL °²«ü¥O

¦³®É­Ô¤@­ÓÅܼƻݭ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   WORD
y       BYTE    11h,22h
        ⁝
        mov     ax,x
        mov     cl,y

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

¥t¤@­Ó¨Ò¤l¬O¤W­±©Ò´£¨ì¥Ñ 1 ¨ì 199 ªº©_¼Æ²Õ¦¨ªº°}¦C¡C¦b³o­Ó¨Ò¤l¤¤¡A¨S¦³¿ìªk¦b WHILE »P ENDM ¤§¶¡«Å§iÅܼƦWºÙ¡A¦]¬°³o¼Ëªº¸Ü´N·|¨Ï¸ÓÅܼƦWºÙ­«½Æ¡A·|µo¥Í­«½Æ©w¸qÅܼƦWºÙªº¿ù»~¡C¦]¦¹¦b³o­Ó­«½Æ°Ï¶ô¤§«e¡A¥H LABEL °²«ü¥O«Å§i³o 100 ­Ó©_¼Æ©Ò²Õ¦¨ªº°}¦C¦WºÙ¬° odd_number¡A¥H§QÀ³¥Îµ{¦¡¦s¨ú¡C

¤W­±ªº¨Ò¤lÁÙ¥i¥H¦A¥[¥H§ï¶i¡C¦]¬°¨C¦¸»Ý­n odd_number °}¦C®É¡A³£­n½Æ»s¶K¤W¡A¤]¬O¦³¨Ç³Â·Ð¡A¥i¥HÅý³o¬qµ{¦¡½X¼g¦b¥t¤@­Ó¥¨¶°¤§¤¤¡A¨£¤U­±ªº±_ª¬¥¨¶°ªº»¡©ú¡C

±_ª¬¥¨¶° ( Nesting Macros )

¦b¥¨¶°¤§¤ºÁÙ¦³¥t¤@­Ó¥¨¶°¡A³oºØ±¡ªpºÙ¬°±_ª¬¥¨¶°¡C¤@¯ë¦Ó¨¥¡A±_ª¬¥¨¶°ªº§Î¦¡¦p¤U¡G

¥Ò¡@¡@¡@MACRO   ¥Ò¥¨¶°°Ñ¼Æ¦Cªí
¡@¡@¡@¡@⁝
¡@¤A¡@¡@MACRO   ¤A¥¨¶°°Ñ¼Æ¦Cªí
¡@¡@¡@¡@⁝
¡@ENDM
¡@¡@¡@¡@⁝
ENDM

¥Ò¡B¤A¤£¤@©w¤@©w¬O¥¨¶°µ{§Ç¡A¥i¥H¬O¨ä¥LÃþ«¬ªº¥¨¶°¡C¨Ò¦p±N¤W­±ªº WHILE/ENDM ­«½Æ°Ï¶ô¥]§t¶i¥t¤@­Ó¥¨¶°µ{§Ç¤§¤¤¡AÅܦ¨¤U­±ªº¼Ë¤l¡G

arithmetic MACRO a1,d,terms ;;µ¥®t¼Æ¦C¥¨¶°
  an=a1                     ;;­º¶µ
  n=terms
  WHILE n
        DW      an          ;;©w¸q²Ä n ¶µ
        an=an+d             ;;¤U¤@¶µ¬°«e¤@¶µ¥[¤½®t
        terms=terms-1       ;;¶µ¼Æ¤Ö¤@
  ENDM
ENDM

arithmetic ¬Oµ¥®t¼Æ¦C¡]arithmetic sequence¡^ªº·N«ä¡Aarithmetic ¥¨¶°¦³¤T­Ó°Ñ¼Æ¡G①­º¶µ¬O a1¡A②¤½®t¬O d¡A③¶µ¼Æ¬O terms¡C¦]¬°¦b¥¨¶°¤¤µLªk§ïÅܰѼƤ§­È¡A©Ò¥H³]¥ß¥t¥~¨â­ÓÅÜ¼Æ an¡Bn ¨ÓÅý¦¹¥¨¶°¤u§@¡C¤Þ¥Î arithmetic ¥¨¶°ªº¤èªk¦p¤U¡G

.DATA
⁝
odd_number      LABEL   WORD
arithmetic      1,2,100

arithmetic ¥¨¶°¤£¶È¥i¥H¹³¤W­±¤@¼Ë«Ø¥ß 1¡ã199 ªº©_¼Æ©Ò²Õ¦¨ªº¼Æ¦C¡A¦pªG¾A·í³]©w a1¡Bd¡Bterms¡A¤]¥i¥H«Ø¥ß¨ä¥Lµ¥®t¼Æ¦C¡Carithmetic ¥¨¶°ªº¥Î³~»á¤j¡A¤]¥i¥H§â arithmetic ¥¨¶°¦s¤J¬Y­Ó¥]§tÀɤ¤¡A·í­n«Ø¥ßµ¥®t¼Æ¦C®É¡A´N±N¦¹¥]§tÀɧt¬A¶i¨Ó¡A¦A¤Þ¥Î arithmetic ¥¨¶°¡C

FOR/ENDM ­«½Æ°Ï¶ô

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Á|­Ó¨Ò¤l¡A°²³]¦³­Ó¥¨¶°¬O¡G

FOR     arg,<1,2,3,4,5>
        BYTE    arg DUP (arg)
ENDM

¤W­±ªº¥¨¶°²£¥Í©³¤Uªºµ{¦¡½X¡G

        BYTE    1 DUP (1), 2 DUP (2), 3 DUP (3), 4 DUP (4), 5 DUP (5)

±ø¥ó²ÕĶ

±ø¥ó²ÕĶ¬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¨ýµÛ¸õ¹L¸Ó¬qµ{¦¡½X¡A·íµM¤]¤£·|¼g¤J¥ØªºÀɤΥi°õ¦æÀɸ̭±¡C±ø¥ó²ÕĶªº°²«ü¥O¦³¦n´XºØ¡A¥ý¤¶²Ð³Ì±`¨£ªº IF/ELSE/ENDIF¡C

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

²Ä¤»³¹´¿¸g´£¹Lªº±ø¥ó±±¨î¬yµ{«ü¥O¡A.IF/.ESLEIF/.ELSE/.ENDIF¡A¬Ý°_¨Ó»P³oùØÁ¿ªº IF/ELSE/ENDIF «Ü¹³¡A¦ý¥¦­Ì¬O¤£¤@¼Ëªº·§©À¡C­º¥ý«eªÌ¬O¦bÀ³¥Îµ{¦¡°õ¦æ®É´Á®É³Q CPU ©Ò°õ¦æ¡A«áªÌ«h¬O¦b²ÕĶ®É´Á³Q CPU ©Ò°õ¦æ¡F¨ä¦¸«eªÌªº§PÂ_¦¡¦h¥H¼Æ¾Ç²Å¸¹ªí¥Ü¡A«áªÌ«h¬O¥H­^¤å¦r¥Àªí¥Ü¡C

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 ELSE¡A»yªk¬°¡G

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

¤W­±ªºµ{¦¡½X¬O»¡¡A¦pªG§PÂ_¦¡¬°¯u¡A¨º»ò´N²ÕĶµ{¦¡¤ù¬q¤@¤¤ªºµ{¦¡¡A§_«h´N²ÕĶµ{¦¡¤ù¬q¤G¤¤ªºµ{¦¡¡C§PÂ_¦¡ªº¼gªk»P«e­z´£¤Îªº WHILE/ENDM ¤@¼Ë¡A½Ð¦Û¦æ°Ñ¦Ò¡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

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

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¥~¡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


¥Î¥¨¶°¡B±ø¥ó²ÕĶ¤Î¾÷±ñ½X¹ê²{ MASM ¥¼¤ä´©ªº«ü¥O

­ì²z

¸g¹L²Ä 24 ³¹¥H¤Î¥»³¹«e¥b³¡ªº¸É¥R¡A²{¦b§Ú­Ì¤w¸g¦³¯à¤OÅý MASM 6.11 ¤ä´©­ì¥»¥¼¤ä´©ªº x86 «ü¥O¡ARDRAND¡C¬d¾\ªþ¿ý¤Cªº¡u64-Bit OpCode Extensions¡v±oª¾ RDRAND ªº¾÷±ñ½X¦ì©ó GRP9¡A¨ä¾Þ§@½X¡]OpCode¡^¦³¨â­Ó¡A¨Ì¦¸¬O 0FH 0C7H¡A¨Ã¥B¦³©µ¦ùªº¾Þ§@½X¡]OpCode Extensions¡^¡A110¡A¦¹©µ¦ùªº¾Þ§@½X¦ì©ó ModR/M ¦ì¤¸²Õªº²Ä 3¡ã5 ¦ì¤¸¡A¦p¤U¹Ï¡G ¤W¹Ï¤¤¡AModR/M ¦ì¤¸²Õªº Mod Äæ¦ì¥H¤Î R/M Äæ¦ì¥Î¨Óªí¥Ü¹Bºâ¤¸¡A¤]´N¬O¼È¦s¾¹¡C¬d¾\²Ä 24 ³¹¡uBit-32 Mod »P R/M ªºÃö«Y¡v¡A±oª¾ Mod ¬° 11 ®É¡AR/M ¼Æ­È¤£¦P¥Nªí¤£¦Pªº¼È¦s¾¹¡CR/M ¦³¤T­Ó¦ì¤¸¡A«ê¦n¥i¥Hªí¥Ü¤K­Ó³q¥Î¼È¦s¾¹¡C

«e­±»¡¹L¡ARDRAND ªº¹Bºâ¤¸¥u¦³¤@­Ó¡A³o­Ó¹Bºâ¤¸¬O 64¡B32 ©Î 16 ¦ì¤¸ªº¼È¦s¾¹¡C¦ý¬O¡A¦b MS¡ÐDOS ¤¤¡A¨ÃµLªk¨Ï¥Î x64 ·s¼Wªº¼È¦s¾¹¡A¤]´N¬O¤£¯à¨Ï¥Î 64 ¦ì¤¸ªº¼È¦s¾¹¡C³oùرo¦A»¡±o§ó²M·¡¤@¨Ç¡A¨Æ¹ê¤W¡A¤£¯à¨Ï¥Îªº¼È¦s¾¹ÁÙ§ó¦h¤@¨Ç¡C©Ò¿×¡u·s¼Wªº¼È¦s¾¹¡v¡A¬O«ü¶i¤J x64 ®É¥N¡A¨ä¼È¦s¾¹ªº¦WºÙ¬O·s¼Wªº¡C¤]´N¬O»¡¡A¹³ RAX¡BRBX¡K¡Kµ¥¤£¯à¨Ï¥Î¡A¦ý¥i¥H¨Ï¥Î EAX¡BAX¡BEBX¡BBX¡K¡K¡A¦]¬°«e¨âªÌ¬O x64 ·s¼Wªº¡A¦Ó«á¥|ªÌ¬O IA¡Ð32 ­ì¥»´N¦³ªº¡C¦P²z¡AÁöµM R8D¡BR8W ¤À§O¬O 32¡B16 ¦ì¤¸ªº¼È¦s¾¹¡A«o¤]µLªk¦b MS¡ÐDOS ¨Ï¥Î¡A­ì¦]¬O³o¨â­Ó¼È¦s¾¹¦WºÙ¤]¬O·s¼Wªº¡C

¬°¦ó¦p¦¹©O¡H¤p¤ì°¸²q·Q¨ä¤¤ªº­ì¦]¤j·§¬O­n¨Ï¥Î x64 ·s¼Wªº¼È¦s¾¹¡A´N¥²¶·­n¨Ï¥Î REX «e¸m½X¡C²Ä 24 ³¹´£¹L¡AREX «e¸m½X¦b½d³ò 40H¡ã4FH ¤§¶¡¡A¦Ó¦b¯u¹ê¼Ò¦¡®É¡A³o¬q½d³òªº¾÷±ñ½X¬O¥Nªí INC¡BDEC «ü¥O¡C«Ü¤£©¯¡AMS¡ÐDOS ´N¬O¦b¯u¹ê¼Ò¦¡¤U¹B§@ªº¡A©Ò¥H¦b MS¡ÐDOS ¤¤¡A¨ÃµLªk¨Ï¥Î x64 ·s¼Wªº¼È¦s¾¹¡C

¦ý¤S«Ü©¯¹Bªº¬O¡A¦]¬°¦b MS¡ÐDOS °õ¦æªºµ{¦¡¤£¯à¨Ï¥Î·s¼Wªº¼È¦s¾¹¡A±¡ªpº¥Åܱo«Ü³æ¯Â¤F¡C¤]´N¬O»¡¡ARDRAND «ü¥Oªº¹Bºâ¤¸¡A´N¥u­n¦Ò¼{­ì¥»ªº 32 ©Î 16 ¦ì¤¸ªº¼È¦s¾¹§Y¥i¡C

¥ý»¡°²¦p RDRAND «ü¥Oªº¹Bºâ¤¸¬O 16 ¦ì¤¸ªº¸Ü¡A¦p¦óªí¥Ü¡H¬°¤F³æ¯Â°_¨£¡A¥H¡uRDRAND AX¡v¬°¨Ò¤l¡C¬d¾\²Ä 24 ³¹¡uBit-32 Mod »P R/M ªºÃö«Y¡v¥i¥H±oª¾ Mod ¬° 11 ¥B R/M ¬° 000 ®É¡A©Ò¥Nªíªº¹Bºâ¤¸¬O AL¡BAX ©Î EAX¡Cªí¤¤ªº W ¦ì¤¸¬O¾Þ§@½Xªº²Ä¹s­Ó¦ì¤¸¡A¤£ºÞ¬O 0FH ©Î 0C7H ²Ä¹s­Ó¦ì¤¸§¡¬° 1¡A¬G¹Bºâ¤¸¬° AX ©Î EAX ¨ä¤¤¤§¤@¡]¤]¥i¥H·Q¦¨ RDRAND ªº¹Bºâ¤¸¤£¯à¬O¤K¦ì¤¸ªº¼È¦s¾¹¡^¡C¦]¬° MS¡ÐDOS ¬O 16 ¦ì¤¸ªº§@·~¨t²Î¡A¬G¿ï¾Ü AX¡Cºî¦X¤W­z¹Lµ{¡AModR/M ¦ì¤¸²Õ¬O 11 110 000¡A²Ä 7¡B6 ¦ì¤¸¬O Mod Äæ¦ì¡A²Ä 3¡ã5 ¦ì¤¸¬O¾Þ§@½Xªº©µ¦ù¡A²Ä 0¡ã2 ¦ì¤¸¬O R/M Äæ¦ì¡A¥Nªí AX ¼È¦s¾¹¡A¦X¦b¤@°_´N¬O 0F0H¡CMS¡ÐDOS À³¥Îµ{¦¡¤¤¡A­n¨Ï¥Î¡uRDRAND AX¡v«ü¥O¡A¥i¥H¦bµ{¦¡½X°Ï¬q¶ñ¤J¨ä¾÷±ñ½X¡G

.CODE
⁝
DB      0FH,0C7H,0F0H       ;¯à°õ¦æ rdrand ax «ü¥O

¨º¦pªG¬O¡uRDRAND CX¡v¡A¥u¦³ R/M Äæ¦ì§ï¦¨ 001¡F¦P²z¨ä¾l¼È¦s¾¹¤]¥u¦³ R/M Äæ¦ì¤£¦P¡CŪªÌ¥i¥H¦Û¦æ¥H¦¹¼¶¼gµ{¦¡¡AµM«á¥Î°£¿ù¾¹¸ü¤JÆ[¹î¡A§A·|µo²{µ²ªG¹ê¦b¬O¤SÅå¤S³ß¡A³ºµM¯uªº¥i¥H°õ¦æ¡C

¨º»ò¦pªG­n°õ¦æ¡uRDRAND EAX¡v«ü¥O¡A¤S·í¦p¦ó©O¡H¨ä¹ê¨Ã¤£Ãø¡A¥u­n¥[¤W¹Bºâ¤¸«e¸m½X¡]operand-size override prefix¡^§Y¥i¡A¤]´N¬O¦b­ì¥»ªº¾÷±ñ½X¤§«e¥[¤W 66H¡C«e¤@³¹´£¹L¡A¹Bºâ¤¸«e¸m½X¬O¥Î¨Ó¤Á´«¹Bºâ¤¸¤j¤p¡C­ì¥»¦b MS¡ÐDOS ¬O¤Q¤»¦ì¤¸ªº°Ï¬q¡A¹w³]¹Bºâ¤¸¤j¤p¤]¬O¤Q¤»¦ì¤¸¡A¥[¤W¤F 66H ¤§«á´N¤Á´«¦¨¤T¤Q¤G¦ì¤¸¡C¦]¦¹­n¨Ï¥Î¡uRDRAND EAX¡v«ü¥O¡A¥i¥H¦bµ{¦¡½X°Ï¬q¶ñ¤J¨ä¾÷±ñ½X¡G

.CODE
⁝
DB      66H,0FH,0C7H,0F0H   ;¯à°õ¦æ rdrand eax «ü¥O

¨º»ò¦p¦ó±N RDRAND ªº¹Bºâ¤¸§ï¦¨ RBX¡BRCX¡K¡K©O¡H¸ò¤Q¤»¦ì¤¸ªº±¡ªp¤@¼Ë¡A¥u¦³ ModR/M ¤¤ªº R/M Äæ¦ì§ïÅܦӤw¡C

»s§@ rdrand ¥¨¶°

¹ï©ó­n¥H¥ô¦ó¤@­Ó¦Xªkªº¼È¦s¾¹§@¬° RDRAND «ü¥Oªº¹Bºâ¤¸¡AÀ³¸Ó³£¯à¼g¥X¨Ó¤F¡C¦ý¬O¦pªG­n°õ¦æ RDRAND «ü¥O¡A³£­n¨Ï¥Î¡uDB 0FH,0C7H¡K¡K¡v¡A¬Ý°_¨Ó´N«Ü§C¯Å¡C¤p¤ì°¸³¥¤ß§ó¤j¡A·Q»s§@¤@­Ó¥¨¶°¡A¦Ó¥B´N±N³o­Ó¥¨¶°©R¦W¬° rdrand¡A¥¦´N¥u¦³¤@­Ó°Ñ¼Æ¡A¦¹°Ñ¼Æ´N¬O¼È¦s¾¹¡A¤Þ¥Î°_¨Ó¥i¥H´N¸ò¨ä¥L x86 «ü¥O¤@¼Ò¤@¼Ë¡C³o­Ó rdrand ¥¨¶°¤º®e¦p¤U¡G

rdrand  MACRO   arg
;;ÁöµMMASM 6.11¨Ã¥¼¤ä´©RDRAND«ü¥O¡A¦ýrdrand¥¨¶°³z¹L¦bµ{¦¡½X°Ï¬q¤¤¶ñ¥R¾÷±ñ
;;½Xªº¤è¦¡¡A¹ê§@RDRAND«ü¥O¡AÅýMASM 6.11¤]¯à°õ¦æRDRAND«ü¥O

;;flag¬O¥Î¨ÓÀˬdarg¬O§_¬°¦Xªkªº16©Î32¦ì¤¸ªº¼È¦s¾¹¡C­Y¬°¦Xªk¼È¦s¾¹¡A°õ¦æ¨ì
;;¥¨¶°³Ì«á­±¡Aflag¬°1¡F­Y¤£¦Xªk¡A«h¨ì¥¨¶°³Ì«á­±flag¬°0
        flag=0
;;Àˬdarg¬O§_¬°32¦ì¤¸¼È¦s¾¹
        i=0
  FOR   param,<eax,ecx,edx,ebx,esp,ebp,esi,edi>
    IFIDNI <arg>,<param>
        flag=1
        ModRM=0f0h+i
        DB      66h,0fh,0c7h,ModRM
        EXITM   ;;­Yarg¬°32¦ì¤¸¼È¦s¾¹¡A°h¥XFOR/ENDM­«½Æ°Ï¶ô
    ENDIF
        i=i+1
  ENDM
  IF flag EQ 1  ;;­Yflag¬°1¡Aªí¥Üarg¬O32¦ì¤¸¼È¦s¾¹¡A°h¥Xrdrand¥¨¶°
    EXITM
  ENDIF
;;Àˬdarg¬O§_¬°16¦ì¤¸¼È¦s¾¹
        i=0
  FOR   param,<ax,cx,dx,bx,sp,bp,si,di>
    IFIDNI <arg>,<param>
        flag=1
        ModRM=0f0h+i
        DB      0fh,0c7h,ModRM
        EXITM   ;;­Yarg¬°16¦ì¤¸¼È¦s¾¹¡A°h¥XFOR/ENDM­«½Æ°Ï¶ô
    ENDIF
        i=i+1
  ENDM
;;­Yflag¬°0¡Aªí¥Üarg¤£¬O16¦ì¤¸¤]¤£¬O32¦ì¤¸ªº¼È¦s¾¹¡A¦L¥X¿ù»~°T®§
  IF flag EQ 0
        ECHO ERROR:
        ECHO THE OPERANDS MUST BE 16, 32 BITS REGISTERS,
        ECHO AND REGISTERS LIKE R8D, R8W CANNOT BE USED.
  ENDIF
ENDM

¥i¥H¬Ý¥X¨Ó¡Ardrand ¥¨¶°¨Ï¥Î¤F¨â­Ó FOR/ENDM ¨Ó¤À§OÀˬd 32¡B16 ¦ì¤¸¼È¦s¾¹¡C³o¨âºØ¤£¦P¦ì¤¸¼Æªº¼È¦s¾¹¦U¦³¤K­Ó¡A¼Æ¶q¤£¦h¡A©Ò¥H§@¬° FOR ªº¤Þ¼Æ¦Cªí¡AÁÙ¤£ºâ¤Ó³Â·Ð¡C¦b¶i¤J FOR/ENDM ¤§«e¥ý±N flag ÅܼƳ]¬° 0¡A¦¹ÅܼƬO­ÓºX¼Ð¡A¥Î¨Óªí¥Ü¬O§_¦³¦Xªkªº°Ñ¼Æ¡C¦b¨C­Ó FOR/ENDM ­«½Æ°Ï¶ô¤º¡A³£¦³¤@­Ó IFIDNI/ENDIF ¨ÓÀˬdµ{¦¡¶Ç¨Óªº°Ñ¼Æ¡A¬O§_²Å¦X FOR ¤§«áªº¤Þ¼Æ¦Cªí¡C¦pªG²Å¦X¡A´Nªí¥Ü§ä¨ì¦Xªkªº¼È¦s¾¹¡Aflag ·|³Q³]¬°¤@¡F¤Ï¤§¡Aflag ¤´µM¬O¹s¡C

ÅÜ¼Æ i ¬O¥Î¨Ó­pºâ¦b¤Þ¼Æ¦Cªí¤¤ªº²Ä´X­Ó¤Þ¼Æ²Å¦X°Ñ¼Æ¡A¦Ó¤Þ¼Æªº±Æ¦C¶¶§Ç¦pªG»P R/M Äæ¦ì©Ò¥Nªíªº¼È¦s¾¹¶¶§Ç¤@¼Ë¡A¨º»ò R/M ¤§­È´N·|»P i ¬Ûµ¥¡C¦Ó Mod »P OpCode ©µ¦ùÄæ¦ì¤§­È¬O©T©wªº¡A¨ä¹ê´N¬O 0F0H¡A©Ò¥H ModR/M ¦ì¤¸²Õ´N¬O 0F0H ¥[¤W i¡C

¦b rdrand ¥¨¶°¤¤ÁÙ¦³¨â­Ó°²«ü¥O¤£´¿¤¶²Ð¡G①EXITM¡B②ECHO¡C

EXITM °²«ü¥O

¦b¥¨¶°¤¤¡A¥i¥H§Q¥Î EXITM ±j­¢¥¨¶°µ²§ô¡A¦P®É§â¦^¶Ç­È¶Ç¦^¡CEXITM ªº»yªk¬O¡G

EXITM   textitem

·í²ÕĶ¾¹¥Ñ¤W¦Ó¤U²ÕĶ­ì©lµ{¦¡ªº¥¨¶°®É¡A¦pªG¹J¨ì EXITM¡A´N·|©¿²¤±q EXITM ¨ì ENDM ¤§¶¡ªº¥¨¶°µ{¦¡½X¡A¸õ¥X¥¨¶°¡A¨Ã¶Ç¦^¦^¶Ç­È¡C

¦^¶Ç­È´N¬Oºò±µµÛ EXITM ¤§«áªº textitem¡Atextitem ¥²¶·¬O¦r¦ê©Î¬O¥Nªí¦r¦êªº²Å¸¹¦WºÙ¡A¤]¥i¥H¬O¥t¤@­Ó¥¨¶°¨ç¦¡ªº¦^¶Ç­È¡C¦^¶Ç­È¤]¥i¥H¬Ù²¤¡A¦pªG¬Ù²¤ªº¸Ü¡A´N¨S¦³ textitem¡CEXITM ¶È¶È¬Oµ²§ô¦Û¨­©Ò¦bªº¥¨¶°¡A©Ò¥H¦b±_ª¬¥¨¶°¤¤¡A¦pªG¦b²Ä¤G¼h¥¨¶°¨Ï¥Î EXITM¡A¨º»ò´N¥u¦³µ²§ô²Ä¤G¼h¥¨¶°¡A¦ý¤´¦b²Ä¤@¼h¥¨¶°¤¤¡C¨Ò¦p©³¤U¨Ò¤l¡G

a_mac   MACRO      ;;──────────┐
                  ;;          │
  b_mac MACRO      ;;─┐        │
                  ;; │        │
    IF arg LT 20h  ;; │        │
       EXITM       ;; ├─b_mac  │
    ENDIF          ;; │        ├─a_mac
                  ;; │        │
  ENDM             ;;─┘        │
  arg=20h          ;;          │
                  ;;          │
ENDM               ;;──────────┘

¤W­±ªº a_mac¡Bb_mac ³£¬O¥¨¶°¤¤¡A¦ý a_mac ¥¨¶°¥]§t¤F¥t¤@­Ó b_mac ¥¨¶°¡A³oºØ±¡§ÎºÙ¬°±_ª¬¥¨¶°¡C·í²ÕĶ¨ì b_mac¡A¦pªG arg ¤p©ó 20H¡A¨º»ò´N·|°h¥X b_mac¡F¦ý¨Ã«D¦P®É¤]°h¥X a_mac¡A¦Ó¬O·|Ä~Äò²ÕĶ¡uarg=20h¡v¥H¤Î¨ä«á a_mac ªº³Ñ¾l³¡¤À¡C

ECHO °²«ü¥O

ECHO ·|¨Ï²ÕĶ¾¹¦b²ÕĶ­ì©lµ{¦¡´Á¶¡¡A§â±µ¦b ECHO ¤§«áªº¸ê®Æ¦L¦b¿Ã¹õ¤W¡C¨ä¥D­n¥Øªº¡A¬O¹ï¥¨¶°°£¿ù¡C¥¦¦³¨âºØ¥Îªk¡G

ECHO ¦r¦ê
%ECHO ¦r¦êÅܼÆ

²Ä¤@ºØ¥Îªk«Ü²³æ¡A´N¬O³æ¯Âªº§â¦r¦ê¦L¦b¿Ã¥ú¹õ¤W¡C²Ä¤GºØ¥Îªk¯à§â¦r¦êÅܼƪº¤º®e¦L¥X¨Ó¡A¦pªG¦b ECHO ¤§«e¤£¥[¤W¡u%¡v¹Bºâ¤l¡A´N¥u¯à¦L¥XÅܼƪº¦WºÙ¡A´NÅܦ¨²Ä¤@ºØ¥Îªk¡C¥[¤F¡u%¡v¤§«á¡A¡u%¡v¦³¨D±o¨ä­Èªº¥\¥Î¡A¡u%¡v»P ECHO ¤§¶¡¥i¥H¦³ªÅ¥Õ¡A¤]¥i¥H¤£¥[ªÅ¥Õ¡C¨Ò¦p©³¤Uªº¨Ò¤l¡G

Love    EQU    <I love assembly.>  ;;«Å§iLove¦r¦ê
ECHO    Love                       ;;²ÕĶ®É¥u·|¦L¥XLove
%ECHO   Love                       ;;²ÕĶ®É·|¦L¥X¡uI love assembly.¡v

¨Ò¤l¡GTSTRND.ASM

©³¤Uªº¨Ò¤l¡ATSTRND.ASM¡A·|§Q¥Î¤W­zªº rdrand ¥¨¶°¡A²£¥Í 0¡ã65535 ¤§¶¡ªº¶Ã¼Æ¦@ 65536 ­Ó¡AµM«á²Î­p³o¨Ç¶Ã¼Æ¸¨¦b¦U½d³ò¤ºªº­Ó¼Æ¡C³o¨Ç½d³ò¦@°Ï¦³ 16 ­Ó¡A¨C­Ó½d³ò©Ò¥]§tªº¼Æ³£¤@¼Ë¦h¡A¥¦­Ì¤À§O¬O 0000¡ã0FFFH¡]0¡ã4095¡^¡B1000H¡ã1FFFH¡]4096¡ã8191¡^¡B2000H¡ã2FFFH¡]8192¡ã12287¡^¡K¡K¡B0F000H¡ã0FFFFH¡]61440¡ã65535¡^¡A¦b¡u¡]¡v¡B¡u¡^¡v¤ºªº¬O¥H¤Q¶i¦ìªí¥Ü¡C

¦b TSTRND.ASM ¤¤¡A¦³­Ó qty °}¦C¡A¥¦¦³ 16 ­Ó¤¸¯À¡A¨C­Ó¤¸¯À°O¿ýµÛ¸¨¦b¸Ó½d³ò¤ºªº¶Ã¼Æ­Ó¼Æ¡C¨Ò¦p²Ä 0 ­Ó¤¸¯À¡A¬O¬ö¿ý¸¨¦b 0¡ã4095 ¤§¶¡ªº¶Ã¼Æ¦³´X­Ó¡B²Ä¤@­Ó¤¸¯À¡A¬O¬ö¿ý¸¨¦b 4096¡ã8191 ¤§¶¡ªº¶Ã¼Æ¦³´X­Ó¡K¡K¡C©³¤U¥ý¨Ó¬Ý¬Ý TSTRND.ASM ªºµ{¦¡½X¡C

TSTRND.ASM ­ì©lµ{¦¡

©³¤U¬O TSTRND.ASM ­ì©lµ{¦¡ªº¤º®e¡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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
;TSTRND¥Î¥¨¶°¹ê²{MASM 6.11¥¼¤ä´©ªºRDRAND x86«ü¥O
;TSTRND°õ¦æ65536¦¸RDRAND«ü¥O¡A¨Ã¥H¨C1000H¬°½d³ò¡A²Î­p¨ä¥X²{¦¸¼Æ¡C¤]´N¬O
;»¡TSTRND·|²Î­p©Ò¥Í¦¨ªº¶Ã¼Æ¸¨¦b0¡ã0FFFH¦³´X¦¸¡A¸¨¦b1000H¡ã1FFFH¦³´X¦¸¡K¡K
.MODEL  TINY
.586

rdrand  MACRO   arg
;;ÁöµMMASM 6.11¨Ã¥¼¤ä´©RDRAND«ü¥O¡A¦ýrdrand¥¨¶°³z¹L¦bµ{¦¡½X°Ï¬q¤¤¶ñ¥R¾÷±ñ
;;½Xªº¤è¦¡¡A¹ê§@RDRAND«ü¥O¡AÅýMASM 6.11¤]¯à°õ¦æRDRAND«ü¥O

;;flag¬O¥Î¨Ó¬ö¿ýarg¬O§_¬°¦Xªkªº16©Î32¦ì¤¸ªº¼È¦s¾¹¡C­Y¬°¦Xªk¼È¦s¾¹¡A°õ¦æ¨ì
;;¥¨¶°³Ì«á­±¡Aflag¬°1¡F­Y¤£¦Xªk¡A«h¨ì¥¨¶°³Ì«á­±flag¬°0
        flag=0
;;Àˬdarg¬O§_¬°¦Xªkªº32¦ì¤¸¼È¦s¾¹
;;­Yarg¬°¦Xªkªº32¦ì¤¸¼È¦s¾¹¡A¨º»òi´N¬OFOR°Ñ¼Æ¦Cªí¤¤ªº²Ä´X­Ó²Å¦Xarg¡C¨Ò¦p
;;­Yarg¬°EAX¡Ai´N¬O0¡Farg¬°ECX¡Ai´N¬O1¡K¡K
        i=0
  FOR   param,<eax,ecx,edx,ebx,esp,ebp,esi,edi>
    IFIDNI <arg>,<param>
        flag=1
        ModRM=0f0h+i
        DB      66h,0fh,0c7h,ModRM
        EXITM   ;;­Yarg¬°32¦ì¤¸¼È¦s¾¹¡A°h¥XFOR/ENDM­«½Æ°Ï¶ô
    ENDIF
        i=i+1
  ENDM
  IF flag EQ 1  ;;­Yflag¬°1¡Aªí¥Üarg¬O32¦ì¤¸¼È¦s¾¹¡A°h¥Xrdrand¥¨¶°
    EXITM
  ENDIF
;;Àˬdarg¬O§_¬°¦Xªkªº16¦ì¤¸¼È¦s¾¹
        i=0
  FOR   param,<ax,cx,dx,bx,sp,bp,si,di>
    IFIDNI <arg>,<param>
        flag=1
        ModRM=0f0h+i
        DB      0fh,0c7h,ModRM
        EXITM   ;;­Yarg¬°16¦ì¤¸¼È¦s¾¹¡A°h¥XFOR/ENDM­«½Æ°Ï¶ô
    ENDIF
        i=i+1
  ENDM
;;­Yflag¬°0¡Aªí¥Üarg¤£¬O16¦ì¤¸¤]¤£¬O32¦ì¤¸ªº¼È¦s¾¹¡A¦L¥X¿ù»~°T®§
  IF flag EQ 0
        ECHO ERROR:
        ECHO THE OPERANDS MUST BE 16, 32 BITS REGISTERS,
        ECHO AND REGISTERS LIKE R8D, R8W CANNOT BE USED.
  ENDIF
ENDM
;*********************************************************************
.CODE
ORG     100h
;---------------------------------------------------------------------
main    PROC
        jmp     begin
msg     DB      "TSTRND implementation generates unsupported",\
                0dh,0ah,"x86 instructions using macros in ML.EXE",\
                0dh,0ah,0dh,0ah,"  Range   Freq",0dh,0ah,"$"
;qty°}¦C¬ö¿ý¸¨¦b­Ó½d³ò¤ºªº¶Ã¼Æ­Ó¼Æ¡CÁ|¨Ò¨Ó»¡¡A¸¨¦b0¡ã0FFFh¤§¶¡ªº¶Ã¼Æ
;­Ó¼Æ¦s©óqty[0]³B¡A;¸¨¦b1000h¡ã1FFFh¤§¶¡ªº¶Ã¼Æ­Ó¼Æ¦s©óqty[2]³B¡A¸¨¦b
;2000h¡ã2FFFh¤§¶¡ªº¶Ã¼Æ­Ó¼Æ¦s©óqty[4]³B¡K¡K
qty     DW      16 DUP (0)      ;¨C­Ó½d³òªº¶Ã¼Æ­Ó¼Æ
ten     DW      10
buffer  DB      "?000-?FFF:XXXX",0dh,0ah,"$"
begin:  mov     ah,9
        lea     dx,msg
        int     21h
        xor     cx,cx   ;CX·|±q0FFFFH¡ã0¡A¨Ï¤U­±°j°é°õ¦æ65536¦¸
again:  rdrand  bx      ;¨ú±o¶Ã¼Æ¡A¨Ã¦s©óBX
        shr     bx,12
        shl     bx,1
        inc     qty[bx]
        loop    again
        xor     bx,bx   ;BX·|±q0¡B2¡B4¡K¡K¤@ª½¨ì1EH¡A¦@16­Ó
        mov     cx,16   ;©³¤Uªº°j°é¦L¥X¥X²{¦b¨C­Ó½d³ò¤ºªº¶Ã¼Æ¦¸¼Æ
next:   call    print
        add     bx,2
        loop    next
        int     20h     ;µ{¦¡µ²§ô
main    ENDP
;---------------------------------------------------------------------
;¿é¤J¡GBX¡Ðqty°}¦C¤¤ªº¤¸¯À¦ì§}¡A±q0¡B2¡B4¡K¡K¤@ª½¨ì1EH
;¿é¥X¡G¦L¥XÃþ¦ü¡u?000-?FFF:XXXX¡vªº¦r¦ê
print   PROC
        lea     di,buffer
    ;­pºâ¡u?000-?FFF:XXXX¡v¤¤ªº¨â­Ó¡u?¡v
        mov     ax,bx
        shr     ax,1
        add     al,"0"
        cmp     al,"9"
        jbe     save
        add     al,7
save:   stosb
        mov     di,OFFSET buffer+5
        stosb
    ;­pºâ¡u?000-?FFF:XXXX¡v¤¤ªº¡uXXXX¡v¡A
    ;XXXX¬°¶Ã¼Æ¸¨¦b?000-?FFFªº½d³ò¤ºªº­Ó¼Æ
        mov     ax,qty[bx]
        mov     di,OFFSET buffer+13
.WHILE  1
        xor     dx,dx
        div     ten
        add     dl,"0"
        mov     [di],dl
.BREAK  .IF ax==0
        dec     di
.ENDW
        mov     dx,OFFSET buffer
        mov     ah,9
        int     21h
        ret
print   ENDP
;*********************************************************************
END     main

TSTRND.ASM ²Ä 63¡ã65 ¦æ¡A¬O¦L¥X TSTRND ªºµ{¦¡¥\¯à¡A³o¨S¤°»ò¥i»¡¡C

TSTRND.ASM ²Ä 66¡ã71 ¦æ¡A¬O¥Î¨Ó²£¥Í 65536 ­Ó¶Ã¼Æ¡AµM«á±N³o¨Ç¶Ã¼ÆÂkÃþ¦b¨C­Ó½d³ò¤º¡C¦ý TSTRND.ASM ¨Ã«D¤@¦¸²£¥Í 65536 ­Ó¶Ã¼Æ¡AµM«á¦AÂkÃþ¡F¦Ó¬O¥Î¤@­Ó°õ¦æ 65536 ¦¸ªº°j°é¡A¨C°õ¦æ¤@¦¸°j°é¥u²£¥Í¤@­Ó¶Ã¼Æ¡AµM«áÂkÃþ¡C¦¹³BªºÂkÃþ¬O«ü®Ú¾Ú¥Í¦¨ªº¶Ã¼Æ¤j¤p¡A§PÂ_¥¦¸¨¦b­þ¤@­Ó½d³ò¤º¡AµM«á¨Ï¥Nªí¸Ó½d³òªº qty ¤¸¯À¤§­È¼W¥[¤@¡C

§PÂ_¶Ã¼Æ¸¨¦b­þ­Ó½d³ò¡A´N¥u¥Î²Ä 68¡B69 ¨â¦æµ{¦¡½X´N§¹¦¨¤F¡A©³¤U¸ÑÄÀ¦p¦ó°µ¨ì¡C­º¥ý¡AÆ[¹î³o¤Q¤»­Ó½d³ò¡G

0000H¡ã0FFFH
1000H¡ã1FFFH
2000H¡ã2FFFH
3000H¡ã3FFFH
  ⁝
F000H¡ãFFFFH

§Ú­Ì¥i¥H³o¼Ë·Q¡G

¸g¹L¤W­±ªº¾ã²zÂk¯Ç¡A´N·|µo²{¡A¨ì©³­n¨Ï qty °}¦Cùتº­þ¤@­Ó¤¸¯À¤§­È¼W¥[¤@¡A¥u»P¶Ã¼Æªº³Ì°ª¦ì¦³Ãö¡C¨Ò¦p°²¦p¥Í¦¨ªº¶Ã¼Æ¬O 6571¡A´«¦¨¤Q¤»¶i¦ì¬O 19ABH¡A¸¨¦b 1000H¡ã1FFFH¡]¤]´N¬O¤Q¶i¦ìªº 4096¡ã8191¡^¡C¹ï©ó TSTRND.ASM ¨Ó»¡¡A¥u­nÀË´ú¤Q¤»¶i¦ìªº³Ì°ª¦ì¡A1¡A´N¯àª¾¹D­n¨Ï qty ªº²Ä¤@­Ó¤¸¯À¤§­È¼W¥[¤@¡CTSTRND.ASM ¥Î SHR «ü¥O±N¥Í¦¨ªº¶Ã¼Æ¥k²¾ 12 ­Ó¦ì¤¸¡A´N¯à±o¨ì³Ì°ª¦ì¡]TSTRND.ASM ²Ä 68 ¦æ¡^¡C

qty °}¦C¬O¥Ñ 16 ­Ó¤¸¯À²Õ¦¨ªº¡A¨C­Ó¤¸¯À¦û¥Î¨â­Ó¦ì¤¸²Õ¡]¨â­Ó¦ì¤¸²Õ¬Û·í©ó¤@­Ó¦r²Õ¡^¡C¦]¦¹ÁÙ¥²¶·±N qty ªº²Ä´X­Ó¤¸¯À­¼¥H¤G¡A¤]´N¬O TSTRND.ASM ªº²Ä 69 ¦æ¡A§Q¥Î SHL ±N²Ä´X­Ó¤¸¯À¦V¥ª²¾¤@¦ì¡C©Î³\¦³¤H·|³o¼Ë·Q¡A¥ý­n¦V¥k²¾ 12 ­Ó¦ì¤¸¡AµM«á¥ß§Y¥k¦V¥ª²¾¤@­Ó¦ì¤¸¡A¨º»ò¬O§_¥i¥Hª½±µ¦V¥k²¾ 11 ­Ó¦ì¤¸©O¡Hµª®×¬O¤£¦æ¡A³o­Ó­ì¦]¨ä¹ê«Ü²³æ¡A½Ð¦Û¦æ·Q·Q¡CTSTRND.ASM ªº¨ä¾l³¡¤Àªº­ì²z¡A«e­±³¹¸`³£´£¹L¡A´N¤£ÂØ­z¤F¡C


«á°O

¶Ã¼Æ¡AÅU¦W«ä¸q¡A¶V¶Ã¶V¦n¡A¦ý¦ó¿×¡u¶Ã¡v¡H¥H¤p¤ì°¸²LÁ¡ªº¨£ÃÑ¥H¬°¡A¶Ã¼Æ¬OµLªk¹w´úªº¦Ó¥B¸¨ÂI±o§¡¤Ã¤À¥¬¡A¤]´N¬O»¡¦b¨C­Óµ¥¤j½d³ò¤º¥X²{ªº¦¸¼Æ³£À³¸Ó¬Û¦P¡CTSTRND.ASM ·|°õ¦æ rdrand ¥¨¶°¦Ó¥Í¦¨ 65536 ­Ó¶Ã¼Æ¡A¨Ì¾Ú¨ä¤j¤p±N¥¦­Ì¤À¦¨¤Q¤»­Ó½d³ò¡A¨ÃÅã¥Ü¸¨¦b¨C­Ó½d³òªº¶Ã¼Æ­Ó¼Æ¡C³oºØ¤èªk¥i¥H¥Î¤H¤u¨Ó§PÂ_ CPU ªº RDRAND «ü¥O¬O§_¯à²£¥Í¸¨ÂI¤À§G§¡¤Ãªº¶Ã¼Æ¡A·íµM³o¬O³Ì²Ê²Lªº¤è¦¡¡AÁÙ¥i¥H§ó²`¤J¡A¦ý³o¤w¶W¥X²Õ¦X»y¨¥±Ð¾Çªº½d³ò¡C

³o¤@³¹°£¤FÀË´ú CPU ¥Í¦¨ªº¶Ã¼Æ«~½è¤§¥~¡AÁÙ¦³¤@«GÂI¡A¨º´N¬OÅý¤£¤ä´© RDRAND «ü¥Oªº MASM 6.11¡A¯à¥¿±`²ÕĶ¦¹«ü¥O¡A¨Ã¥B¯à¥¿±`°õ¦æ¡C³o­Ó·Qªk¬O¤p¤ì°¸¦Û¦æ·Q¥X¨Óªº¡A¨Ã¨S¦³¬Ý¨£¨ä¥L¦a¤è¦³³o¼Ëªº·Qªk¡C·íµM¡A¦³¥i¯à¬O¤p¤ì°¸©t­®¹è»D¡A¤]¥i¯à¬OÁÙ¦b¥Î MASM 6.11 ªº¤H¥»´N¤Ö¤F¡A©Ò¥H´X¥G¨S¤°»ò¤H·|¥h·Q¦p¦ó¼W¶i MASM 6.11 ªº¥\¯à¡C