A programmable interval timer is the way to go. If you will only deal with new systems, learn HPET. There are a few things to know for PIT. Firstly, to configure it, you need to use port 0x43 as the control / command port to set the zero channel timer. The byte we want to send is a bitmap field:
7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 +----------------------------------------------+ | Channel | RW Mode | Channel Mode | BCD?| +----------------------------------------------+
The channel will be cleared to select the zero channel.
The RW model can be 1-LSB, 2-MSB or 3-LSB, followed by an MSB. We want both bits to be (bit pattern 3, 011), because we need to send a 16-bit value (LSB, then MSB)
For channel mode, we need a square wave. This is a bit pattern from 3 (011)
We want to send a 16-bit divider for the counter, not the BCD value, so the low bit is cleared.
This gives us: 000110110 in binary format or 0x36 in hexadecimal format. Now we have installed it:
mov al, 0x36 ; 0x36 from our work above out 0x43, al ; Send that byte to the control port mov ax, 11931 ; The timer ticks at 1193182. 100hz would be 1193182/11931 out 0x40, al ; send low byte out 0x40, ah ; send high byte
At this point, you need to decide whether you will respond to the interrupt (IRQ 0) or just want to read the timer. I will point you to this excellent link to OSDev, which has a brilliant entry on both code examples.