Help with interrupts
Help with interrupts
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???
Re:Help with interrupts
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.
Re:Help with interrupts
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 !
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 !