You are on page 1of 3

Computer Architecture and Assembly

Language Programming Practical (CS401P) Lab No. 13

Problem Statement

You are required to write a TSR program that will print characters of your name on new line once
you press ‘p’ from keyboard.

Solution

name db 'YourName', 0
newline db 13, 10, '$'
prevInt9 dw 0
org 0x0100
mov ax, 0
mov ds, ax
; Save the original interrupt vector at INT 9
mov ax, 3509h
int 0x21
mov word [prevInt9], bx
mov word [prevInt9+2], es
; Install our interrupt handler at INT 9
mov ax, SEG keyHandler
mov es, ax
mov bx, OFFSET keyHandler
mov ah, 25h
mov al, 9
int 0x21
; Terminate and Stay Resident (TSR)
mov ah, 31h
int 0x21

keyHandler:
pushf ; Save flags
push ax ; Save AX register
; Check if the 'p' key is pressed (ASCII code 112)
mov ah, 1
int 0x16
cmp al, 112
jne skipPrintName
; Print the name on a new line
mov dx, name
mov ah, 9
int 0x21
; Print newline characters
mov dx, newline
mov ah, 9
int 0x21
skipPrintName:
pop ax ; Restore AX register
popf ; Restore flags
; Call the original interrupt handler
pushf
call dword [prevInt9]
retf
; Define the TSR signature and padding

times 0x100-($-$$) db 0

Further, For any queries feel free to send an email at cs401P@vu.edu.pk or join the weekly interactive
session

You might also like