很简单的一段代码。可能对于刚学习的同学有两点知识需要补充:
(1)
mov ah,2Ch ;ch=时,cl=分,dh=秒 用来获取系统的时间,并且分别放在注释中的寄存器中
int 21h ;获取时间
(2)
用来设置光标的位置
- setshow proc ;设置光标位置
- mov dh,12 ;行号12
- mov dl,35 ;列号35
- mov bh,0 ;分页
- mov ah,2
- int 10h
- ret
- show endp
下面是完整的程序:
- ;时钟显示
- data segment
- ; add your data here!
- hour db 0
- minute db 0
- second db 0
- time db "00:00:00$"
- len equ $-time
- num db 0
- ends
- stack segment
- dw 128 dup(0)
- ends
- code segment
- start:
- mov ax, data
- mov ds, ax
- mov es, ax
- begin:
- call setshow
- call get_system_time
- jmp begin
- get_system_time proc
- ;---------------------------------- 获取系统时间
- mov ah,2Ch ;ch=时,cl=分,dh=秒
- int 21h ;获取时间
- mov hour,ch
- mov minute,cl
- mov second,dh
- ;------------------------------------
- mov ax,0 ;时间显示到字符串
- mov al,hour ;商:al,余数:ah
- mov num,10
- div num
- add al,30h
- mov time[0],al
- add ah,30h
- mov time[1],ah
- mov ax,0
- mov al,minute
- mov num,10
- div num
- add al,30h
- mov time[3],al
- add ah,30h
- mov time[4],ah
- mov ax,0
- mov al,second
- mov num,10
- div num
- add al,30h
- mov time[6],al
- add ah,30h
- mov time[7],ah
- ;------------------------ 输出系统时间
- lea dx, time
- mov ah, 9
- int 21h
- ret
- get_system_time endp
- ;-------------------------- --
- setshow proc ;设置光标位置
- mov dh,12 ;行号12
- mov dl,35 ;列号35
- mov bh,0
- mov ah,2
- int 10h
- ret
- setshow endp
- ;------------------------- ----
- mov ax, 4c00h
- int 21h
- ends
- end start