Please disable adblock to view this page.

← Go home

Terminate but Stay Resident (TSR) Program of screen saver (Assembly x86)

April 23, 2016
Published By : Pratik Kataria
Categorised in: ,

code segment
assume cs:code
main :
jmp init
mes db “This is screen saver$”
old_time dd ?
old_kbd dd ?

buff db 4000 dup(0)
cnt db 0
flag db 0

our_time:

push ax
push bx
push cx
push dx
push es
push ds
push ss
push si
push di

mov ax,cs
mov ds,ax

cmp flag,1
je exit_time

inc cnt
cmp cnt,100
jne exit_time

mov flag,01
mov si,0b800h
mov es,si
mov cx,2000
lea di,buff
mov si,0

save:
mov al,es:[si]
mov [di],al
mov al,’ ‘
mov es:[si],al
inc si
inc di
mov al,es:[si]
mov [di],al
mov al,00100111b
mov es:[si],al
inc si
inc di
dec cx
jnz save

lea di,mes
mov si,2000
print_mes:
mov al,[di]
cmp al,’$’
je exit_time
mov es:[si],al
inc di
add si,2
jmp print_mes
exit_time:

pop di
pop si

pop ss
pop ds

pop es
pop dx

pop cx
pop bx
pop ax

jmp cs:old_time

our_kbd:

push ax
push bx
push cx
push dx
push es
push ds
push ss
push si
push di

mov ax,cs
mov ds,ax

mov cnt,0
cmp flag,0
je exit_kbd
mov flag,0
mov si,0b800h
mov es,si
mov si,0

mov cx,4000
lea di,buff
restore:
mov al,[di]
mov es:[si],al
inc si
inc di
dec cx
jnz restore

exit_kbd:

pop di
pop si

pop ss
pop ds

pop es
pop dx

pop cx
pop bx
pop ax

jmp cs:old_kbd
init:
mov ax,cs
mov ds,ax
cli

mov ah,35h
mov al,8
int 21h

mov word ptr old_time,bx
mov word ptr old_time+2,es

mov ah,25h
mov al,8
lea dx,our_time
int 21h

mov ah,35h
mov al,9
int 21h

mov word ptr old_kbd,bx
mov word ptr old_kbd+2,es

mov ah,25h
mov al,9
lea dx,our_kbd
int 21h

mov ah,31h
mov al,0
lea dx,init
int 21h

sti
code ends
end main

View Article Page
Download

Pratik Kataria is a budding programmer, web designer and developer.