; This program redirects the 00H function of the 2FH interrupt

; Actually the interrupt is redirected, but the handler manages

; only the 00h function.The other functions are sent to the original

; handler.

  

 

assume cs:cseg, ds:cseg

 

cseg segment

 

;the address of the old handler for the 2Fh interrupt

oldInt   dd ?

 

;the message that will be displayed when the function 00H of the 2Fh interrupt is called

mesaj   db 'The 00h function of the 2Fh interrupt has been redirected',10,13,'$'

 

handler proc far

            ; inhibits the interrupts

            cli

            ; test if the called function is the 00h function

        cmp ah, 00h

        ;otherwise call the original handler is called

        jne orig

           

            ; The called functin is 00H function

            ;saves on the stack the content of the registries  registrilor ce

            ; that will,eventually, be modified.

        push ax

        push bx

        push dx

        push ds

 

            ; puts into the ds registry the address of the code segment

            ; data is kept here into the code segment [OldInt and the message]

        push cs

        pop ds

        ; dispaly the message using the 09h function of the 21h interrupt

        mov ah, 09h

        mov dx, offset mesaj

        int 21h

 

            ; restores the modified registries

        pop ds

        pop dx

        pop bx

        pop ax

        sti

       

        ;return from the interrupt's handler

        iret

orig:

            ;calls the original handler through a far call [seg]:[offset]

        call dword ptr cs:[oldInt]

        sti

        ; Return far. We don't use iret because the flag registry

        ; was already poped out from the stack by the original handler

        ; through iret. iret would be incorrect here because it would realise another

        ; pop up operation for the flags from the stack, while those no longer

        ; exist on the stack.

        retf

handler endp

 

start:

        mov ax, cseg

        mov ds, ax

       

        ; obtain the address of the original handler of the interrupt

        mov ax, 352Fh

        int 21h

       

        ;saves the address of the original handler

        mov word ptr [oldInt+2], es

        mov word ptr [oldInt], bx

 

            ; inactivates the interrupt while the address of the handler is changed

            cli

            ; assigns the new address of the handler for the 2Fh interrupt

        mov ax, 252Fh

        mov dx, offset handler

        

        ;ds is already set on  cseg

        int 21h

            sti

           

            ; call of the interrupt 2Fh with the function 00h. Our handler will be called

        mov ah, 00h

        int 2Fh

           

            ; restores the original handler of the 2Fh interrupt 

        mov ax, 252Fh

        mov dx, word ptr [oldInt]

        mov bx, word ptr [oldInt+2]

        mov ds, bx

        int 21h

 

        mov ax,4c00h

        int 21h

cseg ends

end start