发一个自己写的超长汇编程序,实现输入日期,输出该日期是这一年的第几天和星期几
程序代码:
;数据段,定义了indate用来存放输入的ascll,定义的date用来年,月,日, ;存放ascll转换成数形式的年,月,日,和星期,weeks也存放了星期,其他的就是一些输出的字符串 DATAS SEGMENT indate db 11,11 dup (?),'$' date0 db 13,10,'$' dates dw 5 dup (?) date1 db ' is the ','$' day dw 4 dup (?) date2 db 'th day of this year and ','$' weekdate1 db 'Monday','$' weekdate2 db 'Tuesday','$' weekdate3 db 'Wednesday','$' weekdate4 db 'Thursday','$' weekdate5 db 'Friday','$' weekdate6 db 'Saturday','$' weekdate7 db 'Sunday','$' weeks dw 1 dup (?) error db 13,10,'Error date! Input a correct date:','$' input db 'please input a date between 1949 and 2049(yyyy.mm.dd):','$' DATAS ENDS ;数据段开始 CODES SEGMENT ASSUME CS:CODES,DS:DATAS main proc far ;main程序 START: MOV AX,DATAS ;载入数据段 MOV DS,AX mov dx,offset input ;调用21h的06号功能实现字符串输入 mov ah,09h int 21h call inputsub call dealmon call dealsub mov dx,offset date0 ;最终的输出 mov ah,09h int 21h mov dx,offset indate mov ah,09h int 21h mov dx,offset date1 mov ah,09h int 21h mov dx,offset day mov ah,09h int 21h mov dx,offset date2 mov ah,09h int 21h call dealweek ;输出最后一个字符串,即星期 mov dx,offset date0 ;输入正确日期结束后,再次输入时,回车换行 mov ah,09h int 21h jmp start ; 再次开始 main endp ;main程序结束 inputsub proc near ;实现输入的子程序,转换为数据 lea dx,indate mov ah,0ah int 21h mov di,2 mov cx,11 loop1: mov al,[indate+di] ;处理字符串的开始两位 mov [indate-2+di],al inc di loop loop1 mov al,'$' ;处理掉回车换行 mov [indate+10],al mov al,byte ptr [indate] ;把年的ascll转换成数 cbw sub ax,30h mov bx,1000d mul bx mov [dates],ax mov al,byte ptr [indate+1] cbw sub ax,30h mov bx,100d mul bx add [dates],ax mov al,byte ptr [indate+2] cbw sub ax,30h mov bx,10d mul bx add [dates],ax mov al,byte ptr [indate+3] cbw sub ax,30h add [dates],ax mov dx,[dates] cmp dx,1949 jb error1 cmp dx,2049 ja error1 mov al,byte ptr [indate+5] ;把月的ascll转换成数 cbw sub ax,30h mov bx,10d mul bx mov [dates+2],ax mov al,byte ptr [indate+6] cbw sub ax,30h add [dates+2],ax mov dx,[dates+2] cmp dx,1 jb error1 cmp dx,12 ja error1 mov al,byte ptr [indate+8] ;把日的ascll转换成数 cbw sub ax,30h mov bx,10d mul bx mov [dates+4],ax mov al,byte ptr [indate+9] cbw sub ax,30h add [dates+4],ax mov dx,[dates+4] cmp dx,1 jb error1 cmp dx,30 ja error1 jmp exiti error1: mov dx,offset error ;如果错误,则输出错误信息,并且重新输入 mov ah,9h int 21h call inputsub exiti: ret inputsub endp dealsub proc near ;实现处理星期处理的子程序,用蔡勒公式处理 mov ax,[dates+2] ;判断月份是不是小于3 cmp ax,3 jae above3 mov ax,0 ;不是小于3就不需要转换成上一年的13,14月处理 mov ax,[dates] dec ax mov dx,0 mov bx,100d div bx mov [dates+6],dx mov ax,dx mov dx,0 mov bx,4 div bx add [dates+6],ax mov ax,[dates+2] add ax,12 inc ax mov bx,26d mul bx mov dx,0 mov bx,10d div bx add [dates+6],ax mov ax,[dates+4] add [dates+6],ax mov ax,[dates+6] dec ax mov [dates+6],ax mov dx,[dates] cmp dx,1999d jb below3 mov dx,35 sub [dates+6],dx jmp exit below3: mov dx,34 sub [dates+6],dx jmp exit above3: ;月份大于3的情况 mov ax,0 mov ax,[dates] mov dx,0 mov bx,100d div bx mov [dates+6],dx mov ax,dx mov dx,0 mov bx,4 div bx add [dates+6],ax mov ax,[dates+2] inc ax mov bx,26d mul bx mov dx,0 mov bx,10d div bx add [dates+6],ax mov ax,[dates+4] add [dates+6],ax mov ax,[dates+6] dec ax mov [dates+6],ax mov dx,[dates] cmp dx,2000d jb below mov dx,35 sub [dates+6],dx jmp exit below: mov dx,34 sub [dates+6],dx exit: ;用蔡勒公式算出来的分正数和负数分开处理 mov ax,[dates+6] cmp ax,0 js signd mov dx,0 mov bx,7d div bx mov [dates+6],dx mov [weeks],dx jmp exitddd signd: neg ax mov dx,0 mov bx,7d div bx sub dx,7 neg dx mov [dates+6],dx mov [weeks],dx exitddd: ret dealsub endp dealmon proc near ;处理在多少天,分闰年和非闰年分开处理 mov ax,[dates] mov dx,0 mov bx,4 div bx cmp dx ,0 jnz nleap mov ax,[dates] mov dx,0 mov bx,100d div bx cmp dx,0 jnz leap jz again again: mov ax,[dates] mov dx,0 mov bx,400 div bx cmp dx,0 jz leap jnz nleap leap: ;是闰年,继续判断月份 mov [dates+8],0 mov dx,[dates+2] cmp dx,12d jz leap12 mov dx,[dates+2] cmp dx,11d jz leap11 mov dx,[dates+2] cmp dx,10d jz leap10 mov dx,[dates+2] cmp dx,9d jz leap9 mov dx,[dates+2] cmp dx,8d jz leap8 mov dx,[dates+2] cmp dx,7d jz leap7 mov dx,[dates+2] cmp dx,6d jz leap6 mov dx,[dates+2] cmp dx,5d jz leap5 mov dx,[dates+2] cmp dx,4d jz leap4 mov dx,[dates+2] cmp dx,3d jz leap3 mov dx,[dates+2] cmp dx,2d jz leap2 mov dx,[dates+2] cmp dx,1d jz leap1 leap12: mov [dates+8],335 mov ax,[dates+4] add [dates+8],ax jmp exitd leap11: mov [dates+8],305 mov ax,[dates+4] add [dates+8],ax jmp exitd leap10: mov [dates+8],274 mov ax,[dates+4] add [dates+8],ax jmp exitd leap9: mov [dates+8],244 mov ax,[dates+4] add [dates+8],ax jmp exitd leap8: mov [dates+8],213 mov ax,[dates+4] add [dates+8],ax jmp exitd leap7: mov [dates+8],182 mov ax,[dates+4] add [dates+8],ax jmp exitd leap6: mov [dates+8],152 mov ax,[dates+4] add [dates+8],ax jmp exitd leap5: mov [dates+8],121 mov ax,[dates+4] add [dates+8],ax jmp exitd leap4: mov [dates+8],91 mov ax,[dates+4] add [dates+8],ax jmp exitd leap3: mov [dates+8],60 mov ax,[dates+4] add [dates+8],ax jmp exitd leap2: mov [dates+8],31 mov ax,[dates+4] add [dates+8],ax jmp exitd leap1: mov [dates+8],0 mov ax,[dates+4] add [dates+8],ax jmp exitd nleap: mov [dates+8],0 ;不是闰年 mov dx,[dates+2] cmp dx,12d jz nleap12 mov dx,[dates+2] cmp dx,11d jz nleap11 mov dx,[dates+2] cmp dx,10d jz nleap10 mov dx,[dates+2] cmp dx,9d jz nleap9 mov dx,[dates+2] cmp dx,8d jz nleap8 mov dx,[dates+2] cmp dx,7d jz nleap7 mov dx,[dates+2] cmp dx,6d jz nleap6 mov dx,[dates+2] cmp dx,5d jz nleap5 mov dx,[dates+2] cmp dx,4d jz nleap4 mov dx,[dates+2] cmp dx,3d jz nleap3 mov dx,[dates+2] cmp dx,2d jz nleap2 mov dx,[dates+2] cmp dx,1d jz nleap1 nleap12: mov [dates+8],334 mov ax,[dates+4] add [dates+8],ax jmp exitd nleap11: mov [dates+8],304 mov ax,[dates+4] add [dates+8],ax jmp exitd nleap10: mov [dates+8],273 mov ax,[dates+4] add [dates+8],ax jmp exitd nleap9: mov [dates+8],243 mov ax,[dates+4] add [dates+8],ax jmp exitd nleap8: mov [dates+8],212 mov ax,[dates+4] add [dates+8],ax jmp exitd nleap7: mov [dates+8],181 mov ax,[dates+4] add [dates+8],ax jmp exitd nleap6: mov [dates+8],151 mov ax,[dates+4] add [dates+8],ax jmp exitd nleap5: mov [dates+8],120 mov ax,[dates+4] add [dates+8],ax jmp exitd nleap4: mov [dates+8],90 mov ax,[dates+4] add [dates+8],ax jmp exitd nleap3: mov [dates+8],59 mov ax,[dates+4] add [dates+8],ax jmp exitd nleap2: mov [dates+8],31 mov ax,[dates+4] add [dates+8],ax jmp exitd nleap1: mov [dates+8],0 mov ax,[dates+4] add [dates+8],ax jmp exitd exitd: mov ax,[dates+8] ;判断 第几天 ,有三种情况,大于100,大于10和小于10,需要不同的空间来存放ascll mov dx,ax cmp dx,100d jae exitd1 cmp dx,10d jae exitd2 jb exitd3 exitd1: mov ax,[dates+8] mov dx,0 mov bx,100d div bx mov [day],ax mov ax,dx mov dx,0 mov bx,10d div bx mov [day+2],ax mov [day+4],dx mov ax,'$' mov [day+6],ax mov cx,30h add [day],cx add [day+2],cx add [day+4],cx jmp exitdddo exitd2: mov ax,[dates+8] mov dx,0 mov bx,10d div bx mov [day],ax mov [day+2],dx mov ax,'$' mov [day+4],ax mov cx,30h add [day],cx add [day+2],cx jmp exitdddo exitd3: mov ax,[dates+8] mov [day],ax mov ax,'$' mov [day+2],ax mov cx,30h add [day],cx jmp exitdddo exitdddo: ret dealmon endp dealweek proc near ;把存放在week的星期最终的星期输出 mov ax,[weeks] cmp ax,6 jz weeks6 mov ax,[weeks] cmp ax,5 jz weeks5 mov ax,[weeks] cmp ax,4 jz weeks4 mov ax,[weeks] cmp ax,3 jz weeks3 mov ax,[weeks] cmp ax,2 jz weeks2 mov ax,[weeks] cmp ax,1 jz weeks1 mov ax,[weeks] cmp ax,0 jz weeks0 weeks6: mov dx,offset weekdate6 mov ah,09h int 21h jmp exitw weeks5: mov dx,offset weekdate5 mov ah,09h int 21h jmp exitw weeks4: mov dx,offset weekdate4 mov ah,09h int 21h jmp exitw weeks3: mov dx,offset weekdate3 mov ah,09h int 21h jmp exitw weeks2: mov dx,offset weekdate2 mov ah,09h int 21h jmp exitw weeks1: mov dx,offset weekdate1 mov ah,09h int 21h jmp exitw weeks0: mov dx,offset weekdate7 mov ah,09h int 21h jmp exitw exitw: ret dealweek endp CODES ENDS ;数据段结束 END START
asm.rar
(2.59 KB)