Sunday, July 21, 2019

CS401 assignment no 3 Complete Solution

  • HTML

  • Code

    [org 0x0100]

    jmp start


    oldisr: dd 0 ; space for saving old isr

    ; keyboard interrupt service routine

    kbisr:

    push ax

    push es

    mov ax, 0xb800

    mov es, ax ; point es to video memory

    in al, 0x60 ; read a character from keyboard port

    cmp al, 0x11 ; has the 'w' key pressed

    jne nomatch ; no, go to nomatch

    mov byte [es:0], '1' ; yes, print 1

    mov byte [es:2], '5' ; yes print 0

    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 ; sent 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 interrupt

    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 residant

    int 0x21
    Try it Yourself »

    1 comment: