¥Á°ê 70 ¦~¡A°ê»Ú°Ó·~¾÷¾¹¤½¥q¡]IBM¡^¶}©l¥X²£ IBM PC Ó¤H¹q¸£®É¡A¨º®É¦b IBM PC µwÅ餺³¡´N¦³¤@Ó½s¸¹¬O 8253 ªº´¹¤ù¡A±Mªùt³dp®É¡C³oÓ´¹¤ù¥HÀW²v 18.2Hz ªº¤è¦¡²£¥Í²Ä 8 ¸¹¤¤Â_¡]18.2Hz ªº·N«ä´N¬O»¡¨C¬íIJµo²Ä 8 ¸¹¤¤Â_ 18.2 ¦¸¡^¡A´«¥y¸Ü»¡¨C¹j 55 ²@¬í¡]1¡Ò18.2≑0.0549¡^´N°õ¦æ¤@¦¸²Ä 8 ¸¹¤¤Â_¡CIBM PC ¦@¦³ 256 Ó¤¤Â_¡A½s¸¹¥Ñ¹s¶}©l¨ì¤Q¤»¶i¦ìªº 0FFH¡A§ÚÌ¥i¥H§â¤¤Â_·Q¦¨¬O¬YºØ°Æµ{¦¡¡C
¨ì¤F²{¦b¡A8253 ´¹¤ù¤w¸g³Q°ªºë«×¨Æ¥óp®É¾¹¡]high precision event timer¡AÁY¼g HPET¡^¨ú¥N¡A¨Ã¾ã¦X¨ì¤F«n¾ô´¹¤ù¤¤¡A¦ý«n¾ô´¹¤ù¤]«O¯d¤F 8253 ªº¥\¯à¡C¦]¦¹²{¦bªº¹q¸£¡A¤´µM¯à°õ¦æ¥H«eªº§@·~¨t²Î¡A¨Ò¦p MS¡ÐDOS¡A¥un§A¯à§ä¨ì¶}¾÷®É±Ò°Êªº¤èªk¡C
¦b¤j³¡¤Àªº±¡§Î¤U¡A§Ṳ́£»Ýnºë±K«×«Ü°ªªºp®É¾¹¡A¨C 55 ²@¬íIJµo¤@¦¸ªººë±K«×¤w¸g¨¬°÷¤F¡C³o¤@³¹n¤¶²Ð¦b Windows §@·~¨t²Î¤¤ªºp®É¾¹¡A¨Ã»¡©ú¦p¦óÀ³¥Î¡C
¦b Windows §@·~¨t²Î¤¤¡Ap®É¾¹¥i¥H¬Ý°µ¬O¤@ºØ¿é¤J³]³Æ¡A§ÚÌ¥i¥H«ü©w¥¦¨C¹j¤@¬q©T©wªº®É¶¡¶¡¹j¡A¹ïÀ³¥Îµ{¦¡µo¥X WM_TIMER °T®§¡C¥E¬Ý¤§¤U¡Ap®É¾¹¦ü¥G¤£¹³Áä½L¡B·Æ¹«¨º»ò«n¡A¦ý¬O¥¦¤]¦³¤@¨Ç¤£¥i¿i·Àªº°^Äm¡A¨Ò¦p¡G
¥H¤W¬Op®É¾¹ªºÀ³¥Î¡A¨º»òn¦p¦ó¨Ï¥Îp®É¾¹©O¡Hº¥ý¡A§ÚÌ¥²¶·¥ý«Ø¥ßp®É¾¹¡C
¦b Windows §@·~¨t²Î¤¤¡AÀ³¥Îµ{¦¡µLªkª½±µÅª¨ú²Ä 8 ¸¹¤¤Â_¡A³o¨ÇµwÅé¸ê·½³£¥Ñ Windows ²ÎÄw¹B¥Î¡CÀ³¥Îµ{¦¡¥²¶·³z¹L Windows ¨Ó¨Ï¥Î³o¨ÇµwÅé¸ê·½¡A¥i¥H©I¥s SetTimer¡A«Ø¥ßp®É¾¹¡CWindows ·|¬°¦¹p®É¾¹«Ø¥ß¤@Óp¼Æ¾¹¨Ãªì©l¥¦¡AµM«á¨C¹j 55 ²@¬íp¼Æ¾¹«K´î¤@¡Aª½¨ì´î¦Ü¹s¡A«K¹ïÀ³¥Îµ{¦¡µo¥X WM_TIMER °T®§¡CÀ³¥Îµ{¦¡¦¬¨ì WM_TIMER °T®§«á¡A«K¯à¦b³B²z¦¹°T®§°µ¤@¨Ç¤u§@¡C©³¤U¬O SetTimer ªº¥Îªk¡G
invoke SetTimer,\ hWnd,\ ; handle of window for timer messages nIDEvent,\ ; timer identifier uElapse,\ ; time-out value lpTimerFunc ; address of timer procedure
¤j³¡¤Àªº±¡§Î¤U¡AlpTimerFunc ¬°¹s¡A¨º»ò Windows ¨C¹j¤@¬q®É¶¡¶¡¹j¡]¦¹®É¶¡¶¡¹j¥Ñ²Ä¤TÓ°Ñ¼Æ uElapse «ü©w¡^´N·|§â WM_TIMER µo°eµ¹©I¥s SetTimer ®É²Ä¤@ӰѼƩҫü©wªºµøµ¡¡Cµo°eªº WM_TIMER °T®§ùتº wParam µ¥©óp®É¾¹ÃѧO½X¡A¤]´N¬O©I¥s SetTimer ®Éªº²Ä¤GӰѼơF¦ÓlParam µ¥©ó¹s¡C¦]¬°¥i¥H¦b¦PÓÀ³¥Îµ{¦¡¤¤¥Î¦hÓ¤£¦Pªº nIDEvent ¨Ó¦h¦¸©I¥s SetTimer¡A¦p¦¹´N«Ø¥ß¦hÓp®É¾¹¡A³o¼Ë´Nn¥Î wParam ¤À¿ë¤£¦Pªºp®É¾¹¡C¨ä®æ¦¡¦p¤U¡G
invoke SetTimer,hwnd,TIMER_SEC,1000,0 ;«Ø¥ß¨C¬í°e¥X WM_TIMER ªºp®É¾¹ invoke SetTimer,hwnd,TIMER_MIN,60000,0 ;«Ø¥ß¨C¤À°e¥X WM_TIMER ªºp®É¾¹ ⁝ case WM_TIMER: switch wParam case TIMER_SEC: ;¨C¬í¤@¦¸ªº³B²z case TIMER_MIN: ;¨C¤ÀÄÁ¤@¦¸ªº³B²z endsw ⁝
°²¦p²Ä¥|Ó°Ñ¼Æ lpTimerFunc ¤£¬O¹s¡A¦Ó¬O¬YӰƵ{¦¡¦ì§}ªº¸Ü¡A¨º»ò Windows ¨C¹j¤@Ӯɶ¡¶¡¹j¡A¤£¦A¬Oµo°e WM_TIMER °T®§µ¹©I¥s SetTimer ®É²Ä¤@ӰѼƩҫü©wªºµøµ¡¡A¦Ó¬O©I¥s¸Ó°Æµ{¦¡¤@¦¸¡C¥Ñ¦¹¬Ý¨Ó¡A¦¹°Æµ{¦¡¨ä¹ê¬O¤@ºØ¦^©I¨ç¦¡¡C°²³]¦¹¦^©I¨ç¦¡¦WºÙ¬O TimerProc¡A¨ä쫬¬°¡G
TimerProc PROC hwnd:HWND, message:UNIT, iTimerID:UNIT, dwTime:DWORD
; ³o¨à¬O¨C¹j¤@Ӯɶ¡¶¡¹jn³B²zªº¤u§@
TimerProc ENDP
Windows ¶Çµ¹ TimerProc ªº²Ä¤@Ó°Ñ¼Æ hwnd¡A¨ä¹ê´N¬O©I¥s SetTimer ®Éªºµøµ¡¥N½X¡Amessage ©l²×¬O WM_TIMER¡AiTimerID ¬O©I¥s SetTimer ®Éªº¦^¶ÇÈ¡AdwTimer ¬O±Ò°Ê Windows ®É¤w¸g¹L¦h¤Ö²@¬í¡C
¦pªGp®É¾¹«Ø¥ß¥¢±Ñ¡A¦^¶ÇȬ°¹s¡C¦pªG¦¨¥\«Ø¥ßp®É¾¹¡A¨ä¦^¶ÇȤS¤À¨âºØ±¡§Î¡G
²Ä¤TӰѼƬO®É¶¡¶¡¹j¡AÁöµM³æ¦ì¬O²@¬í¡A¦ý¬O¥Ñ©ó³\¦h¦]¯À¡AµLªkºë½T¨ì¤@²@¬í¡A¦]¦¹¦pªG¯unºë½Tp®É¡A³Ì¦n¤£n¨Ï¥Î SetTimes p®É¾¹¡C¦pªG uElapse ¤p©ó USER_TIMER_MINIMUM¡]USER_TIMER_MINIMUM¡×0AH¡^¡A«h uElapse ·|³]¬° USER_TIMER_MINIMUM¡F¦pªG uElapse ¤j©ó USER_TIMER_MAXIMUM¡]USER_TIMER_MINIMUM¡×07FFFFFFFH¡^¡A«h uElapse ·|³]¬° USER_TIMER_MAXIMUM¡C
·í¥Î¤£µÛp®É¾¹®É¡A©Î¬Oµ{¦¡µ²§ô®É¡A¥²¶·±Np®É¾¹¾P·´¡C¾P·´p®É¾¹ªº¤èªk¬O©I¥s KillTimer¡A¨ä»yªk¦p¤U¡G
invoke KillTimer,\ hWnd,\ ; handle of window that installed timer uIDEvent ; timer identifier
¦pªG KillTimer ¦¨¥\¾P·´p®É¾¹¡A¦^¶ÇȬ°«D¹s¡F¥¢±Ñ¡A¦^¶ÇȬ°¹s¡C
©³¤U¹ê§@¤@Ó¨Ò¤l¡A»¡©úp®É¾¹ªº¥Îªk¡C³oÓ¨Ò¤l¬O RNDLINE1.ASM¡A¥¦·|¦bµøµ¡ªº¤u§@°Ï¤º¥H¥ª¤W¨¤¬°°_ÂI¡AÀH¾÷¨ú¤@ÂI¬°²×ÂIø¥X¤@ÓÀH¾÷ÃC¦âªº½u¬q¡A¦Ó«á§â¸Ó½u¬qªº²×ÂI§@¬°¥t¤@½u¬qªº°_ÂI¡A¦AÀH¾÷¨ú¤@ÂI¬°²×ÂIø¥X²Ä¤GÓÀH¾÷ÃC¦âªº½u¬q¡A¦p¦¹¤@ª½«½Æª½¨ì¨Ï¥ÎªÌÃö³¬ RNDLINE1 ¬°¤î¡C
RNDLINE1.ASM ²o¯A¨ì·í«e¹³¯À¡Bø»s½u¬q¤Î±m¦â¤å¦r¡A¦]¦¹¥ý¸É¥R¦³Ãö³o¤è±ªºª¾ÃÑ¡C©³¤U©Òn½Í½×ªº¬O GDI ª«¥ó¤§¤@¡Aµeµ§¡Cµeµ§»Pµe¨ê¬Û¦ü¡An¥ý«Ø¥ß«á¤~¯à¨Ï¥Î¡Aµeµ§¬O¥Î¨Óµe¥X½u¬q¡B¦±½u©Î¬O¹Ï§Î¡]¨Ò¦p¯x§Î¡B¾ò¶êµ¥¡^¡C
CreatePen ¯à¥Î«ü©wªº·®æ¡B¼e«×¥H¤ÎÃC¦â«Ø¥ßÅÞ¿èµeµ§¡CCreatePen ªºì«¬¬O¡G
invoke CreatePen,\ fnPenStyle,\ ; pen style nWidth,\ ; pen width crColor ; pen color
±`¼Æ | »¡©ú |
PS_SOLID | µeµ§µe¥Xªº¬O¹ê½u |
PS_DASH | µeµ§µe¥Xªº³\¦hµu½u²Õ¦¨ªº½u¬q |
PS_DOT | µeµ§µe¥Xªº¬Oµê½u |
PS_DASHDOT | µeµ§µe¥Xªº¬Oµu½u¡BÂI¡Bµu½u¡BÂI¡K¡K²Õ¦¨ªº½u¬q |
PS_DASHDOTDOT | µeµ§µe¥Xªº¬Oµu½u¡BÂI¡BÂI¡Bµu½u¡BÂI¡BÂI¡K¡K²Õ¦¨ªº½u¬q |
PS_NULL | Áô§Îªºµeµ§¡A¤]´N¬O»¡µe¤£¥X½uÂ_¨Ó¡A¶È²¾°Ê·í«e¹³¯À |
PS_INSIDEFRAME | ³oºØµeµ§¥u¦³¦bµeµ§¼e«×¤j©ó¤@¡A¥Bø»s«Ê³¬¹Ï§Î¡A¨Ò¦p¯x§Î¡B¾ò¶ê¤~¯à¨£¨ì®ÄªG¡A¦¹®ÄªG¬O±N¹Ï§ÎªºÃä½u©¹¤¤¶¡ÂX®i¡AÃä½u¥~½t´N¬O«Ê³¬¹Ï§Îªº¥~½t¡C |
¦pªG¦¨¥\«Ø¥ßÅÞ¿èµeµ§¡A¦^¶ÇȬO¦¹ÅÞ¿èµeµ§ªº¥N½X¡A¨º»ò¥i¥H¥Î¦¹ÅÞ¿èµeµ§¥N½X¬°°Ñ¼Æ¡A©I¥s SelectObject ±N¦¹ÅÞ¿èµeµ§¿ï¤J¸Ë¸m¤º®e¡Cº¸«áµe¥Xªº½u¬q¡B¦±½u³£¬O¥Î³oÓÅÞ¿èµeµ§Ã¸»s¡C»P«e¤@³¹µe¨ê¤@¼Ë¡A·í©Ò«Ø¥ßªºµeµ§¤£¥Î®É¡A¥²¶·©I¥s DeleteObject §R°£¡A¥H¸`¬Ù¸ê·½¡C¦pªG«Ø¥ßÅÞ¿èµeµ§¥¢±Ñ¡ACreatePen ªº¦^¶ÇȬO 0¡C
SelectObject ¨Ï¸Ë¸m¤º®e¤ºªº GDI ª«¥ó³]©w¬°·s«ü©wªº GDI ª«¥ó¡C¨Ò¦p¥i¥H©I¥s SelectObject ±N¸Ë¸m¤º®e¤¤Â¦³ªºµeµ§¡A¥H·s«Ø¥ß¦nªºµeµ§¨ú¥N¡CSelectObject ªºì«¬¬O¡G
invoke SelectObject,\ hdc,\ ; handle to DC hgdiobj ; handle to object
¯à°÷³Q SelectObject ¿ï¤Jªº GDI ª«¥ó¦³¤U±´XºØÃþ«¬¡G①¦ì¤¸¹Ï¡]bitmap¡^¡B②µe¨ê¡]brush¡^¡B③¦r§Î¡]font¡^¡B④µeµ§¡]pen¡^¡B⑤°Ï°ì¡]region¡^¡C
¦pªG SelectObject ªº²Ä¤GӰѼƤ£¬O°Ï°ì¡A¦Ó SelectObject ¤S°õ¦æ¥¢±Ñ¡A¨º»ò¦^¶ÇȬ°¹s¡F¦pªG°õ¦æ¦¨¥\¡A¦^¶ÇȬOì¥ý GDI ª«¥ó¥N½X¡C¦pªG SelectObject ªº²Ä¤GӰѼƬO°Ï°ì¡A¦Ó SelectObject ¤S°õ¦æ¥¢±Ñ¡A¨º¼¯¦^¶ÇȬO HGDI_ERROR¡F¦pªG°õ¦æ¦¨¥\¡A¨º»ò¦^¶ÇȬO¤U¦C¤§¤@¡G
·íµ{¦¡©I¥s BeginPaint ©Î GetDC ¥HÀò±oµøµ¡¤u§@°Ïªº¸Ë¸m¤º®e¥N½X®É¡A·|±N¤u§@°Ï¥ª¤W¨¤·í°µ·í«eªº¹³¯À¡]¹³¯À^¤å¬O pixel¡A¥i¥H¬Ý¦¨¬O¿Ã¹õ¤WªºÂI¡^¡A¦Ó MoveToEx ¥i¥H§â·í«e¹³¯À²¾¨ì«ü©wªº¹³¯À¤W¡CMoveToEx ªºì«¬¬O¡G
invoke MoveToEx,\ hdc,\ ; handle of device context X,\ ; x-coordinate of new current position Y,\ ; y-coordinate of new current position lpPoint ; address of old current position
¦pªG MoveToEx ¦¨¥\³]©w·í«e¹³¯À¡A¦^¶ÇȬ°«D¹s¡F¦pªG¥¢±Ñ¡A¦^¶ÇȬ°¹s¡C
LineTo ¥i¥H§â·í«e¹³¯À»P«ü©wªº²×ÂI¹³¯À¨âÂI³s±µ°_¨Ó¡Aø¥X¤@½u¬q¨Ó¡CLineTo ªºì«¬¬O¡G
invoke LineTo,\ hdc,\ ; device context handle nXEnd,\ ; x-coordinate of line's ending point nYEnd ; y-coordinate of line's ending point
LineTo ·|¥Î·í«eªºµeµ§Ã¸¥X½u¬q¡A·í«eµeµ§¥i¥H¥Î©I¥s CreatePen¡BCreatePenIndirect µ¥ API «Ø¥ß¡AµM«á¥H SelectObject ¿ï¤J¨ì¸Ë¸m¤º®e¤¤¡CLineTo ¦pªG¦¨¥\ø¥X½u¬q¡A¨º»ò¦^¶ÇȬ°«D¹s¡A¦P®É·í«e¹³¯À³]©w¬° nXEnd¡BnYEnd ©Ò«üªº¹³¯À¡F¦pªG¥¢±Ñ¡A¦^¶ÇȬ°¹s¡C
SetTextColor ±N«ü©wªº¸Ë¸m¤º®eªº¤å¦r³]©w¬°¬YºØÃC¦â¡C¨ä쫬¬°¡G
invoke SetTextColor,\ hdc,\ ; handle of device context crColor ; text color
¦pªG¦¨¥\³]©w¤å¦rÃC¦â¡A¦^¶ÇȬ°ì¨Óªº¤å¦rÃC¦â¡F¦pªG¥¢±Ñ¡A¦^¶ÇȬ° CLR_INVALID¡A¥i¥H©I¥s GetLastError ±o¨ì§ó¶i¤@¨Bªº¿ù»~ì¦]¡C
©³¤U¬O RNDLINE1.ASM ì©lµ{¦¡ªº§¹¾ã¦Cªí¡C
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
113 114 115 116
117 118 119 120
121 122 123 124
125 126 127 128
129 130 131 132
133 134 135 136
137 138 139 140
141 142 143 144
145 146 147 148
149 150 151 152
153 154 155 156
157 158 159 160
161 162 163 164
165 166 167 168 |
;RNDLINE1.ASM¡G¦b¿Ã¹õ¤WÅã¥Üµøµ¡¡A§Q¥Îp®É¾¹¨C¹j¤@¬q®É¶¡¡A¦bµøµ¡¤ºÀH¾÷ø»s½u¬q
;²ÕĶ¤è¦¡¡G
;SET INCLUDE=C:\UASM\Include
;SET LIB=C:\UASM\lib64
;SET PATH=C:\UASM;C:\UASM\bin64;
;SET LINK=/SUBSYSTEM:WINDOWS
;UASM64 -win64 RNDLINE1.ASM
;LINK RNDLINE1.OBJ
OPTION CASEMAP:NONE
OPTION WIN64:3
INCLUDE WINDOWS.INC
INCLUDELIB GDI32.LIB
INCLUDELIB KERNEL32.LIB
INCLUDELIB USER32.LIB
TIMER_ID EQU 1000 ;p®É¾¹ÃѧO½X
;*******************************************************************************
.CONST
szClassName DB "RndLine1",0 ;µøµ¡Ãþ§O¦WºÙ
szAppName DB "½u¬q",0
szErr DB "¿ù»~",0
szFmt DB "%d Lines",0
szErrMsg0 DB "CPU¤£¤ä´©¡C",0
szErrMsg1 DB "µù¥Uµøµ¡Ãþ§O¥¢±Ñ¡C",0
;*******************************************************************************
.DATA
hInstance HINSTANCE ? ;¼Ò²Õ¥N½X
hWnd HWND ? ;µøµ¡¥N½X
iWidth DD ? ;¤u§@°Ï¼e«×
iHeight DD ? ;¤u§@°Ï°ª«×
cLines DD ?
pnt POINT <0,0>
;*******************************************************************************
.CODE
;-------------------------------------------------------------------------------
;»s³y¤@¶Ã¼Æ¡A¥B¤p©órange¡AµM«á¦s©óEAX«áªð¦^
get_rnd PROC range:DWORD
mov ecx,30
bsr eax,range ;¥H¤G¶i¦ìªí¥Ürange¡A³Ì°ª¦ì¤¸¬°1ªº¦b²ÄEAX¦ì¤¸
mov r11d,7fffffffh ;¨Ï²Å¸¹¦ì¤¸¬°0
sub ecx,eax ;ECX¡×R11Dªº²Å¸¹¦ì¤¸n¥k²¾¦h¤Ö¦¸
sar r11d,cl ;°õ¦æ¥k²¾CL¦¸
retry: rdrand eax
and eax,r11d
cmp eax,range
ja retry
ret
get_rnd ENDP
;-------------------------------------------------------------------------------
DrawLine PROC hwnd:HWND
LOCAL hdc:HDC,hPen:HPEN,buffer[16]:BYTE,text_color:DWORD
;Àò±oµøµ¡ªº¸Ë¸m¤º®e
invoke GetDC,hwnd
mov hdc,rax
;«Ø¥ßÀH¾÷ªºÃC¦â¡A¥H¦¹ÃC¦â«Ø¥ßµeµ§¡A¨Ã³]©w¤å¦rÃC¦â
invoke get_rnd,0ffffffh
mov text_color,eax
invoke CreatePen,PS_SOLID,3,eax
mov hPen,rax
invoke SetTextColor,hdc,text_color
;§â·s«Ø¥ßªºµeµ§¿ï¤J¸Ë¸m¤º®e¤¤
invoke SelectObject,hdc,hPen
;§â·í«e¹³¯À³]¬°¤W¦¸½u¬q²×ÂI
invoke MoveToEx,hdc,pnt.x,pnt.y,0
;¦b¤u§@°Ï¤ºÀH¾÷¿ï¾Ü¤@ÂI¡A¨Ã¦s¤Jpnt¡A¥H§@¬°¤U¦¸ªº°_ÂI
invoke get_rnd,iWidth
mov edx,eax
mov pnt.x,eax
invoke get_rnd,iHeight
mov pnt.y,eax
;§â·í«eªºÂI¡]¤W¦¸½u¬q²×ÂI¡^»PÀH¾÷¿ï¾ÜªºÂI³s±µ°_¨Ó¡A§Î¦¨½u¬q
invoke LineTo,hdc,edx,eax
inc cLines
;¦b¤u§@°Ï¥k¤U¨¤Åã¥Ü¤wµe¥Xªº½u¬qÓ¼Æ
invoke SetTextAlign,hdc,TA_BOTTOM or TA_RIGHT
invoke wsprintf,ADDR buffer,OFFSET szFmt,cLines
invoke TextOut,hdc,iWidth,iHeight,ADDR buffer,eax
invoke DeleteObject,hPen
invoke ReleaseDC,hwnd,hdc
ret
DrawLine ENDP
;-------------------------------------------------------------------------------
WndProc PROC hwnd:HWND, uMsg:UINT, wParam:WPARAM, lParam:LPARAM
.switch uMsg
.case WM_CREATE
invoke SetTimer,hwnd,TIMER_ID,330,0
.case WM_TIMER
invoke DrawLine,hwnd
.case WM_SIZE
mov r10,lParam
mov r11,lParam
and r10,0ffffh
shr r11,10h
mov iWidth,r10d
mov iHeight,r11d
mov cLines,0
.case WM_DESTROY
invoke KillTimer,hwnd,TIMER_ID
invoke PostQuitMessage,0
.default
invoke DefWindowProc,hwnd,uMsg,wParam,lParam
ret
.endsw
xor rax,rax
ret
WndProc ENDP
;-------------------------------------------------------------------------------
;check_rdrand¥Î¨ÓÀˬdCPU¬O§_¤ä´©RDRAND¡A¦pªG¤ä´©¦^¶ÇȬ°1¡F¤£¤ä´©¦^¶ÇȬ°0
check_rdrand PROC
;¨Ã¤£¬O©Ò¦³ªºCPU³£¤ä´©RDRAND«ü¥O¡A©Ò¥H¦b¨Ï¥Î«en¥ý¶i¦æÀË´ú¡G§âEAX¼È¦s¾¹¸m1¨Ã°õ¦æ
;CPUID«ü¥O¡A¦pªG¤ä´©RDRANDªº¸Ü¡AECX¼È¦s¾¹ªº²Ä30¦ì¤¸¦ì·|³Q¸m¬°1¡C
mov rax,1
cpuid
test ecx,40000000h
jnz support_rdrand
xor rax,rax
support_rdrand: ret
check_rdrand ENDP
;-------------------------------------------------------------------------------
main PROC
LOCAL wc:WNDCLASSEX,msg:MSG
call check_rdrand ;ÀˬdCPU¬O§_¤ä´©RDRAND
lea rdx,szErrMsg0
or rax,rax ;YRAX¡×0¡A¤£¤ä´©¡A¸õ¦Üerror:³B
jz error
invoke GetModuleHandle,0 ;¨ú±o¼Ò²Õ¥N½X
mov hInstance,rax
mov wc.cbSize,SIZEOF WNDCLASSEX
mov wc.style,CS_HREDRAW or CS_VREDRAW
lea rdx,WndProc
mov wc.lpfnWndProc,rdx
mov wc.cbClsExtra,0
mov wc.cbWndExtra,0
mov wc.hInstance,rax
invoke LoadIcon,NULL,IDI_APPLICATION ;¨ú±o¹Ï¥Ü¥N½X
mov wc.hIcon,rax ;¦s¤J¹Ï¥Ü¥N½X
mov wc.hIconSm,rax ;¦s¤J¤p¹Ï¥Ü¥N½X
invoke LoadCursor,NULL,IDC_ARROW ;¨ú±o´å¼Ð¥N½X
mov wc.hCursor,rax ;¦s¤J´å¼Ð¥N½X
mov wc.hbrBackground,COLOR_WINDOW+1
mov wc.lpszMenuName,0
lea rdx,szClassName
mov wc.lpszClassName,rdx
invoke RegisterClassEx,ADDR wc ;µù¥Uµøµ¡Ãþ§O
lea edx,szErrMsg1
.if rax==0
error: invoke MessageBox,0,rdx,OFFSET szErr,MB_ICONERROR or MB_OK
jmp quit
.endif
invoke CreateWindowEx,0,ADDR szClassName,ADDR szAppName,WS_OVERLAPPEDWINDOW,\
CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,0,0,hInstance,0
mov hWnd,rax
invoke ShowWindow,hWnd,SW_SHOWNORMAL
invoke UpdateWindow,hWnd
.while TRUE
invoke GetMessage,ADDR msg,0,0,0
.break .if rax==0
invoke TranslateMessage,ADDR msg
invoke DispatchMessage,ADDR msg
.endw
quit: invoke ExitProcess,0 ;µ{¦¡µ²§ô
main ENDP
;*******************************************************************************
END main |
RNDLINE1.ASM ²Ä 81 ¦æ¡A¦b³B²z WM_CREATE °T®§®É¡A«Ø¥ß¤F¨C¹j 330 ²@¬íµo°e WM_TIMER °T®§µ¹µøµ¡¨ç¦¡ªºp®É¾¹¡C¦b³B²z WM_DESTROY °T®§®É¡A©I¥s KillTimer §R°£¦¹p®É¾¹¡A¦]¬°¦¹¨è§Y±N°h¥Xµ{¦¡¡Ap®É¾¹¤]´N¨S¥Î¤F¡C
¦b RNDLINE1 °õ¦æ¹Lµ{¤¤¡AWindows ·|¨C¹j 330 ²@¬í¡Aµo¥X WM_TIMER °T®§µ¹µøµ¡¨ç¦¡¡Cµøµ¡¨ç¦¡¦b³B²z³o«h°T®§®É¡A©I¥s DrawLine °Æµ{¦¡¡C¦b DrawLine °Æµ{¦¡¤¤¡A¥ýÀò±o¸Ë¸m¤º®e¥N½X¡]²Ä 53¡ã55 ¦æ¡^¡AµM«á¥H¶Ã¼Æ»s³y¥ô·N¤@ºØÃC¦â¡Aµ¥·|¨à·|¥Î³oºØÃC¦âµe½u¨ÃÅã¥Ü¤wµe¥X´X±ø½uªº¤å¦r¡C©Ò¥Hºò±µµÛ²Ä 56¡ã63 ¦æ´N¬O©I¥s CreatePen «Ø¥ßÅÞ¿èµeµ§»P©I¥s SetTextColor ³]©w¤å¦rÃC¦â¡AµM«á¬O©I¥s SelectObject ±N¸Ë¸m¤º®eªºµeµ§³]©w¬°è¤~«Ø¥ßªºµeµ§¡C
¥»¨Ó±µ¤U¨Ó´N¬On©I¥s LineTo µe¥X½u¬q¡ALineTo ©Òµe¥Xªº½u¬q¬O§â·í«e¹³¯À»P¥Ñ¶Ã¼Æ§Î¦¨ªº X¡BY ®y¼Ð©Ò¥Nªíªº¹³¯À³s±µ°_¨Ó¡C¦ý¬O¦]¬°¨C¦¸©I¥s GetDC «á¡AWindows ³£·|§â·í«e¹³¯À³]¬°¥ª¤W¨¤¡A¦pªGª½±µ©I¥s LineTo µe½u¬qªº¸Ü¡A¨º»ò¨C¦¸ªº½u¬q°_ÂI³£¬O¥ª¤W¨¤¡A³o¨Ã¤£²Å¦Xì¨Óªº·Qªk¡C¸Ñ¨Mªº¤èªk´N¬O§â«e¦¸ªº²×ÂI«O¦s°_¨Ó¡A¦b©I¥s LineTo ¤§«e¡A¥ý©I¥s MoveToEx ±N·í«e¹³¯À³]¬°«e¦¸²×ÂI¡A³o¼Ëµe¥X¨Óªº½u¬q´N¯àº§À¬Û³s¡C
«e¦¸²×ÂI«O¦s¦b pnt ÅܼÆùØ¡A³oÓÅܼƨä¹ê¬O¤@Ó POINT µ²ºcÅé¡Cµ{¦¡¤@¶}©l®É¡A¬°¤u§@°Ïªº¥ª¤W¨¤¡A¨ä®y¼Ð¬O ( 0, 0 )¡A¨£²Ä 33 ¦æ¡C¨C¦¸©I¥s DrawLine ®É¡A³£·|ÀH¾÷«ü©w¤@Ó¹³¯À¡A§@¬°½u¬qªº²×ÂI¡ARNDLINE1 ¤]¥²¶·±N³oÓ¹³¯Àªº®y¼Ð«O¦s¤U¨Ó¡A¥H§@¬°¤U¦¸½u¬qªº°_ÂI¡C
RNDLINE1.ASM ¤¤ªºp®É¾¹¬O§â WM_TIMER °T®§µo°eµ¹µøµ¡¨ç¦¡¡A¦ý¬O¤]¥i¥HÅý Windows ±N WM_TIMER °T®§µo°eµ¹¬YÓ¦^©I¨ç¦¡¡C©³¤Uªº RNDLINE2.ASM ´N¬O³o¼Ëªº¨Ò¤l¡C¤£¹L¤p¤ì°¸¤£¥´ºâ§â¥¦§¹¾ãªº¦C¥X¨Ó¡A¥u¦C¥X«nªº³¡¤À¡C
1 2 3 4
5 6 7 8
9 10 ⁝ 50
51 52 ⁝ 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 ⁝ 164 165 |
;RNDLINE2.ASM¡G¦b¿Ã¹õ¤WÅã¥Üµøµ¡¡A§Q¥Îp®É¾¹¨C¹j¤@¬q®É¶¡¡A¦bµøµ¡¤ºÀH¾÷ø»s½u¬q
;²ÕĶ¤è¦¡¡G
;SET INCLUDE=C:\UASM\Include
;SET LIB=C:\UASM\lib64
;SET PATH=C:\UASM;C:\UASM\bin64;
;SET LINK=/SUBSYSTEM:WINDOWS
;UASM64 -win64 RNDLINE2.ASM
;LINK RNDLINE2.OBJ
OPTION CASEMAP:NONE
OPTION WIN64:3
⁝
;-------------------------------------------------------------------------------
DrawLine PROC hwnd:HWND, uMsg:UINT, iTimerID:WPARAM, dwTime:LPARAM
LOCAL hPen:HPEN,hdc:HDC,buffer[16]:BYTE,text_color:DWORD
⁝
DrawLine ENDP
;-------------------------------------------------------------------------------
WndProc PROC hwnd:HWND, uMsg:UINT, wParam:WPARAM, lParam:LPARAM
.switch uMsg
.case WM_CREATE
invoke SetTimer,hwnd,TIMER_ID,330,OFFSET DrawLine
.case WM_SIZE
mov r10,lParam
mov r11,lParam
and r10,0ffffh
shr r11,10h
mov iWidth,r10d
mov iHeight,r11d
mov cLines,0
.case WM_DESTROY
invoke KillTimer,hwnd,TIMER_ID
invoke PostQuitMessage,0
.default
invoke DefWindowProc,hwnd,uMsg,wParam,lParam
ret
.endsw
xor rax,rax
ret
WndProc ENDP
;-------------------------------------------------------------------------------
⁝
;*******************************************************************************
END main |
³Ì«n¤£¦P¬O²Ä 87 ¦æ¡ASetTimer ªº³Ì«á¤@ӰѼƧ令¡uOFFSET DrawLine¡v¡A³o¼Ë´N·|¨Ï Windows ±N WM_TIMER °T®§µo°eµ¹ DrawLine °Æµ{¦¡¡C¥¿¦]¬°¦p¦¹¡A¾ãÓµøµ¡¨ç¦¡¡A±q²Ä 83¡ã108 ¦æ¡A³£¤£»Ý³B²z WM_TIMER¡C¦Ó DrawLine ¬O³Q Windows §@·~¨t²Î©Ò©I¥s¡A¦]¦¹¬O¦^©I¨ç¦¡¡CWindows ¶Ç¨Óªº°Ñ¼Æ¦³¥|Ó¡AÁöµM¥u¦³²Ä¤@Ó°Ñ¼Æ hwnd ¥Î±oµÛ¡A²Ä¤GÓ°Ñ¼Æ uMsg ¥²©w¬O WM_TIMER¡A¨ä¥L¨âӰѼƦb³oÓµ{¦¡¤¤¥Î¤£¨ì¡A¦ýÁÙ¬O±N¨ä¥þ³¡¦C¥X¨Ó¡A¨£ RNDLINE2.ASM ²Ä 51 ¦æ¡C
¦h¤u¬O¦b¤@¬q®É¶¡¤º¦P®É°õ¦æ¦hÓµ{¦¡¡]ºë½TªºÁ¿ªk¬O¦æµ{¡Aprocess¡^¡C¬YÓµ{¦¡¥i¥H¦b¥¿¦b°õ¦æªºµ{¦¡ÁÙ¨Sµ²§ô¤§«e¡A´N°õ¦æ¦Ó«áªÌ·|¤¤Â_¦ý¤£¤@©w¬Oµ²§ô¡C¦]¦¹¡A¦h¤u¥i¬Ý¦¨¹q¸£¥H¥æ¿ùªº¤è¦¡°õ¦æ¦hÓµ{¦¡¤ù¬q¡A¦ý¦]¬°¹q¸£°õ¦æ³t«×«Ü§Ö¡A¥H¤HÃþªº¨¤«×¬Ý¨Ó¦ü¥G¬O¦P®É°õ¦æ³\¦hµ{¦¡¡A¦Ó¹ê»Ú¤W¬O³o¨Çµ{¦¡¦@¨É CPU ©M°O¾ÐÅé¡C·íµM¤¤Â_ªºµ{¦¡¥²¶·«O¦s¨äª¬ºA¡]¨Ò¦p°O¾ÐÅ餺®e©M¼È¦s¾¹¤º®e¡^¡AµM«á¤~¯à¸ü¤J¥t¤@Óµ{¦¡¨Ã±N±±¨îÅvÂಾµ¹¥¦¡C
¦h¤u¤À¬°¨âºØ¡G①¨ó½Õ¦¡¦h¤u¡]cooperative multi-tasking¡^»P②Àu¥ýÅv¦¡¦h¤u¡]preemptive multi-tasking¡^¡C
¨ó½Õ¦¡¦h¤u¬O«ü¥¿¦b°õ¦æªºµ{¦¡¥D°Ê¥æ¥X±±¨îÅv¡AµM«á§@·~¨t²Î¦A±N¨ä¥æµ¹¨ä¥Lµ{¦¡¡C³oºØ¦h¤u¦h¥b¬O¥Ñ©ó CPU ¥¼¯à¦³®Ä¤ä´©©Î®Ä¯à¤£°÷¦Óµo®i¥X¨Óªº¦h¤u¡C¦pªG¦³¤@Óµ{¦¡¤£¥æ¦^±±¨îÅv©ÎªÌ·í±¼¤F¡A¨º»ò¾ãÓ§@·~¨t²Î´N·í±¼¤F¡A¥u¦³«·s±Ò°Ê¤@³~¡C¨Ò¦p«Øºc¦b MS¡ÐDOS ¤Uªº Windows 3.1 ´NÄÝ©ó¨ó½Õ¦¡¦h¤u¡C
Àu¥ýÅv¦¡¦h¤u¤]¥s¥ý¦û¦¡¦h¤u¡A¦b³oºØ¦h¤u¤§¤U¡A¨CÓµ{¦¡ªº°õ¦æ®É¶¡¥Ñ§@·~¨t²Î¨Ó¤À°t¡A¤@Óµ{¦¡ªº®É¶¡¨Ï¥Î§¹¤§«á¡A¨t²Î´N·|±N CPU ¤À°tµ¹¤U¤@Óµ{¦¡¡]³oºØ°Ê§@ºÙ¬°context switching¡^¡A¨S¦³¤@Óµ{¦¡¯à¿W¦û CPU¡C³oºØ¦h¤u¤§¤U¡A¤@Óµ{¦¡·í±¼¡A¤£·|¼vÅT¥t¤@Óµ{¦¡¡COS/2¡BWindows NT/2000/XP/Vista/7/8.x/10/11¡BUNIX/Linux/Solaris/Mac-OS ³£ÄÝ©ó³oºØ¦h¤u¤è¦¡¡C