📄 cx2.asm
字号:
call output
mov dl,':'
mov ah,02h
int 21h
POPA
RET
DISPLYM ENDP
;----------------------------------------------------------
;显示秒
DISPLYS PROC NEAR
PUSHA
;设置光标位置
mov dh,08h ;set Row No.
mov dl,19d ;set Column NO.
call MOVCUR
mov dh,0
mov dl,ds:[SEC]
call output
POPA
ret
DISPLYS endp
;----------------------------------------------------------
;调用DOS中断取得系统时间
GETTIME PROC NEAR
PUSHA
mov ah,2ch ;get the System time,CH:CL=(H:M),DH:DL=(s:1/100s)
int 21h
mov ds:[HOUR],CH ;取得小时
mov ds:[MIN],CL ;取得分钟
; dec DH ;延迟1秒
mov ds:[SEC],DH ;取得秒
mov ds:[MSEC],DL
POPA
ret
GETTIME endp
;----------------------------------------------------------
;调整时间,累加秒,分,时
CALTIME proc near
PUSHA ;调整秒
inc ds:[SEC]
cmp ds:[SEC],60d
jb endc
mov ds:[SEC],0h
setM: ;调整分钟
inc ds:[MIN]
cmp ds:[MIN],60d
jb endc
mov ds:[MIN],0h
setH: ;调整小时
inc ds:[HOUR]
cmp ds:[HOUR],24d
jb endc
mov ds:[HOUR],0h
endc:
POPA
ret
CALTIME endp
;---------------------------------------------------------------------------
;设置时间
SETTIME proc near
PUSHA
call closeSw ;关闭定时刷新
mov dh,11h
mov dl,00h
call MOVCUR ;移动光标
mov dx,00h
mov ah,09h ;输出提示信息,提示输出设置时间
mov dx,offset setTMsg
int 21h
call READNT ;读取时间(HH:MM:SS)
;设置时间
mov ch,ds:[NHOUR] ;HOUR
mov cl,ds:[NMIN] ;MIN
mov dh,ds:[NSEC] ;SECOND
mov dl,0h ;1/100 SECOND
mov ah,2Dh
int 21h
cmp al,00h
je SetSuccess
mov ah,02h ;设置时间中断调用失败处理
mov dl,'!'
int 21h
SetSuccess:
call openSw ;打开刷新开关
POPA
ret
SETTIME endp
;---------------------------------------------------------------------
;设置闹铃时间:
SETRING proc near
PUSHA
call closeSw ;关闭定时刷新
mov dh,11h
mov dl,00h
call MOVCUR ;移动光标
mov dx,00h
mov ah,09h ;输出提示信息,提示输出设置时间
mov dx,offset setRMsg
int 21h
call READRINGT ;读取闹铃时间(HH:MM)
mov ds:[RingSw],0FFH ;设置闹铃开关为 '开'
rSetSuccess:
call openSw ;打开刷新开关
POPA
ret
SETRING endp
;------------------------------------------------------------------
;读取时间(从ASCII码到16进制数值的转换)(HH:MM:SS)
READNT PROC NEAR
PUSHA
MOV AH,01H
INT 21H
cmp al,'h'
jz loop11
cmp al,'m'
jz loop21
cmp al,'c'
jz loop31
loop11: mov ah,01h
int 21h
MOV BX,0H ;bx存放得到的数值(16进制)
LOOP1: CMP AL,'0' ;读取小时
JL ENDLOOP1
CMP AL,'9'
JG ENDLOOP1
SUB AL,30H ;transform from char to number
CBW
XCHG AX,BX
MOV CX,0AH ;put 10d into cx
MUL CX
XCHG AX,BX
ADD BX,AX
MOV AH,01H ;put the read interrupt type
INT 21H ;call the DOS interrupt
JMP LOOP1
;存取小时
ENDLOOP1:
MOV DS:[NHOUR],BL ;
jmp jieshu
loop21: MOV BX,0H ;
LOOP2:
MOV AH,01H
INT 21H
;bx存放得到的数值(16进制)
CMP AL,'0' ;读取分钟
JL ENDLOOP2
CMP AL,'9'
JG ENDLOOP2
SUB AL,30H ;transform from char to number
CBW
XCHG AX,BX
MOV CX,0AH ;put 10d into cx
MUL CX
XCHG AX,BX
ADD BX,AX
JMP LOOP2
;存取分钟
ENDLOOP2:
MOV DS:[NMIN],BL
jmp jieshu
loop31: MOV BX,0H
LOOP3:
MOV AH,01H
INT 21H
;bx存放得到的数值(16进制)
CMP AL,'0' ;读取秒
JL RLAST
CMP AL,'9'
JG RLAST
SUB AL,30H ;transform from char to number
CBW
XCHG AX,BX
MOV CX,0AH ;put 10d into cx
MUL CX
XCHG AX,BX
ADD BX,AX
JMP LOOP3
RLAST: ;存取秒
MOV DS:[NSEC],BL
jieshu: POPA
RET
READNT ENDP
;----------------------------------------------------------------------------
;读取闹铃时间
READRINGT proc near
PUSHA
mov ah,01h
int 21h
mov bx,0h ;bx存放得到的数值(16进制)
rloop1:
cmp al,'0' ;读取小时
jl rendloop1
cmp al,'9'
jg rendloop1
sub al,30h ;transform from char to number
cbw
xchg ax,bx
mov cx,0ah ;put 10d into cx
mul cx
xchg ax,bx
add bx,ax
mov ah,01h ;put the read interrupt type
int 21h ;call the DOS interrupt
jmp rloop1
;存取小时
rendloop1:
mov ds:[RHOUR],bl;
mov bx,0h;
rloop2:
mov ah,01h
int 21h
;bx存放得到的数值(16进制)
cmp al,'0' ;读取分钟
jl rendloop2
cmp al,'9'
jg rendloop2
sub al,30h ;transform from char to number
cbw
xchg ax,bx
mov cx,0ah ;put 10d into cx
mul cx
xchg ax,bx
add bx,ax
jmp rloop2
;存取分钟
rendloop2:
mov ds:[RMIN],bl
POPA
ret
READRINGT endp
;-----------------------------------------------------------------------------
;闹铃发声程序
;
;DI,保存发声频率,CX,BX指定发声程序的持续时间
GENSOUND proc near
PUSHA
push DI
;set the frequency
mov di,020h
mov bx,0FFh
mov al,0b6h ;write timer mode reg.
out 43h,al
mov dx,12h ;timer divisor
mov ax,348ch ;1193100HZ/freq
div di
out 42h,al ;write timer2 count low byte
mov al,ah
out 42h,al ;write timer2 count high byte
in al,61h ;get current port setting
mov ah,al ;and save it in ah
or al,03h ;turn speaker on
out 61h,al
waitsound:
mov cx,500h ;wait for specified intevral
delaySound:
loop delaySound
dec bx
jnz waitsound
mov al,ah ;recover value of port
out 61h,al
pop DI
POPA
ret
GENSOUND endp
;---------------------------------------------------------------------------
;输出字符(dx中存放十进制数值)
output proc near
PUSHA
mov ax,dx ;put the final num into ax
mov dx,00h
mov cx,0h
trans:
mov bx,000ah ;this loop put the char into memory
div bx ;divide 10d
add dl,30h ;transform to character
mov dh,0h
push dx
inc cx
mov dx,00h
cmp ax,00h
jg trans
cmp cx,01h
jg print
addZero: ;增加前导0,,比如:02
mov dh,0
mov dl,'0'
push dx
inc cx
print: ;this loop output the char
cmp cx,0h
jle endout
pop dx
mov dh,0
dec cx
mov ah,02h
int 21h ;call DOS output ability
jmp print
endout:
POPA
ret
output endp
;----------------------------------------------------------
end start ;end assemble
.end
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -