如何获得开关机时间,并将其存入一个文件(如:timercd.sys)
如题:
以下是我的汇编程序,开机时间正确,但不能得到关机时间(关机时间全为0),请各位指教:
coseg segment
org 100h ;.com格式
assume cs:coseg,ds:coseg
start: jmp start1
offset1c dw 0000h ;放原1C中断入口偏移量
seg1c dw 0000h ;放原1c中断入口段地址
lir proc far ;新的1c中断服务程序
push ax ;保护现场
push bx
push cx
push dx
push si
push di
push ds
push es
pushf
call dword ptr cs:offset1c;调原来1c中断
cli;禁止中断
mov ah,02h
int 1ah;读当前实时钟(CH时CL分DH秒,BCD码)
push dx
mov dx,70h;COMS索引寄存器地址
mov al,01h
out dx,al;选择秒报时寄存器
inc dx
pop ax
xchg ah,al
out dx,al;存入秒报时寄存器
mov dx,70h
mov al,03h
out dx,al;选择分报时寄存器
inc dx
mov al,cl;分
out dx,al;存入分报时寄存器
mov dx,70h
mov al,05h
out dx,al;选择时报时寄存器
inc dx
mov al,ch;时
out dx,al;存入时报时寄存器
sti
pop es;恢复现场
pop ds
pop di
pop si
pop dx
pop cx
pop bx
pop ax
iret
lir endp
filename db "c:\timercd.sys",00h ;文件名
begintm db 14 dup(0) ;本次开机日期,时间
endtm db 6 dup(0) ,0dh,0ah ;上次关机时间
stoh proc near
mov ax,cs
mov ds,ax
mov es,ax
mov bx,offset endtm ;关机时间缓冲区
mov dx,70h
mov al,05
out dx,al ;选择时报时寄存器
inc dx
in al,dx ;取关机时
call bcdtoasc;bcd码转换为ascii码
mov [bx+0],dh
mov [bx+1],dl
mov dx,70h
mov al,03
out dx,al ;选择分报时寄存器
inc dx
in al,dx ;取关机分
call bcdtoasc
mov [bx+2],dh
mov [bx+3],dl
mov dx,70h
mov al,01
out dx,al ;选择秒报时寄存器
inc dx
in al,dx ;取关机秒
call bcdtoasc
mov [bx+4],dh
mov [bx+5],dl
mov bx,offset begintm ;开机日期时间缓冲区
mov ah,4
int 1ah ;取当前日期
push dx
mov al,ch ;年的高2位
call bcdtoasc
mov [bx+0],dh
mov [bx+1],dl
mov al,cl ;年的低2位
call bcdtoasc
mov [bx+2],dh
mov [bx+3],dl
pop dx
mov al,dh ;月
push dx
call bcdtoasc
mov [bx+4],dh
mov [bx+5],dl
pop dx
mov al,dl ;日
call bcdtoasc
mov [bx+6],dh
mov [bx+7],dl
mov ah,02
int 1ah ;读当前实时钟
push dx
mov al,ch ;时
call bcdtoasc
mov [bx+8],dh
mov [bx+9],dl
mov al,cl ;分
call bcdtoasc
mov [bx+10],dh
mov [bx+11],dl
pop dx
mov al,dh ;秒
call bcdtoasc
mov [bx+12],dh
mov [bx+13],dl
mov ah,3dh
mov al,1
lea dx,filename
int 21h ;打开文件,写
mov bx,ax ;存文件标记
mov cx,0
mov dx,0
mov al,2
mov ah,42h
int 21h ;指针移到文件尾
mov ah,40h
mov cx,8
lea dx,endtm
int 21h ;上次关机时间存入文件
mov cx,14
mov ah,40h
lea dx,begintm
int 21h ;本次开机日期,时间存入文件
mov ah,3eh
int 21h ;关闭文件
ret
stoh endp
bcdtoasc proc near ;BCD码转换为ASCII码子程序
push cx
mov cl,al
and al,0fh
or al,30h
mov dl,al
mov al,cl
mov cl,04h
shr al,cl
or al,30h
mov dh,al
pop cx
ret
bcdtoasc endp
start1: call stoh
mov ax,0000h ;指定段地址
mov ds,ax
cli ;关中断
mov ax,word ptr ds:[0070h]
mov word ptr cs:offset1c,ax
mov ax,word ptr ds:[0072h]
mov word ptr cs:seg1c,ax
mov word ptr ds:[0070h],offset lir
mov word ptr ds:[0072h],cs
sti
lea dx,filename
int 27h 驻留内存
coseg ends
end start