News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

how to use [int 1ch] and [int 08h]?

Started by guesehsaio, May 30, 2005, 03:42:00 AM

Previous topic - Next topic

guesehsaio

hello all:
as title..i want to interrupt automatically  called on each clock . i get information use (int 1ch,int 08H)
@ internet.but i don't  how to use ?i want to a timer ,like hour:minute:second additional @ my main program.(int 1ah/ah=02h).how to interrupt automatically?

MichaelW

Hello guesehsaio,

We could provide a better answer if you would explain a little more of what you are trying to do.

eschew obfuscation

guesehsaio

Quote from: MichaelW on May 30, 2005, 10:30:54 AM
Hello guesehsaio,

We could provide a better answer if you would explain a little more of what you are trying to do.
for example: i know int 1ah/ah=02h is get real time but why could i interrupt it per 1/18.2 second
i went to do a timer @ my program...

it's seem ok use [int 8h] and [int 1ch] but how to do.....
anyone have sample program for me reference...
sorry my engish very poor...thanks!

MichaelW

You might want to read the last paragraph first.

Interrupt 1Ch, the User Timer Tick, would probably be a better choice that Interrupt 8 because the code for the interrupt handler can be simpler. To receive Interrupt 1Ch your program must provide an interrupt handler and "hook" the Interrupt 1Ch "vector", redirecting it to the new handler. An interrupt "vector" is the far address of the interrupt handler. For real mode, the system maintains a table of interrupt vectors in low memory, one for each of the 256 interrupts. To "hook" an interrupt vector you would normally get and save the current vector value using Interrupt 21h function 35h, and then set the vector to the address of the new handler using Interrupt 21h function 25h. The saved vector value must be used to restore the interrupt vector before the program exits, and depending on the particular interrupt and what the handler needs to do, it can also be used within the handler to "chain" to the previous handler.

The handler should preserve all registers (other than the flags register, which the processor automatically preserves). When the handler receives control, the only segment register with a known value is CS. The simplest method of dealing with this is to place any data that the hander uses in the program code segment, and access the data from within the handler with a CS segment override. For your purposes, there is probably no need to chain to the previous handler, so your handler can simply use an IRET to return to the caller.

There is a potential problem with calling a BIOS function from within an interrupt handler because the BIOS functions are generally not reentrant. If the timer tick interrupted the processor while it was executing a BIOS function, and your handler then called the same function, the function and perhaps the system could fail. There is a method of preventing this problem from happening, but it involves an additional interrupt handler.

Because the timer tick could interrupt processes other than your program, and call your handler as a result, even though the handler would be part of the program, it would be limited in how it could interact with the main part of the program. Without getting into all of the reasons for this, some of them complex, the interaction is normally limited to setting variables that the main part of the program can poll in a loop. The handler could, for example, set a flag to indicate that a timer tick had occurred, and the polling loop in the main program could check the flag, call Interrupt 1Ah, clear the flag, and continue looping.

If you don't actually need to use the timer tick interrupt directly, there is a much easier alternative. You could code the program to poll the count of the timer ticks since midnight that the BIOS maintains in the DWORD at offset address 6Ch in the BIOS data area, located at segment address 40h. The polling loop could compare the count to the value saved on the previous loop, and if the count had changed, indicating that a timer tick had occurred, save the count (for use in the next loop), call Interrupt 1Ah, etc, and continue looping.
eschew obfuscation