📄 电子闹钟_b06030612.asm
字号:
data segment
mess1 db ' ****************ASM ASSIGNMENT**************** ',0ah,0dh
db ' ',0ah,0dh
db ' ***************ELECTRONIC CLOCK*************** ',0ah,0dh
db ' ',0ah,0dh
db ' ',0ah,0dh
db ' *******Press C or c to edit the alarm time Press M or m to change sound!**** ',0ah,0dh
db ' ',0ah,0dh
db ' ***********Press ESC button to exit*********** ',0ah,0dh,'$'
tn db 'Please input the new time (hh:mm:ss):',0dh,0ah,'$'
musicmess db 'Please choose the type of music:1(fast) 2(middle) 3(slow)',0dh,0ah,'$'
mess2 db '*******Time is:',0ah,0dh,'$'
t_buff db 40 ;在数据段开一段时间显示缓冲区
db ?
db 40 dup (?)
hor db ?
min db ?
sec db ?
fg db 0
temphor db ?
tempmin db ?
tempsec db ?
error db 'this is a test sentence',0ah,0dh,'$'
music dw 800 ;存放音乐的频率数
data ends
stack segment
db 100 dup(?)
stack ends
code segment
assume cs:code,ss:stack,ds:data ;确定各个逻辑段的类型
start:
mov ax,data
mov ds,ax
;mov bx,offset t_buff ;送t_buff的偏移地址到BX
;mov ah,2ch ;调用DOS时间调用功能,功能号:2cH,小时,分钟,秒数分别保存在CH,CL,DH中
;int 21h
call clear ;调用清屏子程序
display: ;时间显示部分
mov ax,data
mov ds,ax
mov bx,offset t_buff ;送t_buff的偏移地址到BX
mov ah,2ch ;调用DOS时间调用功能,功能号:2cH,小时,分钟,秒数分别保存在CH,CL,DH中
int 21h
;判断时间是否相等
sub dh,1 ;秒钟+1修正
CALL CHECK
;call err
mov al,ch ;小时数设定
mov ah,0
call bctd ;调用进制转换子程序 二进制转BCD码子程序
push ax
and al,0f0h ;选取al高四位
mov cl,4 ;设置右循环的次数
rol al,cl ;右循环
or al,30h ;加30h得到ACSII码
mov [bx],al ;将得到的结果送到t_buff缓冲区
inc bx ;BX自加1,指针指向下一个缓冲区的下一个地址
pop ax
and al,0fh ;选取低四位
or al,30h
mov [bx],al ;将转换后的低四位值送入缓冲区的第二个地址
inc bx
;----------------------------------------------------------
mov al,':' ;显示分隔符号
mov [bx],al
inc bx
;-------------------------------------------------------
mov ah,2ch
int 21h
mov al,cl ;分钟数设定
mov ah,0
call bctd
push ax
and al,0f0h
mov cl,4
rol al,cl
or al,30h
mov [bx],al
inc bx
pop ax
and al,0fh
or al,30h
mov [bx],al
inc bx
;-------------------------------------------------------------------------
mov al,':' ;显示分隔符号
mov [bx],al
inc bx
;-------------------------------------------------------------------------
mov ah,2ch ;秒设定
int 21h
mov al,dh
mov ah,0
call bctd
push ax
and al,0f0h
mov cl,4
rol al,cl
or al,30h
mov [bx],al
inc bx
pop ax
and al,0fh
or al,30h
mov [bx],al
inc bx
;----------------------------------------------------------------------
mov al,'$' ;将字符串的结束位送至显示缓冲区的最后一位
mov [bx],al
;------------------------------------------------------------------------
push bx ;置光标位置 ,AH=2,BH=0,DH跟DL分别为行号与列号,并入栈保护BX
mov ah,2 ;0~1用于此程序快下边的 在下面的两个置光标位置
mov bh,0
mov dh,17
mov dl,41
int 10h
pop bx
lea dx,t_buff ;送t_buff偏移地址到DX,并调用DOS显示功能,功能号为9
mov ah,9
int 21h ;至此当前事前时间的显示功能结束!
push bx ;置光标位置
mov ah,2
mov bh,0
mov dh,0
mov dl,0
int 10h
pop bx
lea dx,mess1
mov ah,9
int 21h ; 显示mess1
push bx ;置光标位置
mov ah,2
mov bh,0
mov dh,17
mov dl,21
int 10h
pop bx
lea dx,mess2
mov ah,9
int 21h ; 显示mess2
;-----------------------------
call delay1
mov ah,1 ;调用键盘I/O中断功能号1,获取键值到AL
int 16h
cmp al,'c' ;是c键,转到时间修改程序
je edittime
cmp al,'C' ;是C键,转到时间修改程序
je edittime
cmp al,'m'
je editmusic
cmp al,'M'
je editmusic
cmp al,1bh
jz quit ;是ESC键,退出程序
jmp display
quit:
mov ah,4ch ;程序终止功能号
int 21h
ret
Cor: call edittime ;调用预定时间子程序 飞
;-------------------------------
bctd proc near ;二进制转BCD码子程序
;AX输入参数
;AX输出参数,存放调整过的BCD码
mov dx,ax
mov ax,0
mov cx,16 ;设循环次数
bctd1:
clc ;清进位标志C
rcl dx,1 ;通过进位的循环右移
adc al,al ;带进位加法
daa ;加法的十进制调整
xchg al,ah ;交换高、低八位
adc al,al
daa
xchg al,ah
loop bctd1 ;循环次数保存在CX里
ret
bctd endp
;-------------------------------------------
clear proc near
push ax ;入栈保护现场
push bx
push cx
push dx
mov ax,0600h ;ah=06(滚动)al=00(全屏空白)
mov bh,3eh ;设置背景颜色(2)和前景颜色(e)
sub cx,cx
mov dx,5f5fh
int 10h
pop dx ;出栈恢复现场
pop cx
pop bx
pop ax
ret
clear endp
;-----------------------------------------
delay1 PROC ;精确延迟时间子程序
MOV DX,04ffh ;循环次数
up: XOR CX,CX
a: NOP
LOOP a
DEC DX
JNZ up
RET
delay1 ENDP
;----------------------------
edittime proc ;时间修改子程序
push ax ;入栈保护数据
push bx
push cx
push dx
pushf
mov dx,offset tn ;显示修改时间的格式提示
mov ah,09h
int 21h
mov dx,offset t_buff ;数据缓冲区的数据输入
mov ah,0ah
int 21h
and dx,0h
lea bx,t_buff
inc bx
inc bx
inc bx
mov dh,[bx]
sub dh,30h
inc bx
mov dl,[bx]
sub dl,30h
mov cl,10
mov al,dh
mul cl
add al,dl
mov ch,al
;mov hor,al
mov temphor,al
inc bx
inc bx
mov dh,[bx]
sub dh,30h
inc bx
mov dl,[bx]
sub dl,30h
mov cl,10
mov al,dh
mul cl
add al,dl
mov cl,al
;mov min,al
mov tempmin,al
inc bx
inc bx
mov dh,[bx]
sub dh,30h
inc bx
mov dl,[bx]
sub dl,30h
mov cl,10
mov al,dh
mul cl
add al,dl
mov dh,al
mov tempsec,al
popf ;出栈恢复数据
pop dx
pop cx
pop bx
pop ax
jmp start
ret
edittime endp
CHECK PROC
push ax
push bx
cmp ch,temphor ;设置定点报时
jne cf1
cmp cl,tempmin
jne cf1
cmp dh,tempsec
je xiang
cf1:
cmp cl,0 ;设置整点报时
jne cf
cmp dh,0
jne cf
xiang:
CALL OPEN
PUSH DX
PUSH CX
MOV DX,12H
MOV AX,34DEH
mov cx,music
DIV CX
OUT 42H,AL
MOV AL,AH
OUT 42H,AL
MOV AH,1
INT 21H
POP CX
POP DX
CALL CLOSE
CF:
pop bx
POP AX
RET
CHECK ENDP
OPEN PROC
PUSH AX
IN AL,61H
OR AL,03H
OUT 61H,AL
POP AX
RET
OPEN ENDP
CLOSE PROC
PUSH AX
IN AL,61H
AND AL,0FCH
OUT 61H,AL
POP AX
RET
CLOSE ENDP
Editmusic proc
push ax ;入栈保护数据
push bx
push cx
push dx
pushf
mov dx,offset musicmess ;显示修改音乐的种类提示
mov ah,09h
int 21h
mov dx,offset t_buff ;数据缓冲区的数据输入
mov ah,0ah
int 21h
and dx,0h
lea bx,t_buff
inc bx
inc bx
inc bx
mov al,[bx]
cmp al,'1'
je m800to
cmp al,'2'
je m1600to
cmp al,'3'
je m3200to
m800to: mov music,800
jmp t
m1600to: mov music,1600
jmp t
m3200to: mov music,3200
t:
popf ;出栈恢复数据
pop dx
pop cx
pop bx
pop ax
jmp start
ret
Editmusic endp
code ends
end start
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -