驻留时间显示,有点小问题,会的话帮忙改改

romyks 2003-05-12 07:28:39
cseg segment para public 'CODE'
assume cs:cseg,ds:cseg
org 100h
start:
jmp initialize
;----------------------------------------------------------------------------
;Data define
;----------------------------------------------------------------------------
old_timer dd ?
position dw 004bh
tick dw 0
refresh dw 0
blinker dw 0
time db '12:00',0
;----------------------------------------------------------------------------
;Timer initialize
;----------------------------------------------------------------------------
timer_init proc far
sti
pushf
assume ds:nothing
call old_timer
call timer
iret
timer_init endp
;----------------------------------------------------------------------------
;Timer
;----------------------------------------------------------------------------
timer proc near
assume cs:cseg,ds:cseg
push ds
push bx
;
push cs
pop ds ;Set DS=CS
inc tick ;Advance on tick
cmp tick,1092 ;There are 1092 ticks per minute
jl tdone ;If not a whole minute,just redisplay
call settime ;else recompute time
mov tick,0
tdone:
inc refresh ;Refreshing 18.2/second causes
cmp refresh,3 ;flicker.Try only 4.5/second
jl rdone ;If not a whole refresh,do nothing
call dtime ;Else redisplay
mov refresh,0 ;and reset refresh counter
rdone:
inc blinker
cmp blinker,9
jl bdone
call blink
mov blinker,0
bdone:
pop bx
pop ds
ret
timer endp
;----------------------------------------------------------------------------
;Blink
;----------------------------------------------------------------------------
blink proc near
cmp byte ptr time[2],':'
je bloff
mov byte ptr time[2],':'
jmp bldone
bloff:
mov byte ptr time[2],' '
bldone:
ret
blink endp
;----------------------------------------------------------------------------
;Set time
;----------------------------------------------------------------------------
settime proc near
cmp byte ptr time[4],'9' ;compute one
je tenthmin ;If 'X9',advance to next ten
inc byte ptr time[4]
jmp setdone
tenthmin:
mov byte ptr time[4],'0' ;compute ten minutes
cmp byte ptr time[3],'5' ;If '59',then advance one hour
je nexthour
inc byte ptr time[3]
jmp setdone
nexthour:
mov byte ptr time[3],'0' ;compute hours
cmp byte ptr time[1],'2' ;Might be "2" or "12"
je twelvethhour ;See if we'll wrqp around at 12
cmp byte ptr time[1],'9' ;If "9",to "10"
je tenthhour
inc byte ptr time[1]
jmp setdone
twelvethhour:
cmp byte ptr time[0],' ' ;Is it "2"
je thirdhour ;If so,then go to "3"
mov byte ptr time[0],' ' ;If not,then it must be "12"
mov byte ptr time[1],' ' ;so go to "1"
jmp setdone
thirdhour:
inc byte ptr time[1] ;Go to "3"
jmp setdone
tenthhour:
mov byte ptr time[0],'1' ;Go to "10"
mov byte ptr time[1],'0'
setdone:
ret
settime endp
;----------------------------------------------------------------------------
;Dtime subroutine
;----------------------------------------------------------------------------
Dtime proc near
push si
push dx
call get_pos ;Save previous cursro position
push dx ;on stack
mov dx,position ;Go to upper right corner
call set_pos
mov si,offset time ;Display current time string
call dstring
pop dx ;Restore from stack
call set_pos ;old cursor position
pop dx
pop si
ret
Dtime endp
;----------------------------------------------------------------------------
;Dstring subroutine
;----------------------------------------------------------------------------
Dstring proc near
push si
push ax
cmp si,0
je dsdone
dloop:
mov al,[si]
cmp al,0
je dsdone
call dchar
inc si
jmp dloop
dsdone:
pop ax
pop si
ret
Dstring endp
;----------------------------------------------------------------------------
;Char subroutine
;----------------------------------------------------------------------------
DChar proc near
push ax
push bx
mov bh,1
mov ah,0eh
int 10h
pop bx
pop ax
ret
DChar endp
;----------------------------------------------------------------------------
;Get position subroutine
;----------------------------------------------------------------------------
get_pos proc near
push ax
push bx
push cx
push dx
;
mov ah,03h
mov bh,0
int 10h
mov bx,dx
;
pop dx
pop cx
pop bx
pop ax
ret
get_pos endp
;----------------------------------------------------------------------------
;Set position
;----------------------------------------------------------------------------
set_pos proc near
push ax
push bx
mov ah,02h
mov bh,0
int 10h
pop bx
pop ax
set_pos endp

;----------------------------------------------------------------------------
;Initialize section
;----------------------------------------------------------------------------
initialize:
mov bx,cs
mov ds,bx
mov al,08h
mov ah,35h
int 21h
mov word ptr old_timer,bx
mov word ptr old_timer[2],es
;
mov ah,2ch ;Get the time of day from DOS
int 21h
cmp ch,0 ;Is it the witching hour?
jg hour ;If not,handle it normally
add ch,12 ;Else convert to noon and handle that
hour:
cmp ch,12 ;Is it afternoon?
jle day ;If not,just compute normally
sub ch,12 ;If so,subtract and use same code
mov byte ptr time[0],' ' ;Set initial value of tens columen
day: ;Set time fo the twelve hour clock
cmp ch,10 ;Is it after 10?
jl early ;If not,just deal with the one hour
sub ch,10 ;else subtract 10
mov byte ptr time[0],ch ;And set the ones hour column
early: ;Set the time for the one hour column
add ch,'0' ;Convert number to digit
mov byte ptr time[1],ch ;And set the ones hour column
minute:
cmp cl,10 ;Determine how many tens of minutes
jl minset ;we need to set clock to by
sub cl,10 ;means of repeated subtration
inc byte ptr time[3] ;Initialized to '0'
jmp minute
minset:
add cl,'0'
mov byte ptr time[4],cl
mov tick,0

second:
cmp dh,5 ;5 seconds is smallest integer
jle clockstart ;granularity we can measure
add tick,91 ;5 seconds is exactly 91 clock ticks
sub dh,5 ;Get to nearest 5 seconds by
jmp second ;retpearted subtractions

clockstart:
mov dx,offset timer_init
mov al,08h
mov ah,25h
int 21h
;
mov dx,offset initialize
int 27h
cseg ends
end start
...全文
8 点赞 收藏 1
写回复
1 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
ahjoe 2003-05-12
想不到现在还有这么多人学汇编。
我的得意之作:驻留时钟程序 
驻留尺寸小;计算时间精确;三种字体。
源程序下载:http://www.ahjoe.net/download/ti.zip
回复
发动态
发帖子
汇编语言
创建于2007-08-27

2.0w+

社区成员

汇编语言(Assembly Language)是任何一种用于电子计算机、微处理器、微控制器或其他可编程器件的低级语言,亦称为符号语言。
申请成为版主
社区公告
暂无公告