Real mode assembly IV
The IVT, in all it's Glory
The IVT is an array of 1024 bytes, arranged in 16-bit words. The address of the interrupt handler is stored with the offset word first, segment second. Thing's couldn't be easier.
Adding a BIOS INT Style Handler
My style of handler goes like this:
inthandler: cmp ah,0 je .ahzero cmp ah,1 je .ahone cmp ah,2 je .ahtwo ; ...... mov si,msgBadAH call print_string cli hlt .ahzero: ; Do whatever needed here iret
But that's just an outline, you'd need to do it up however you need to use your calls. The FLAGS register is restored in an iret so you need to set it on the stack again depending on how it's set before the iret is done!
Adding the Handler to the IVT
This is fairly simple.
- First, null out ES.
- Set AL=interrupt number, and BL=4h.
- Multiply AL by BL, and then put the result (AX) in BX.
- Move the word that is the address of the start of your interrupt handler into [es:bx].
- Add 2 to BX.
- Move your handler's segment into [es:bx].
- Restore your original ES and you're done!