Page 1 of 1

Timer interrupt handling in DOS real mode using gcc and NASM

Posted: Wed Sep 20, 2006 12:28 am
by Dharma
I want to trigger and handle a timer interrupt (INT 08H) in DOS real mode. I need an example how can I achieve it using INT 21h with the functions 25h and 35h. I am using NASM for assembly programming and gcc for c programming.

My algorithm should be like

main()
{
...
...
intialize 8259 pic;
program 8253 for desired time interval (interrupt for every 10 ms);

while(1);/* infinite loop */
}

---assembly code---

timer_isr_hook:

Hook the user defined timer interrupt isr to the timer interrupt(08).

timer_isr:

save the registers
call timer_hand /* this should be a c function in which I want to call
the scheduler module */
restore the registers
iret

Can anyone come with a good solution for this???

Posted: Wed Sep 20, 2006 1:22 am
by blackcatcoder
my advice is, to read the Intel manuals for programming the 8259 but you will find enough code if you search on google.

as you said that you want to use int 21h in DOS mode so here is an little example how to install an ISR:


mov dx, your_isr ; offset of your timer int, don't forget to load ds with the right segment
mov ax, 2505h ; interrupt vector 5 and function 25
CLI ; disable all ints
INT 21h
STI ;enable all ints


hope this will help ya ;-)

Posted: Thu Sep 21, 2006 11:33 pm
by hailstorm
Don't forget to save the 'old' isr address either, since DOS uses it to handle some things. This isr needs to be called each time your own isr is executed and must be restored when your program exits.