⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dianzibiao.txt

📁 微机原理课程设计汇编语言开发的电子钟 运行环境emu8086
💻 TXT
字号:
;name: ELECTRONIC CLOCK
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 correct the time*******        ',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,'$'
mess2   db  '*******Time is:',0ah,0dh,'$'
t_buff  db 40            ;在数据段开一段时间显示缓冲区
db ?
db 40 dup (?)
hor db ?
min db ?
sec db ?
fg db 0
data  ends

stack segment
      db 100 dup(?)
stack ends

code  segment
      assume cs:code,ss:stack,ds:data ;确定各个逻辑段的类型
start:
      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
      mov al,ch                ;小时数设定
      mov ah,0
      call bctd                 ;调用进制转换子程序
      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
      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
        
      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
        
 ;-----------------------------
      call delay1
      mov  ah,1              ;调用键盘I/O中断功能号1,获取键值到AL
      int  16h
      cmp  al,'c'            ;是c键,转到时间修改程序
      je   Cor
      cmp  al,'C'            ;是C键,转到时间修改程序 
      je   Cor 
      cmp  al,1bh
      jz   quit          ;是ESC键,退出程序
      jmp  display
      
quit:
     mov ah,4ch        ;程序终止功能号
     int 21h
     ret
      
Cor: call correct      ;调用时间修改子程序
;-------------------------------
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
;----------------------------
  correct proc      ;时间修改子程序
  call input        ;调用键盘输入子程序输入数据
  mov ch,hor 
  mov cl,min
  mov dh,sec
  and dl,0h
  mov ah,2dh
  int 21h
  jmp start
  ret
  correct endp
;----------------------------------
 input 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
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
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
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 sec,al
popf                    ;出栈恢复数据
pop dx  
pop cx
pop bx
pop ax
ret
input endp
;----------------------------
code  ends
      end start

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -