汇编高手请进,高分求助!

crystal_si 2003-09-24 11:13:29
用汇编语言或C语言编写1个DOS状态下的CMOS的实时时钟程序
要求:1该程序执行过后在屏幕右上角显示实时数字时钟
2该程序要求驻留内存TSR
3时钟的更新用ICH(IC中断)或08中断
...全文
44 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
紫郢剑侠 2003-09-24
  • 打赏
  • 举报
回复
在VBIN版主的网站http://www.vbin.org上有现成的ASM源代码.
romyks 2003-09-24
  • 打赏
  • 举报
回复
给你一个现成的代码吧,很久以前做的好像和你要的差不多,自己看看吧
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
;Name:CLOCK.ASM
;Function:Display the current time
;By Romyks
;Date:May 11 2002
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
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
romyks 2003-09-24
  • 打赏
  • 举报
回复
给你一个现成的代码吧,很久以前做的好像和你要的差不多,自己看看吧
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
;Name:CLOCK.ASM
;Function:Display the current time
;By Romyks
;Date:May 11 2002
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
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

21,458

社区成员

发帖
与我相关
我的任务
社区描述
汇编语言(Assembly Language)是任何一种用于电子计算机、微处理器、微控制器或其他可编程器件的低级语言,亦称为符号语言。
社区管理员
  • 汇编语言
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧