山东科技大学信电学院07级大神的课程设计代码,实时日历/时钟的设计及实现825982538255仅供学弟学妹参考,课程设计还要自己做。
.386Init macro op1,op2,op3,op4,op5,op6mov cx,00hmov dh,op1mov dl,op2op6:mov ah,02hmov bh,00hint 10hpush cxmov ah,0ahmov al,op3mov bh,00hmov cx,01hint 10hpop cxinc cxinc op4cmp cx,op5jne op6endmdata segmentshijian db 10 dup(':') ;存放时间riqi db 20 dup(' ') ;存放日期str1 db ' Welcome to use this clock ',0ah,0dhdb '* show time--t ',0ah,0dhdb '* set time--s ',0ah,0dh,'$'str2 db ' _ _ ',0ah,0dhdb ' ( ) ( )',0ah,0dhdb ' | |_| | ',0ah,0dhdb ' | _ | /^_` )( ^_`\ ( ^_`\ ( ) ( ) ',0ah,0dhdb ' | | | |( (_| || (_) )| (_) )| (_) | ',0ah,0dhdb ' (_) (_)`\__,_)| ,__/^| ,__/^`\__, | ',0ah,0dhdb ' | | | | ( )_| | ',0ah,0dhdb ' (_) (_) `\___/^ ',0ah,0dhdb ' _ _ _ _ ',0ah,0dhdb ' ( ) ( ) ( ) ( ) ',0ah,0dhdb ' | `\| | __ _ _ _ `\`\_/^/^__ _ _ _ __ ',0ah,0dhdb ' | , ` | /^__`\( ) ( ) ( ) `\ /^/^__`\ /^_` )( ^__) ',0ah,0dhdb ' |`\ | ( ___/| \_/ \_/ | | |( ___/( (_| || | ',0ah,0dhdb ' (_) (_)`\____)`\___x___/^ (_)`\____)`\__ _)(_) ',0ah,0dh,'$'str3 db ' change date--d',0ah,0dhdb ' change time--c',0ah,0dhdb ' time is right--r ',0ah,0dhdb ' return to menu--m ',0ah,0dhdb ' return to doc--o ',0ah,0dh,'$'year db 'please press a new year:',0ah,0dh,'$'month db 'please press a new month:',0ah,0dh,'$'day db 'please press a new day:',0ah,0dh,'$'hour db 'please press a new hour:',0ah,0dh,'$'minu db 'please press a new minute:',0ah,0dh,'$'seco db 'please press a new second:',0ah,0dh,'$'chag db 'Are you sure(y/n)?',0ah,0dh,'$'error db 'press error,please input right button:',0ah,0dh,'$'wrong db 'You have pressed the wrong button, press a new button:',0ah,0dh,'$'cant db 'cant change the time, please rechange:',0ah,0dh,'$'data endscode segment use16assume ds:data,cs:codestart:mov ax,datamov ds,axmov es,axmov ax,0700h ;清屏,al滚动行数mov bh,1ah ;背景、字体颜色mov cx,0 ;窗口左上角坐标mov dx,2479h ;窗口右下角坐标(Y'X)int 10hInit 00d,00d,0Dh,dl,80d,sign1Init 24d,00d,0Dh,dl,80d,sign2Init 00d,00d,2ah,dh,25d,sign3Init 00d,79d,2ah,dh,25d,sign4mov ah,02h ;设置光标位置(1)mov bh,00h ;显示页码mov dh,07h ;行坐标mov dl,02h ;列坐标int 10hlea dx,str1 ;显示提示字符串mov ah,09hint 21hinput:mov ah,01h ;键盘输入int 21hcmp al,'t'jz desk2 ;跳转下一页面cmp al,'s'jnz error1call chandate ;更改日期call chantime ;更改时间jmp desk2error1:call huilea dx,error ;提示输入错误mov ah,09hint 21hjmp inputmov ah,4chint 21hdesk2:call clear ;清屏mov ah,02h ;设置光标位置(2)mov bh,00h ;页码mov dh,0ah ;Y行坐标mov dl,00h ;列X坐标int 10hlea dx,str3 ;显示字符串2call yinmov ah,09hint 21hclear1:mov ah,1 ;查询键盘缓冲区,测试键盘是否有输入(不将字符读出,用于提前测试按键为何字符)int 16hjz shan ;缓冲区为空,zf=1无输入zf=0有输入xor ax,ax ;不为空则取出,清空int 16hjmp clear1shan:mov ah,02h ;设置光标位置(2)mov bh,00h ;页码mov dh,01h ;Y行坐标mov dl,00h ;列X坐标int 10hlea dx,str2 ;显示字符串2call yinmov ah,09hint 21hmov ah,2ch ;提取系统时间CH=时(0~23),CL=分(0~59),DH=秒(0~59),DL =百分秒(0~99)int 21hmov bl,dhcmp bl,30hjb kuangsub bl,12 ;59-2chkuang:Init 05d,42d,bl,dl,25d,sign9 ;横向Init 08d,42d,bl,dl,25d,sign10Init 05d,42d,bl,dh,04d,sign11 ;纵向Init 05d,67d,bl,dh,04d,sign12push axmov ah,00mov al,blmov bl,2div blInit 00d,00d,al,dh,25d,sign5inc alInit 24d,00d,al,dl,80d,sign6inc alInit 00d,79d,al,dh,25d,sign7inc alInit 00d,00d,al,dl,80d,sign8pop axmov si,0 ;清空后别的指令;读取日期mov ah,2ah ;CX=年,AL=星期DH=月,DL=日int 21hmov ax,cx ;年call ascyear ;年ASC码转换and ah,0 ;ah置零mov al,dh ;月call ascdate ;ASC码转换and ah,0mov al,dl ;日call ascdate ;ASC码转换lea bp,riqi ;显示日期ES:BP=显示字符串的地址mov dx,0632h ;DH,DL=起始行,列mov cx,10 ;CX=显示字符串长度mov bx,004eh ;BH=页码BL=属性(若AL=00H或01H)背景字体颜色mov ax,1301h ;AL=显示输出方式1——字符串中只含显示字符,其显示属性在BL 中。
显示后,光标位置改变int 10hmov si,0mov ah,2ch ;读取时间CH=时(0~23),CL=分(0~59),DH=秒(0~59),DL=百分秒(0~99)int 21hand ah,0mov al,ch ;时call asctime ;ASC码转换and ah,0mov al,cl ;分call asctimeand ah,0mov al,dh ;秒call asctimelea bp,shijian ;显示时间,bp显示时间的地址mov dx,0733hmov cx,8 ;字符串长度mov bx,005fh ;颜色mov ax,1301h ;视频中断(INT 10H)13H号功能:显示指定地址、指定长度的字符串int 10hmov ah,02h ;设置光标位置mov bh,00h ;页码mov dh,0fh ;y坐标mov dl,00h ;x坐标int 10hcall delay1 ;时间延迟mov ah,01h ;键盘中断int 16hcmp al,'o'jnz menujmp end1menu:cmp al,'m'jnz rightxor ax,axint 16hjmp startright:cmp al,'r'jnz date1call yin ;时间确定,隐藏光标call clear ;清除字符串2jmp shandate1:cmp al,'d'jnz time1call chandatejmp desk2time1:cmp al,'c'jnz clear1call chantimejmp desk2end1:mov ah,4ch ;主程序结束int 21h ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;子程序;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; asctime proc ;时间asc码转换mov bl,10div bl ;al商ah余数add al,'0'mov shijian[si],alinc siadd ah,'0'mov shijian[si],ahinc siinc siretasctime endpascyear proc ;年asc码转换mov bl,100div bl ;al商ah余数push axand ah,0mov bl,10div bladd al,'0'mov riqi[si],alinc siadd ah,'0'mov riqi[si],ahinc sipop axmov al,ahand ah,0mov bl,10div bladd al,'0'mov riqi[si],alinc siadd ah,'0'mov riqi[si],ahinc siinc siretascyear endpascdate proc ;月日asc码转换mov bl,10div bladd al,'0'mov riqi[si],alinc siadd ah,'0'mov riqi[si],ahinc siinc siretascdate endpdelay1 proc ;精确延迟时间子程序mov dx,04ffh ;循环次数up: xor cx,cx ;空指令没有意义a: noploop adec dxjnz upretdelay1 endpchandate procmov ah,1 ;清空键盘缓冲区;查询键盘缓冲区int 16hjz c ;缓冲区为空xor ax,ax ;不为空则取出,清空int 16hc:call huichanyear:lea dx,year ;更改年mov ah,09hint 21hand cx,0 ;存放结果mov ah,01hint 21hcall ceshi ;第一个数字是否(0-9)sub al,30hand ah,0mov bx,1000mul bxadd cx,axmov ah,01hint 21hcall ceshi ;第二个数字sub al,30hand ah,0mov bl,100mul bladd cx,axmov ah,01hint 21hcall ceshi ;第三个数字sub al,30hand ah,0mov bl,10mul bladd cx,axmov ah,01hint 21hcall ceshi ;第四个数字sub al,30hand ah,0add cx,axpush cx ;保护年call huichanmonth:lea dx,month ;更改月mov ah,09hint 21hcall chan ;更改月日时分秒子程序返回bhcmp bh,1jae ocall cuojmp chanmontho:cmp bh,12jbe qcall cuojmp chanmonthq:mov dh,bhpush dx ;保护月call huipop dx ;退出保护月pop cx ;退出保护年call chanday ;闰年判断得出日的范围push cx ;重新保护年mov dl,bh ;日push dx ;保护月日call huilea dx,chagmov ah,09hint 21hpop dxpop cx ;退出保护年input2:mov ah,01hint 21hcmp al,'n'jz ccmp al,'y'jz judgepush dxcall huilea dx,wrongmov ah,09hint 21hpop dxjmp input2judge:mov ah,2bh ;CX=年(1980~2099),DH=月(1~12),DL=日(1~31) int 21hcmp al,0 ;测试更改是否成功,出口参数:AL=00H--设置成功,0FFH--设置失败jz returncall huilea dx,cantmov ah,09hint 21hjmp chanyearreturn:retchandate endpchantime proc ;更改时间mov ah,1 ;清空键盘缓冲区;查询键盘缓冲区int 16hjz we ;缓冲区为空xor ax,ax ;不为空则取出,清空int 16hwe:call huichanhour:lea dx,hour ;更改小时mov ah,09hint 21hcall chancmp bh,0jae rcall cuojmp chanhourr:cmp bh,23jbe scall cuojmp chanhours:;mov dh,bhmov ch,bh ;CH=时(0~23)call huichanmin:lea dx,minu ;更改分钟mov ah,09hint 21hcall chancmp bh,0jae wcall cuojmp chanminw:cmp bh,59jbe vcall cuojmp chanminv:;mov dh,bhmov cl,bh ;CL=分(0~59)call huichansec:lea dx,seco ;更改秒mov ah,09hint 21hcall chancmp bh,0jae xcall cuojmp chansecx:cmp bh,59jbe ycall cuojmp chansecy:mov dh,bh ;DH=秒(0~59),mov dl,00h ;定义1/100秒从0开始DL=百分秒(0~99) push cxpush dxcall huilea dx,chagmov ah,09hint 21hpop dxpop cxinput3:mov ah,01hint 21hcmp al,'n'jz wecmp al,'y'jz judge2push dxcall huilea dx,wrongmov ah,09hint 21hpop dxjmp input3judge2:mov ah,2dhint 21hcmp al,0 ;修改是否成功jz return1call huilea dx,cantmov ah,09hint 21hjmp chanhourreturn1:retchantime endphui proc ;光标换行mov dl,0ahmov ah,02hint 21hmov dl,0dhmov ah,02hint 21hrethui endpchan procg2:mov ah,01h ;更改月日时分秒子程序int 21hsub al,30hmov bl,10mul bljae g3 ;输入大于0跳转call huilea dx,errorint 21hjmp g2g3:mov bh,al ;bh出口参数mov ah,01h ;输入第二个数字int 21hsub al,30hadd bh,aljae g1 ;输入第二个数大于0call huilea dx,errormov ah,09hint 21hjmp g2g1:retchan endpclear proc ;清屏子程序mov ax,0600hmov bh,2eh ;背景,字体颜色mov cx,0mov dx,2479hint 10hretclear endpyin proc ;隐藏光标mov cx,2000hmov ah,01hint 10hretyin endpceshi proc ;测试输入数字cmp al,30hjae lcall huilea dx,errormov ah,09hint 21hjmp chanyearl:cmp al,39hjbe ncall huilea dx,errorint 21hjmp chanyearn:retceshi endpcuo proc ;显示错误call huilea dx,errormov ah,09hint 21hretcuo endpchanday procb2:push dx;月d:lea dx,day ;更改日mov ah,09hint 21hmov ah,01hint 21hsub al,30hmov bl,10mul bljae d1;al-30>=0跳到d1call huilea dx,errormov ah,09hint 21hjmp dd1:mov bh,almov ah,01hint 21hsub al,30hadd bh,aljae mcall huilea dx,errormov ah,09hint 21hjmp dm:pop dxcmp dh,1jz a1cmp dh,2jz a2jz a1cmp dh,4jz a3cmp dh,5jz a1cmp dh,6jz a3cmp dh,7jz a1cmp dh,8jz a1cmp dh,9jz a3cmp dh,10jz a1cmp dh,11jz a3cmp dh,12jz a1a1:cmp bh,1jae b1push dxcall cuopop dxjmp b2b1:cmp bh,31jbe b3push dxcall cuopop dxjmp b2a3:cmp bh,1jae c1push dxcall cuopop dxjmp b2c1:cmp bh,30jbe b3push dxcall cuopop dxjmp b2a2:mov ax,cxpush bxpush dxcwd ;扩展mov bx,4 ;DX.AX商:ax,DX.AX余数:dxdiv bxcmp dx,0pop dxpop bxjnz lab1;不等于零跳到lab1mov ax,cxmov bl,100div blcmp ah,0jnz lab2mov ax,cxpush bxpush dxcwdmov bx,400div bxcmp dx,0pop dxpop bxjz lab2lab1:cmp bh,1jae d2push dxcall cuopop dxjmp b2d2:cmp bh,28jbe b3push dxcall cuopop dxjmp b2lab2:cmp bh,1jae d3push dxcall cuopop dxjmp b2d3:cmp bh,29jbe b3push dxcall cuopop dxjmp b2b3:ret chanday endp code endsend start。