主题:[讨论]关于日时钟的实现
ilovehuibian
[专家分:0] 发布于 2008-01-06 02:21:00
这个是关于日时钟的实现问题,具体要求是,在输入文件名后,清屏显示current time:然后输入时分秒,开始计时,利用中断刷新时间,推出使用CTRL+C,运行不死机。
上传文件里有程序,哪位大牛帮看看,无法生成。exe文件,link时出现fatal error L1093.
请解释一下,谢谢~~
回复列表 (共3个回复)
沙发
ilovehuibian [专家分:0] 发布于 2008-01-06 02:33:00
程序如下:
data segment para public 'data'
count100 db 100
tenhour db 0
hour db 0,':'
tenmin db 0
minute db 0,':'
tensec db 0
second db 0
show db 'Current time is:$'
fauls db 'Error number!Please input again:$'
data ends
stack segment para stack 'stack'
db 256 dup(0)
stack ends
code segment para public 'code'
;主程序
assume cs:code,ds:data
;显示字符
dic macro
mov ah,09h
int 21h
endm
start: mov ax,data
mov ds,ax
call clear
mov dx,offset show
dic
call newtime
;等待回车按下开始计时
mov ah,0
int 16h
;cmp al,0dh
;jne
cli
mov ax,0
mov es,ax
mov di,20h
mov ax,offset timer
stosw
mov ax,cs
stosw
;为8253时钟计时器设置初值
mov al,36h;选择CH0通道,产生频率100Hz的方波,读写LSB-MSB,二进制计数
out 43h,al
mov bx,11932
mov al,bl
out 40h,al
mov al,bh
out 40h,al
mov al,0fch;只允许定时器和键盘中断,其余皆屏蔽
out 21h,al
sti;产生中断
板凳
ilovehuibian [专家分:0] 发布于 2008-01-06 02:33:00
;显示时间,并随着中断不断变化
forever:mov bx,offset tenhour
mov cx,8
dispclk:mov al,[bx]
call dispchar
inc bx
loop dispclk
mov al,0dh
call dispchar
mov al,second
next: cmp al,second
je next
jmp forever
;中断服务程序
timer proc far
push ax
;计数器count100,当减为零时,对时钟的值进行修改
dec count100
jnz timerx
mov count100,100
;对时间进行修改
inc second
cmp second,'9'
jle timerx
mov second,'0'
inc tensec
cmp tensec,'6'
jl timerx
mov tensec,'0'
inc minute
cmp minute,'9'
jle timerx
mov minute,'0'
inc tenmin
cmp tenmin,'6'
jl timerx
mov tenmin,'0'
inc hour
cmp hour,'9'
ja adjhour
cmp hour,'4'
jnz timerx
cmp tenhour,'2'
jnz timerx
mov hour,'0'
mov tenhour,'0'
jmp short timerx
adjhour:inc tenhour
mov hour,'0'
;中断返回
timerx: mov al,20h
out 20h,al
pop ax
iret
timer endp
;显示时间
dispchar proc near
push bx
mov bx,0
mov ah,14
int 10h
pop bx
ret
dispchar endp
;清屏程序
clear proc near
mov al,0
mov ch,0
mov cl,0
mov dh,24
mov dl,79
mov bh,7
mov ah,06h
int 10h
ret
clear endp
3 楼
ilovehuibian [专家分:0] 发布于 2008-01-06 02:34:00
;输入时间
newtime proc near
th: mov ah,1
int 21h
cmp al,30h
jl wrong1
cmp al,32h
jg wrong1
mov byte ptr tenhour,al
mov bl,al
jmp h
wrong1: mov dx,offset fauls
dic
jmp th
h: mov ah,1
int 21h
cmp al,30h
jl wrong2
cmp bl,32h
jl h10
cmp al,33h
jg wrong2
mov byte ptr hour,al
jmp mao1
h10: cmp al,39h
jg wrong2
mov byte ptr hour,al
jmp mao1
wrong2: mov dx,offset fauls
dic
jmp h
mao1: mov ah,1
int 21h
sub al,30h
jl wrong3
cmp al,10
jnz wrong3
jmp tmin
wrong3: mov dx,offset fauls
dic
jmp mao1
tmin: mov ah,1
int 21h
cmp al,30h
jl wrong4
cmp al,35h
jg wrong4
mov byte ptr tenmin,al
jmp min
wrong4: mov dx,offset fauls
dic
jmp tmin
min: mov ah,1
int 21h
cmp al,30h
jl wrong5
cmp al,39h
jg wrong5
mov byte ptr minute,al
jmp mao2
wrong5: mov dx,offset fauls
dic
jmp min
mao2: mov ah,1
int 21h
sub al,30h
jl wrong6
cmp al,10
jnz wrong6
jmp tsec
wrong6: mov dx,offset fauls
dic
jmp mao2
tsec: mov ah,1
int 21h
cmp al,30h
jl wrong7
cmp al,35h
jg wrong7
mov byte ptr tensec,al
jmp sec
wrong7: mov dx,offset fauls
dic
jmp tsec
sec: mov ah,1
int 21h
cmp al,30h
jl wrong8
cmp al,39h
jg wrong8
mov byte ptr second,al
jmp exit
wrong8: mov dx,offset fauls
dic
jmp sec
exit: ret
newtime endp
code ends
end start
我来回复