Help with interrupts

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
KieranFoot

Help with interrupts

Post by KieranFoot »

can anyone provide an example of programming an interrupt, I allready have an example but it does not explain in detail what is being done, why and how???
User avatar
Solar
Member
Member
Posts: 7615
Joined: Thu Nov 16, 2006 12:01 pm
Location: Germany
Contact:

Re:Help with interrupts

Post by Solar »

The QuickLinks thread should have several; "The Art of Assembly" gives a pretty good introduction to the field as well as ASM examples of how to handle them.
Every good solution is obvious once you've found it.
Frki

Re:Help with interrupts

Post by Frki »

There are some nice texts on this topic on the net, but I'll try to provide you the basic info on how it works.

So, first, you must setup an interrupt. This is the example for the setup of the INT21h routine


; Initalise Interrupt
Initalise_int:
   push ax         ; Save registers
   push es

   ; Setup the segments for the Interrupt Vector Table (0000:0000)
   xor ax, ax      ; Zero ax
   mov es, ax      ; Setup es to equal sx (0000)

   ; Int 21
   mov WORD [es:0x21*4], Int21   ; Procedure
   mov WORD [es:0x21*4+2], cs   ; Segment

   pop es
   pop ax
   ret

.....and somewhere else in the code (or some include file) you have this :


;interrupt 21h routines
Int21:
   ; Contains many functions - Function code passed in AL

   ; 0 - Program terminate
   cmp ah, 0x00
je .INT_ProgramTerminate

   ; 1 - Keyboard input with echo
   cmp ah, 0x01
   je .INT_KeyboardEcho

....so here should be other routines

...
And there is one more thing to remember. When you jump to an interrupt routine, you must use IRET instruction to return to its previous code, not the standard RET or RETF !!!

I hope this helped you to understand the basics of seting up an interrupt !
Post Reply