10

In Assembly Language we have the DOS interrupt INT 21h, which is not a hardware interrupt.

I was wondering if it was possible to write my own interrupt and call it.

If possible, please suggest links or methods.

1 Answers1

23

Yes, you can create your own interrput handler and call it whenever you want. You will need to set up the interrupt vector (which starts at address 0000:0000) to point to your own interrupt handler.

The pointer to each handler consumes 4 bytes (offset and segment) so if for example you want to setup your interrupt handler for INT 22h you would update the interrput vector at location 0000:0088h to point to your handler.

Check Ralph Brown's interrupt list to check an unused interrupt number (at least one that is not used by a hardware interrput).

Here goes an example of how to set up a handler for interrupt 22h:

INITIALIZE: 
      XOR AX,AX
      MOV ES,AX
      CLI ; Disable interrupts, might not be needed if seting up a software-only interrupt
      MOV WORD PTR ES:[136], OFFSET INT22  ; setups offset of handler 22h
      MOV WORD PTR ES:[138], CS            ; Here I'm assuming segment of handler is current CS
      STI ; Reenable interrupts
      ; End of setup


INT22  PROC FAR
       ; Here goes the body of your handler
       IRET
INT22  ENDP
gusbro
  • 22,357
  • 35
  • 46
  • I get that, but something like a file write feature in INT 21H, is programming that possible. Besides, can you give an example of setting up an Interrupt. Would be of great help Sir. – Total Anime Immersion Sep 17 '12 at 17:38
  • @TotalAnimeImmersion: Yes, you can do whatever you want in the interrupt handler. Added an example of setting up the handler. – gusbro Sep 17 '12 at 18:04
  • 1
    If you're not using DOS and wondering which vectors you should use, the [8086 intel manual](https://edge.edx.org/c4x/BITSPilani/EEE231/asset/8086_family_Users_Manual_1_.pdf) (section 2 pg 25) suggests vectors 32-255 (0x80-0x3ff in memory), as the lower vectors are "reserved" by intel, which, of course, is a suggestion because it can't be enforced in real-mode. – James M. Lay Jan 15 '17 at 02:38