You are on page 1of 2

www.VUSR.

net
CS401- Computer Architecture and Assembly Language
Programming
Assignment # 4
Spring 2009
Solution:
Program code:
; Terminate and Stay Resident program to change background color after 10
seconds
[org 0x0100]
jmp start

tickcount: dw 0
attrib: dw 0x07

; timer interrupt service routine


timer: push es
push ax
push cx
push di
SR
inc word[cs:tickcount] ; increment on every tick
cmp word[cs:tickcount], 182 ; Is tickcount equal to 182 (18.2x10)
je clrscr ; If yes, then jump to clrscr
jmp exit ; If no, then jump to exit
U

clrscr: mov word[cs:tickcount], 0 ; reset tickcount


V

mov ax, 0xb800 ; load video base in ax


mov es, ax ; point es to video base
xor di, di ; point di to top left column
mov al, 0x20 ; load space char in al

add word[cs:attrib], 0x10 ; add 16 to the attribute variable


cmp word[cs:attrib], 0x77 ; Is max value reached
jbe continue ; If no, then jump to continue

mov word[cs:attrib], 0x07 ; If yes, load the initial value

continue: mov ah, [cs:attrib] ; load attribute byte in ah


mov cx, 2000 ; number of screen locations
cld ; auto increment mode
rep stosw ; clear the whole screen

exit: mov al, 0x20


out 0x20, al ; send EOI to PIC

Page 1 of 2

http://lms.vusr.net
www.VUSR.net
pop di
pop cx
pop ax
pop es
iret ; return from interrupt

start: xor ax, ax


mov es, ax ; point es to IVT base
cli ; disable interrupts
mov word [es:8*4], timer ; store offset at n*4
mov [es:8*4+2], cs ; store segment at n*4+2
sti ; enable interrupts

mov dx, start ; end of resident portion


add dx, 15 ; round up to next para
mov cl, 4
shr dx, cl ; number of paras
mov ax, 0x3100 ; terminate and stay resident
int 0x21

SR
U
V

Page 2 of 2

http://lms.vusr.net

You might also like