汇编语言编写一个“时钟的常驻内存程序”。
发布网友
发布时间:2022-05-08 03:12
我来回答
共1个回答
热心网友
时间:2023-07-31 03:45
masm5.0编译,windows98或dos可以正常显示
;tsr例程
;功能:每按下ctrl键显示
;surported by campuslichen@yeah.net
;07/11/29
lmcmosr macro colorc,rowc,colc ;宏:获取cmos时间并显示
local lcmosrb,frc,btoa,toasc,nxt
jmp lcmosrb
pshow db ' \ \ : : ',0 ;ascii码存放区
acmos db 9,8,7,4,2,0 ;cmos端口,70h号:入口参数,9:年,8:月,7:日,4:时,2:分,0:秒,71h:出口参数,BCD码
pcmos db 7 p(0) ;
frc:
;;无入口参数________________________
push si
push cx
mov cx,6
mov si,0
frs:
mov al,acmos[si]
out 70h,al ;将al中的参数写入al,格式为 :out 70h,al
in al,71h ;从 71h端口读取出口参数到al
mov pcmos[si],al
inc si
loop frs
pop cx
pop si
ret
btoa: ;bcd码转为ascii码
;;入口:si,di_______________________
mov cx,6
bs:
mov al,ds:[si]
call toasc
mov ds:[di],ah
mov ds:[di+1],al
inc si
inc di
inc di
inc di
loop bs
ret
toasc:
;;_________________________________;btoa的子程序,将al中的bcd码转为两个ascii码,存放在ah,al
;;al
;;ah,al
mov ah,al
shr ah,1
shr ah,1
shr ah,1
shr ah,1
and al,00001111b
add al,30h
add ah,30h
ret
lcmosrb: ;================================= 读取cmos主程序
push cs
pop ds
ifb <colorc> ;=================处理宏参数
mov bl,0eh
else
mov bl,colorc
endif
ifb <rowc>
mov dh,0
else
mov dh,rowc
endif
if <colc>
mov dl,0
else
mov dl,colc
endif
call frc
mov si,offset pcmos
mov di,offset pshow
call btoa
mov ax,ds
mov es,ax
mov bp,offset pshow
mov cx,18
mov bh,0
mov al,0
mov ah,13h
int 10h
endm
assume cs:code,ds:code
row = 0
column =0
pagen =0
color1 = 0ah
wakek = 1dh ;激活键ctrl扫描码
code segment
dm db ' Hello , this is a TSR program '
dm1 db ' current time:',0dh,0ah
dint9 dd 0
stayr:
in al,60h ;从键盘缓冲区读取一个扫描码
cmp al,wakek ;判断 是ctrl则激活tsr
je nxt1
lover: ;退出,调用原int9中断
jmp dword ptr cs:dint9
nxt1:
push ax
push bx
push dx
push es
push bp
mov ax,cs
mov es,ax
mov bp,offset dm
mov cx,offset dint9 -offset dm
mov bh,pagen
mov bl,color1
mov dh,row
mov dl,column
mov al,0
mov ah,13h
int 10h
lmcmosr 1eh,2,62
pop bp
pop es
pop dx
pop bx
pop ax
jmp lover
;<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
start:
mov ax,code
mov ds,ax
mov al,9h
mov ah,35h
int 21h
mov word ptr dint9[0],bx
mov word ptr dint9[2],es
mov dx,offset stayr
mov al,9h
mov ah,25h
int 21h
mov dx,offset start ;计算驻留长度,以节(16字节)为单位,传给入口参数dx
add dx,15
mov cl,4
shr dx,cl
add dx,10h
mov ah,31h ;调用31h号dos功能,驻留并退出
int 21h
code ends
end start
;int9
;al,60h