1、汇编小闹钟实验 题目小闹钟程序教 师 评 语评价指标: 题目内容完成情况 优 良 中 差 对原理的理解程度 优 良 中 差 程序设计水平 优 良 中 差 实验报告结构清晰 优 良 中 差 实验总结和分析详尽 优 良 中 差 实验报告一、实验目的通过本综合性、设计性实验使学生进一步巩固课堂所学,全面熟悉、掌握8088宏汇编语言程序设计的基本方法和技巧,进一步提高编写程序、阅读分析程序及上机操作、调试程序的能力。二、实验要求 1 从键盘输入闹铃时间2 程序开始记时,并在屏幕上显示时间(如00:00:01)并实时刷新3 时间到,则发出闹铃声,声音维持数秒;同时时间停止刷新三、实验原理分析 1 由键盘
2、输入十进制字符,转化为二进制数值,并保存作为响铃时间 2 调用2ch中断获取系统时间,在循环中并用回车返回刷新时间 3 将系统实时时间与保存的时间比较,相等则响铃四、流程图 五、源程序data segmentline1 db =Alarm Clock=,$set db * Please input the ringbell time:,$h db * Hour:,$m db * Munite:,$s db * Second:,$crf db 0ah,0ah,$now db * The start time : ,$cur db =current=,$nh dw 0nm dw 0ns dw 0c
3、r db 0dh,0ah,$br db 0dh,$rin db * The time is reach!,$err db * quit input 0:,$line2 db =Clock Close=,$line3 db =Clock Start=,$data ends ;*code segment main proc far assume cs:code,ds:datastart: push ds sub ax,ax push ax mov ax,data mov ds,ax ;输出=Alarm Clock= mov ah,9 lea dx,line1 int 21h call dropli
4、ne ;输出Please input the ringbell time: mov ah,9 lea dx,now int 21h ;2ch号功能调用,取系统时间:ch,cl,dh中分别存放时分秒 mov ah,2ch int 21h call displayTime call dropline ;输入响铃时间 call input ;输出=Clock Start= lea dx,line3 mov ah,9 int 21h call dropline ;若输入出错,可输入“0”退出 lea dx,err mov ah,9 int 21h mov ah,1 int 21h cmp al,0 j
5、z exit call dropline ;输出=current= lea dx,cur mov ah,9 int 21h call dropline ;实时刷新时间,并检查响铃时间是否到了s0: call displayTime ;消除光标 mov cx,2000h mov ah,01h int 10h ;回车刷新 mov ah,9 lea dx,br int 21h mov ah,2ch int 21h ;比较时 mov al,ch cbw cmp ax,nh jnz s0 ;比较分 mov al,cl cbw cmp ax,nm jnz s0 ;比较秒 mov al,dh cbw cmp
6、 ax,ns jnz s0 call dropline ;响铃 call ringbell call dropline ;结束输出=Clock Close= mov ah,9 lea dx,line2 int 21h exit: retmain endp;*;响铃控制ringbell proc near push bx push cx mov ah,9 lea dx,rin int 21h mov bx,30000 mov cx,30000 call sound pop cx pop bx retringbell endp;*;发声子程序,参数为BX,CXsound proc near pus
7、h dx push ax mov dx,cx in al,61h and al,10101010btrig: xor al,2 out 61h,al mov cx,bx delay: loop delay dec dx jne trig pop ax pop dx retsound endp;*;接收输入的时分秒,存入nh,nm,nsinput proc near push dx push ax ;输出Please input the ringbell time: mov ah,9 lea dx,set int 21h call dropline ;接收时 mov ah,9 lea dx,h
8、int 21h call tansfer call dropline mov nh,ax ;接收分 mov ah,9 lea dx,m int 21h call tansfer call dropline mov nm,ax ;接收秒 mov ah,9 lea dx,s int 21h call tansfer call dropline mov ns,ax pop dx pop ax ret input endp;*;输出参数ax存放接受的十进制数实际大小tansfer proc near push bx mov ax,0 mov ah,1 int 21h sub al,30h mov bl
9、,al mov ah,1 int 21h sub al,30h mov bh,al mov al,bl mov bl,10 mul bl mov bl,bh mov bh,0 add ax,bx pop bx rettansfer endp;*displayTime proc near mov al,ch ;小时的值赋给al cbw ;al扩展成ax,用做除法的被除数 call bindecmov dl,: ;显示: mov ah,02h int 21h mov al,cl ;分 cbw call bindec mov dl,: ;显示: mov ah,02h int 21h mov al,d
10、h ;秒 cbw call bindec ret displayTime endp ;*bindec proc nearpush ax push cx push dx mov dx,0 mov cx,10d div cx mov bx,dx ;先保存余数mov dl,al ;显示商(即十进制二位数的十位)or dl,30h mov ah,02h int 21h mov dx,bx ;恢复余数的值(十进制二位数的个位) add dl,30h mov ah,02h int 21h pop dx pop cx pop ax ret bindec endp ;*;输出空行dropline proc near push ax push dx mov ah,9 lea dx,cr int 21h pop dx pop ax retdropline endp;*code ends end start 六、程序测试 1.输入响铃时间,选择“0”可以退出2.current处动态刷新时间3时间到响铃
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1