用汇编语言编写一个时钟程序,能显示时分秒的,还要有秒表就是计时器的功能,

2022-04-14 教育 174阅读
STACK1SEGMENTSTACK
DW200DUP(?)
STACK1ENDS
DATASEGMENT
SPACEDB1000DUP('')
PATTERNDB6DUP(''),0C9H,26DUP(0CDH),0BBH,6DUP('')
DB6DUP(''),0BAH,26DUP(20H),0BAH,6DUP('')
DB6DUP(''),0C8H,26DUP(0CDH),0BCH,6DUP('')
DBUFFERDB8DUP(':'),12DUP('')
DBUFFER1DB20DUP('')
STR1DB0DH,0AH,'PLEASEINPUTDATE(D)ORTIME(T)ORQUIT(Q):$'
DATAENDS
CODESEGMENT
ASSUMECS:CODE,DS:DATA,ES:DATA,SS:STACK1
START:MOVAX,0001H;设置显示方式为40*25彩色文本方式
INT10H
MOVAX,DATA
MOVDS,AX
MOVES,AX
MOVBP,OFFSETSPACE
MOVDX,0B00H
MOVCX,1000
MOVBX,0040H
MOVAX,1300H
INT10H
MOVBP,OFFSETPATTERN;显示矩形条
MOVDX,0B00H
MOVCX,120
MOVBX,004EH
MOVAX,1301H
INT10H
LEADX,STR1;显示提示信息
MOVAH,9
INT21H
MOVAH,1;从键盘输入单个字符
INT21H
CMPAL,44H;AL='D'?
JNEA
CALLDATE;显示系统日期
A:CMPAL,54H;AL='T'?
JNEB
CALLTIME;显示系统时间
B:CMPAL,51H;AL='Q'?
JNESTART
MOVAH,4CH;返回dos状态
INT21H

DATEPROCNEAR;显示日期子程序
dis:MOVAH,2AH;取日期
INT21H
MOVSI,0
MOVAX,CX
MOVBX,100
DIVBL
MOVBL,AH
CALLBCDASC1;日期数值转换成相应的ASCII码字符
MOVAL,BL
CALLBCDASC1
INCSI
MOVAL,DH
CALLBCDASC1
INCSI
MOVAL,DL
CALLBCDASC1
MOVBP,OFFSETDBUFFER1
MOVDX,0C0DH
MOVCX,20
MOVBX,004EH
MOVAX,1301H
INT10H
MOVAH,02H;设置光标位置
MOVDX,0300H
MOVBH,0
INT10H
MOVBX,0018H
REPEA:MOVCX,0FFFFH;延时
REPEAT:LOOPREPEAT
DECBX
JNZREPEA
MOVAH,01H;读键盘缓冲区字符到AL寄存器
INT16H
JEdis
JMPSTART
MOVAX,4C00H
INT21H
RET
DATEENDP

TIMEPROCNEAR;显示时间子程序
DISPLAY1:MOVSI,0
MOVBX,100
DIVBL
MOVAH,2CH;取时间
INT21H
MOVAL,CH
CALLBCDASC;将时间数值转换成ASCII码字符
INCSI
MOVAL,CL
CALLBCDASC
INCSI
MOVAL,DH
CALLBCDASC
MOVBP,OFFSETDBUFFER
MOVDX,0C0DH
MOVCX,20
MOVBX,004EH
MOVAX,1301H
INT10H
MOVAH,02H
MOVDX,0300H
MOVBH,0
INT10H
MOVBX,0018H
RE:MOVCX,0FFFFH
REA:LOOPREA
DECBX
JNZRE
MOVAH,01H
INT16H
JEDISPLAY1
JMPSTART
MOVAX,4C00H
INT21H
RET
TIMEENDP

BCDASCPROCNEAR;时间数值转换成ASCII码字符子程序
PUSHBX
CBW
MOVBL,10
DIVBL
ADDAL,'0'
MOVDBUFFER[SI],AL
INCSI
ADDAH,'0'
MOVDBUFFER[SI],AH
INCSI
POPBX
RET
BCDASCENDP

BCDASC1PROCNEAR;日期数值转换成ASCII码字符子程序
PUSHBX
CBW
MOVBL,10
DIVBL
ADDAL,'0'
MOVDBUFFER1[SI],AL
INCSI
ADDAH,'0'
MOVDBUFFER1[SI],AH
INCSI
POPBX
RET
BCDASC1ENDP
CODEENDS
ENDSTART

cursorequ45H
attribequ2fh
codesegment
assumecs:code,ds:code
start:
jmpgo
oldcurdw?
OLD1CDW2DUP(?)
NEWINT1C:
PUSHF
CALLDWORDPTRCS:OLD1C
pushax
PUSHBX
PUSHCX
PUSHDX
XORBH,BH
MOVAH,3
INT10H
MOVCS:OLDCUR,DX
MOVAH,2
xorbh,bh
MOVDX,CURSOR
INT10H
MOVAH,2     ;读取系统时钟
INT1AH
PUSHDX
PUSHCX
POPBX
PUSHBX
CALLSHOWBYTE
CALLSHOWCOLON
POPBX
XCHGBH,BL
CALLSHOWBYTE
CALLSHOWCOLON
POPBX
CALLSHOWBYTE
MOVDX,CS:OLDCUR
MOVAH,2
XORBH,BH
INT10H
POPDX
POPCX
POPBX
POPAX
IRET
SHOWBYTEPROCNEAR
PUSHBX
MOVCL,4
MOVAL,BH
SHRAL,CL
ADDAL,30H
CALLSHOW
CALLCURMOVE
POPBX
MOVAL,BH
ANDAL,0FH
ADDAL,30H
CALLSHOW
CALLCURMOVE
RET
SHOWBYTEENDP

SHOWCOLONPROCNEAR
MOVAL,':'
CALLSHOW
CALLCURMOVE
RET
SHOWCOLONENDP

CURMOVEPROCNEAR
PUSHAX
PUSHBX
PUSHCX
PUSHDX
MOVAH,3
MOVBH,0
INT10H
INCDL
MOVAH,2
INT10H
POPDX
POPCX
POPBX
POPAX
RET
CURMOVEENDP

SHOWPROCNEAR
PUSHAX
PUSHBX
PUSHCX
MOVAH,09H
MOVBX,attrib
MOVCX,1
INT10H
POPCX
POPBX
POPAX
RET
SHOWENDP

GO:
PUSHCS
POPDS
MOVAX,351CH;取中断向量
INT21H
MOVOLD1C,BX      ;保存原中断向量
MOVBX,ES
MOVOLD1C+2,BX
MOVDX,OFFSETNEWINT1C ;置新的中断向量
MOVAX,251CH
INT21H
MOVDX,OFFSETGO
SUBDX,OFFSETSTART
MOVCL,4
SHRDX,CL
ADDDX,11H
MOVAX,3100H       ;结束并驻留
INT21H
CODEENDS
ENDSTART
声明:你问我答网所有作品(图文、音视频)均由用户自行上传分享,仅供网友学习交流。若您的权利被侵害,请联系fangmu6661024@163.com