code segment
assume cs:code,ds:code
org 100h
start: jmp install
msg db 'current time is: '
time0 db ?,?
db ':'
time1 db ?,?
db ':'
time2 db ?,?,0,0
oldint1c dd ?
newint1c: push ax
push bx
push cx
push dx
push si
push di
push es
mov ax,0200h
int 1ah
mov al,ch
lea si,time0
call bcd
mov al,cl
lea si,time1
call bcd
mov al,dh
lea si,time2
call bcd
mov ax,0b800h
mov es,ax
mov di,54*2d
lea si,msg
disp: mov al,cs:[si]
inc si
or al,al
jz disp0
cld
stosb
inc di
jmp disp
disp0: pop es
pop di
pop si
pop dx
pop cx
pop bx
pop ax
jmp cs:oldint1c
bcd: mov ah,al
shr ah,1
shr ah,1
shr ah,1
shr ah,1
and al,0fh
add ax,'00'
xchg ah,al
mov cs:[si],ax
ret
install: push cs
pop ds
mov ax,351ch
int 21h
mov word ptr oldint1c,bx
mov word ptr oldint1c+2,es
lea dx,newint1c
mov ax,251ch
int 21h
mov dx,offset install+120h
mov cl,04h
shr dx,cl
mov ah,31h
int 21h
code ends
end start
code segment
assume cs:code,ds:code
org 100h
start: jmp install
msg db 'current time is: '
time0 db ?,?
db ':'
time1 db ?,?
db ':'
time2 db ?,?,0,0
oldint1c dd ?
以下为新的中断服务程序
newint1c: push ax
push bx
push cx
push dx
push si
push di
push es 保存现场
mov ax,0200h
int 1ah 取时间
mov al,ch
lea si,time0
call bcd 转成bcd
mov al,cl
lea si,time1
call bcd
mov al,dh
lea si,time2
call bcd
mov ax,0b800h
mov es,ax
mov di,54*2d
lea si,msg
disp: mov al,cs:[si] 写到b800:54×2d
inc si
or al,al
jz disp0
cld
stosb
inc di
jmp disp
disp0: pop es
pop di
pop si
pop dx
pop cx
pop bx
pop ax 恢复现场并转到原入口
jmp cs:oldint1c
bcd: mov ah,al
shr ah,1
shr ah,1
shr ah,1
shr ah,1
and al,0fh
add ax,'00'
xchg ah,al
mov cs:[si],ax
ret
以下为安装服务程序
install: push cs
pop ds
mov ax,351ch
int 21h 取原中断向量
mov word ptr oldint1c,bx
mov word ptr oldint1c+2,es 保存
lea dx,newint1c
mov ax,251ch 置新的中断服务地址
int 21h
mov dx,offset install+120h
mov cl,04h
shr dx,cl
mov ah,31h
int 21h 驻留并退出
code ends
end start