;;;;;;;;;;;;;;;;;;;;; Assignment No. 3 Solution ;;;;;;;;;;;;;; [org 0x0100] jmp start oldisr: dd 0 ; space for saving old isr Hello: db 'Hello' ; string hello to be printed World: db 'World' ; string World to be printed ; Subroutine to clear the screen clrscr: push es push ax push cx push di mov ax, 0xb800 mov es, ax ; point es to video base xor di, di ; point di to top left column mov ax, 0x0720 ; space char in normal attribute mov cx, 2000 ; number of screen locations cld ; auto increment mode rep stosw ; clear the whole screen pop di pop cx pop ax pop es ret ; keyboard interrupt service routine kbisr: push ax push es in al, 0x60 ; read a character from keyboard cmp al, 0x2e ; check if the c key has been pressed jne nextcmp ; if not, then jump to next comparison call clrscr ; clear the screen jmp exit ; leave interrupt routine nextcmp: cmp al, 0x23 ; check if the h key has been pressed jne nextcmp2 ; if not, then jump to next comparison mov ah, 0x13 ; load service 13 to print the string mov al, 1 ; subservice 01 to update cursor mov bh, 0 ; output on page 0 mov bl, 7 ; normal attrib mov dx, 0x0032 ; print hello string at first row and 50th column mov cx, 5 ; length of hello string push cs pop es ; segment of string mov bp, Hello ; offset of string int 0x10 jmp exit ; leave interrupt routine nextcmp2: cmp al, 0x11 ; check if the w key has been pressed jne nomatch ; if not, jump to label nomatch mov ah, 0x13 ; if yes, load service 13 to print string mov al, 1 ; subservice 01 to update cursor mov bh, 0 ; output on page 0 mov bl, 7 ; normal attrib mov dx, 0x0039 ; print world string at first row and 57th column mov cx, 5 ; length of World string push cs pop es ; segment of string mov bp, World ; offset of string int 0x10 jmp exit ; leave interrupt routine nomatch: pop es pop ax jmp far [cs:oldisr] ; call the original ISR exit: mov al, 0x20 out 0x20, al ; send EOI to PIC pop es pop ax iret ; return from interrupt start: xor ax, ax mov es, ax ; point es to IVT base mov ax, [es:9*4] mov [oldisr], ax ; save offset of old routine mov ax, [es:9*4+2] mov [oldisr+2], ax ; save segment of old routine cli ; disable interrupts mov word [es:9*4], kbisr ; store offset at n*4 mov [es:9*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 ; make TSR int 0x21