¦b©I¥s°Æµ{¦¡ªº®ÉÔ¡A¦³®É¬ÛÃö¸ê®Æ·|«Å§i¦¨¤@Óµ²ºcÅé¡AµM«á¥H¦¹µ²ºcÅé©w¸qµ²ºcÅéÅܼơA±N¦¹µ²ºcÅéÅܼƧ@¬°°Ñ¼Æ©I¥s°Æµ{¦¡¡C¨º»ò³o®ÉÔ¡A¦³Ó°ÝÃD²£¥Í¤F¡A¦b°Æµ{¦¡¤¤À³¸Ó¦p¦óŪ¨ú©ÎªÌ¼g¤Jµ²ºcÅ餺ªº¦UÄæ¦ì©O¡Hµª®×¬OÂǥѦì§}¡A§âµ²ºcÅéÅܼƪº¦ì§}§@¬°°Ñ¼Æ¶Ç¤J°Æµ{¦¡¡A¦b°Æµ{¦¡¤¤¤]¬O¥H¦UÄæ¦ì¬Û¹ï©óµ²ºcÅé°_©l¦ì§}Ū¨ú©Î¼g¤J¸ÓÄæ¦ì¡C
¦b¤wª¾µ²ºcÅéÅܼƪº°_©l¦ì§}«á¡A¦Ü¤Ö¦³¤TºØ¤èªk¯à¦s¨ú¨ä¤¤ªºÄæ¦ì¡C©³¤U¤p¤ì°¸Á|Ó¨Ò¤l»¡©ú¡A°²³]¦³Ó¥s what_day_is ªº°Æµ{¦¡¡A¥¦ªº¥\¥Î¬Opºâ¥X¬Y¦~¬Y¤ë¬Y¤@¤Ñ¬O¬P´Á´X¡C¥i·Q¦Óª¾¡A¥¦À³¸Ó¦³¤TӰѼơA¤À§O¬O¦~¥÷¡B¤ë¥÷¡B¤é¡A¦ý¤p¤ì°¸·Q¥Î¤@Óµ²ºcÅé¥]§t³o¤Tµ§¸ê®Æ¡A¦]¦¹«Å§i DATE µ²ºcÅé¦p¤U¡G
DATE STRUCT year DW ? ;¦è¤¸¦~¥÷ month DB ? ;¤ë¥÷ day DB ? ;¤é DATE ENDS
²{¦b what_day_is ´N¶È¶È»Ýn¤@ӰѼƧY¥i¡A¨º´N¬O DATE ªº°_©l¦ì§}¡C¨Ò¦p¡Anpºâ¦è¤¸ 2022 ¦~¤C¤ë¤G¤Q¤»¤é¬P´Á´X¡Aµ{¦¡¤ù¬q¦p¤U¡G
.DATA
today DATE {2022,7,26}
.
.
.CODE
what_day_is PROC pdate:WORD ─┐
. ├──what_day_is °Æµ{¦¡¤º¡A¦³Åª¨ú pdate ©Ò«ü¦ì§}ªºµ²ºcÅéÅܼƤº¤§Äæ¦ì
what_day_is ENDP ─┘
.
.
INVOKE what_day_is,OFFSET today
¦b what_day_is °Æµ{¦¡ùØ¡A¥²©wnŪ¨ú today ùتº¤TÓÄæ¦ì¡Cèè¤p¤ì°¸»¡¦Ü¤Ö¦³¤TºØ¤èªk¡G
ASSUME si:PTR DATE mov si,pdate mov ax,[si].year mov bl,[si].month mov cl,[si].day ASUME si:NOTHING
mov si,pdate mov ax,(DATE PTR [si]).year mov bl,(DATE PTR [si]).month mov cl,(DATE PTR [si]).day
mov si,pdate mov ax,[si].date.year mov bl,[si].date.month mov cl,[si].date.day
³o¤TºØ¤èªk¤¤¡A¤£ºÞ¥Îþ¤@ºØ¤èªk¡A¤@¶}©l³£n§â¤@Ó«ü¼Ð©Î¯Á¤Þ¼È¦s¾¹ ( ¨Ò¦p BX¡BSI¡BDI ) «ü¦Vµ²ºcÅé°_©l¦ì§}¡AµM«á¥H¡u.¡v¤À¹jµ²ºcÅé»PÄæ¦ì¦Wªº¤è¦¡¦s¨ú¡C¦]¬°µ²ºcÅé«á±¤wªí©ú¤FÄæ¦ì¡A¦]¦¹²ÕĶ¾¹¯àpºâ¥XÄæ¦ì¶ZÂ÷µ²ºcÅé°_©l¦ì§}¦h¤ÖӦ줸²Õªº°¾²¾¦ì§}¡A³o¤TºØ¤èªk³Ì«á³£·|³Q²ÕĶ¦¨¤@¼Ò¤@¼Ëªºµ{¦¡½X¡G
mov si,pdate mov ax,[si] mov bl,[si+2] mov cl,[si+3]
³o¼Ë§ÚÌ´N¤£»Ýn¦Û¤v¥hpºâÄæ¦ìªº°¾²¾¦ì§}¤F¡C
©³¤U¬O WHATDAY.ASM ªºì©l½X¡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
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 |
.MODEL SMALL,STDCALL
.386
DATE STRUCT
year DW ? ;¦è¤¸¦~¥÷
month DB ? ;¤ë¥÷
day DB ? ;¤é
DATE ENDS
;*******************************************************************************
.STACK
;*******************************************************************************
.DATA
today DATE {?}
str0 DB "Input year : $"
str1 DB 0dh,0ah,"Input month : $"
str2 DB 0dh,0ah,"Input day : $"
str_sunday DB 0dh,0ah,"Sunday$"
str_monday DB 0dh,0ah,"Monday$"
str_tuesday DB 0dh,0ah,"Tuesday$"
str_wednesday DB 0dh,0ah,"Wednesday$"
str_thursday DB 0dh,0ah,"Thursday$"
str_friday DB 0dh,0ah,"Friday$"
str_saturday DB 0dh,0ah,"Saturday$"
error_message DB 0dh,0ah,"Input Arabic numerals only.$"
;*******************************************************************************
.CODE
;-------------------------------------------------------------------------------
print_string PROC pStr:WORD
mov dx,pStr
mov ah,9
int 21h
ret
print_string ENDP
;-------------------------------------------------------------------------------
;¿é¤J0¡ã65535ªº¤Q¶i¦ì¾ã¼Æ¡C
;ªð¦^¡GCX¡×00¡Aµo¥Í¿ù»~
;¡@¡@¡@CX«D¹s¡A¿é¤J¥¿½T¡AAX¡×¨Ï¥ÎªÌ¿é¤Jªº¼ÆÈ
input PROC
LOCAL value:WORD
mov cx,5 ;³Ì¦h¿é¤J¤¦ì
mov value,0 ;¨ÏvalueÂk¹s
.WHILE cx
mov ah,1 ;DOSªA°Èµ{¦¡¡AÁä½L¿é¤J¦r¤¸
int 21h ;AL¡×¿é¤J¦r¤¸ªºASCII½X
.IF (al>="0")&&(al<="9")
sub al,"0"
mov dx,value
shl value,3 ;8*value
shl dx,1 ;2*value
cbw
add value,dx ;value¡×8*value+2*value¡×10*value
add value,ax ;value¡×value¡ÏAX
.ELSEIF al==0dh
jmp finish
.ELSE
jmp short quit1
.ENDIF
dec cx
.ENDW
finish: mov ax,value
mov cx,1
jmp short quit2
quit1: xor cx,cx
quit2: ret
input ENDP
;-------------------------------------------------------------------------------
;pºâ¬Y¦~¬Y¤ë¬Y¤@¤Ñ¬O¬P´Á´X
;¿é¤J¡Gpdate¡GDATEµ²ºcÅ骺¦ì§}¡A¨ä¤¤year¡Bmonth¡Bday¥²¶·¤w¶ñ¤J¥¿½T¤é´Á
;¿é¥X¡GAX¡×¬P´Á´X¡G0¡×¬P´Á¤é¡B1¡×¬P´Á¤@¡A2¡×¬P´Á¤G¡K¡K
; AX¡×-1¡A¿é¤J¿ù»~ªºDATEµ²ºcÅé
what_day_is PROC pdate:WORD
LOCAL w:WORD
;ASSUME si:PTR DATE
;what_day_is§Q¥ÎZeller's¤½¦¡¨D¥X¬YÓ¤é´Á¬O¬P´Á´X¡A¥HWªí¥Ü
;W={C/4¡Ð2*C¡ÏY¡ÏY/4¡Ï13*(M¡Ï1)/5¡ÏD¡Ð1} Mod 7
; ¤ë¥÷¡G1¤ë 2¤ë 3¤ë 4¤ë 5¤ë 6¤ë 7¤ë 8¤ë 9¤ë 10¤ë 11¤ë 12¤ë
; --------------------------------------------------------
; M¡×13 14 3 4 5 6 7 8 9 10 11 12
; A¡× 1 1 0 0 0 0 0 0 0 0 0 0
; B¡×¥|¦ì¼Æ¦r¦~¥÷¡ÐA
; C¡×Bªº«e¨â¦ì¼Æ(¤d¦ì¼Æ©M¦Ê¦ì¼Æ©Ò²Õ¦¨ªº¨â¦ì¼Æ)
; Y¡×Bªº«á¨â¦ì¼Æ(¤Q¦ì¼Æ©MÓ¦ì¼Æ©Ò²Õ¦¨ªº¨â¦ì¼Æ)
; D¡×¤é
mov si,pdate
mov cl,100
movzx bx,(DATE PTR [si]).month
mov ax,(DATE PTR [si]).year
cmp bx,2 ;Àˬd¬O§_¬°¤¸¤ë¥÷©Î¤G¤ë¥÷
ja not_adj
add bx,12 ;¦pªG¤ë¥÷¬°¤¸¤ë¥÷©Î¤G¤ë¥÷¡An½Õ¾ã¦¨«e¤@¦~ªº13¤ë¡B
dec ax ;14¤ë¡A¥ç§Y¤ë¥÷Åܦ¨13¤ë¡B14¤ë¦P®É¦~¥÷´î¤@
not_adj: div cl ;¦~¥÷¡×B¡×AX
movzx cx,ah ;CX¡×Y
movzx dx,al ;DX¡×C
mov w,cx ;W¡×Y
shr cx,2 ;CX¡×Y/4
add w,cx ;W¡×Y¡ÏY/4
mov cx,dx
shr cx,2 ;CX¡×C/4
shl dx,1 ;DX¡×2*C
movzx ax,(DATE PTR [si]).day
add w,cx ;W¡×C/4¡ÏY¡ÏY/4
sub w,dx ;W¡×C/4¡Ð2*C¡ÏY¡ÏY/4
add w,ax ;W¡×C/4¡Ð2*C¡ÏY¡ÏY/4¡ÏD
inc bx ;BX¡×M¡Ï1
mov cx,50dh ;CL¡×13¡ACH¡×5
mov ax,bx
mul cl
div ch
cbw ;AX¡×13*(M¡Ï1)/5
add ax,w
mov cx,7
dec ax ;AX¡×C/4¡Ð2*C¡ÏY¡ÏY/4¡Ï13*(M¡Ï1)/5¡ÏD¡Ð1
cwd
idiv cx ;¦]¬°DX:AX¦³¥i¯à¬Ot¼Æ¡A¦]¦¹¥ÎIDIV
cmp dx,0 ;¦pªGDX:AX¬Ot¼Æ©Ò±o¾l¼Æ(¦s©óDX)¤]¬Ot¼Æ
jge ok
add dx,cx ;¦]¦¹¾l¼Æn¥[¤W¤C¡A½T«O¬°¥¿¼Æ
ok: mov ax,dx
ret
what_day_is ENDP
;-------------------------------------------------------------------------------
.STARTUP
INVOKE print_string,OFFSET str0
call input
jcxz error
mov today.year,ax
INVOKE print_string,OFFSET str1
call input
jcxz error
mov today.month,al
INVOKE print_string,OFFSET str2
call input
jcxz error
mov today.day,al
INVOKE what_day_is,OFFSET today
.IF ax==0
mov dx,OFFSET str_sunday
.ELSEIF ax==1
mov dx,OFFSET str_monday
.ELSEIF ax==2
mov dx,OFFSET str_tuesday
.ELSEIF ax==3
mov dx,OFFSET str_wednesday
.ELSEIF ax==4
mov dx,OFFSET str_thursday
.ELSEIF ax==5
mov dx,OFFSET str_friday
.ELSE
mov dx,OFFSET str_saturday
.ENDIF
INVOKE print_string,dx
mov al,0
jmp short exit
error: INVOKE print_string,OFFSET error_message
mov al,1
exit: .EXIT al
;*******************************************************************************
END |
²ÕĶ³sµ²³oÓì©lµ{¦¡«Ü²³æ¡A¥u»Ý¦b¡uVirtual PC 2007 SP1¡v¶}±Ò¡uMS-DOS 6.20¡vµêÀÀ¾÷¾¹¡A¤Á´«¨ì WHATDAY.ASM ªº¤l¥Ø¿ýùØ¡A¿é¤J¡uML WHATDAY.ASM¡v¡A«ö¤U¡uEnter¡vÁä§Y¥i¡C¦p¤U¹Ï¡G
¦³Ãö WHATDAY.ASM ªº¸Ñ»¡¡A³Ì¥Dnªº¬O¦³Ãö¦s¨úµ²ºcÅ餤ªºÄæ¦ì¡A«e±¤w¸g´yz¹L¤F¡C¦b³oÓµ{¦¡ùØ¡AÁÙ¦³¨âÓ¦a¤èȱoª`·N¡G①½²°Ç¤½¦¡¡F②¦³¸¹¼Æªº±ø¥ó¸õÅD¡C
½²°Ç¤½¦¡¬O¥Î¨Ópºâ¦è¾ä¬Y¦~¬Y¤ë¬Y¤é¬O¬P´Á´Xªº¤½¦¡¡C¥¦¼g¦¨¤U±ªº¦¡¤l¡G
©³¤U»¡©ú³o¨ÇÅܼƪº·N¸q¤Îpºâ¹Lµ{¡A±À¾É¹Lµ{¨£¤Ñ¤å¾äªk©Î fater ªº¤å³¹¡C
¨Ò¦pnpºâ¦è¤¸ 2000 ¦~¤¸¤ë¤¸¤é¬P´Á´X¡A¦]¬°¬O¤@¤ë¥÷¡A©Ò¥HÀ³¸Ó¬Ý¦¨¬O 1999 ¦~ 13 ¤ë 1 ¤é¡C¦]¦¹ C¡×19¡AY¡×99¡AM¡×13¡AD¡×1¡A¥N¤J½²°Ç¤½¦¡¡G
¦]¦¹¦è¤¸ 2000 ¦~¤¸¤ë¤¸¤é¬O¬P´Á¤»¡C
¦b½²°Ç¤½¦¡¤¤¡A¤p¬A¸¹¤º©Òpºâ¥X¨Óªº¼Æ¦³¥i¯à¬OtÈ¡A³o¼Ëªº¸Ü´N¤£¯à¥Î DIV «ü¥O¨D°£¥H 7 ªº¾l¼Æ¡A¥²¶·¨Ï¥Î IDIV¡C²z¥Ñ«Ü²³æ¡A¦]¬° DIV ¬OpºâµL¸¹¼Æªº°£ªk¡AIDIV ¤~¯àpºâ¦³¸¹¼Æªº°£ªk¡C¦¹¥~¡A¦pªG¬Ot¼Æ°£¥H 7 ©Ò±oªº¾l¼Æ¤]¬OtÈ¡A¥Î³otȵLªk¸g¥Ñ¦ì§}¨ú±o¬P´Á´Xªº¦r¦ê¡A¦]¦¹n¥[¤W¤@¬qµ{¦¡Àˬd¦pªG¾l¼Æ¬°t¡A¸Ó¦p¦ó³B²z¡CnÀˬd¾l¼Æ¬O¤£¬Ot¼Æ¡A³Ìª½Ä±ªº¤è¦¡´N¬O§â¾l¼Æ©M¹s°µ¤ñ¸û¡A¾l¼Æ¤p©ó¹s´N¬Ot¼Æ¡C¦pªG¾l¼Æ¬°t¡A¨º»òÁÙn¦A¥[¤W¤C¡A¨Ï¤§Åܬ°¥¿ªº¾l¼Æ¡C( ª`·N¡I¤£¬OÅܸ¹¡A¦Ó¬O¥[¤C )
n¤ñ¸û¦³¸¹¼Æªº¤j¤pn¥Î CMP «ü¥O¡A¨Ã·f°t±ø¥ó¸õÅD«ü¥O JG/JGE/JL/JLE ¥|ºØ¤¤ªº¨ä¤¤¤@ºØ¡C
JG ¬O¡ujump short if greater¡vªº·N«ä¡A¦pªG¤j©ó´N¸õÅD¡CJGE ¬O¡ujump short if greater or equal¡vªº·N«ä¡A¦pªG¤j©ó©Îµ¥©ó´N¸õÅD¡CJL «ü¥O¬O¡ujump short if less¡vªº·N«ä¡A¦pªG¤p©ó´N¸õÅD¡CJLE ¬O¡ujump short if less or equal¡vªº·N«ä¡A¦pªG¤p©ó©Îµ¥©ó´N¸õÅD¡Cª`·N¡I¤ñ¸û¦³¸¹¼Æªº¤j¤p¡A¥Î CMP ·f°t JL/JG/JLE/JGE¡F¤ñ¸ûµL¸¹¼Æªº°ª§C¡A¤]¬O¥Î CMP ¦ý·f°t JA/JB/JAE/JBE¡C
©³¤U¤p¤ì°¸¥Î¤@Ó¨Ò¤l»¡©ú¡C°²³]¦³¤U±¨â¬q«Ü¬Û¦üªºµ{¦¡¡A¶È¦³¤@³B¤£¦P¡A¨º´N¬O JG »P JA ªº®t§O¡C³o¨âµ{¦¡°õ¦æ¨ì ok: ³B®É¡ACX ¤À§O·|¬O¦h¤Ö©O¡H
µ{¦¡¤@ µ{¦¡¤G
mov cx,0 mov cx,0
mov al,0FFh mov al,0FFh
mov bl,3 mov bl,3
cmp al,bl cmp al,bl
jg ok ja ok
mov cx,1 mov cx,1
ok: . ok: .
. .
. .
®Ú¾Úè¤~»¡ªº¡Aµ{¦¡¤@¤¤¡AJG ¬O¤ñ¸û¦³¸¹¼Æªº¤j¤p¡A©Ò¥Hn§â AL ¬Ý¦¨¬O ¡Ð1¡ABL ¬O 3¡A±o¨ì AL¡ÕBL¡C¦ý¬O¡uCMP AL,BL/JG OK¡vªº·N«ä¬O AL¡ÖBL ¤~·|¸õÅD¡A©Ò¥H¦¹®É¨Ã¤£·|¸õ¨ì ok: ³B¡A¦Ó¬O°õ¦æ¤U¤@¦æ¡A¬G CX µ¥©ó 1¡C
µ{¦¡¤G¤¤¡AJA ¬O¤ñ¸ûµL¸¹¼Æªº°ª§C¡A©Ò¥Hn§â AL ¬Ý¦¨¬O 255¡ABL ¬O 3¡A±o¨ì AL¡ÖBL¡C¦Ó¡uCMP AL,BL/JA OK¡vªº·N«ä¬O AL¡ÖBL ¤~·|¸õÅD¡A©Ò¥Hµ{¦¡¤G·|µo¥Í¸õ¶V¨ì ok: ³B°õ¦æ¡A¬G CX µ¥©ó 0¡C
¦^¨ì WHATDAY.ASM ì©lµ{¦¡ùØ¡Aµ{¦¡²Ä 118¡ã119 ¦æ¬°¡G
cmp dx,0 ;¦pªGDX:AX¬Ot¼Æ©Ò±o¾l¼Æ(¦s©óDX)¤]¬Ot¼Æ
jge ok
DX:AX °£¥H 7 «á©Ò±oªº¾l¼Æ¦b DX ùØ¡A¦Ó DX:AX ¦³¥i¯à¬Ot¼Æ¡An¦p¦ó½T©w¬O¥¿¼ÆÁÙ¬Ot¼Æ¡A¥u»Ý¤ñ¸û DX »P 0¡A¦pªG DX ¤j©ó¹s©Îµ¥©ó¹s¡A¤£»ÝnÃB¥~ªº³B²z¡F¦pªG DX ¤p©ó¹s´N¬Ot¼Æ¡A¥²¶·Åý¾l¼Æ¥[¤@¤~¯à±o¨ì¥¿¼Æªº¾l¼Æ¡C