Real mode assembly III

From OSDev Wiki
Jump to: navigation, search
Difficulty level
Difficulty 1.png

In installment number three of the real mode assembly bare bones series, we're covering a bit of stuff on timing, it's uses, and doing a quick skim of INT 15h.


Timing: Fun in a Few Interrupts

 xor ax,ax
 int 1Ah

That little sprig of code grabs the timer ticks since midnight in CX:DX. It's a great seed for generating random numbers. Think what would happen if you threw in some things like this:

 ror dx,2
 shr cx,3
 xchg dl,dh

You could use them in conjunction with some other instructions (think multiplying, adding, subtracting, etc.) to really create a random number.

Quick rundown of ticks: There are about 18.2 timer ticks per second, and every tick, interrupt 08h is fired. int 08h calls int 1Ch, which you can use for your own personal use. I'll describe using the IVT to program software interrupts you can call for uses like system calls and such. To time approximately one second, you can use hlt 18 times. Tip: use loop to make the resulting code smaller and more readable.

INT 15h

AH=86h - Microsecond Timing

INT 15h does some nifty stuff. Originally meant for accessing the cassette tape system on the original PC and more obscure PCjr, most if not all systems since the mid '80s don't have tape drives. So instead, INT 15h has commonly been used for miscellaneous services. AH=86h is microsecond timing, taking CX:DX as an interval of microseconds to wait for until an iret instruction fires and you get back to whatever you were doing. Note that there is a wait resolution of about 977 microseconds, so it's not extremely accurate, but it's real useful!

AH=0xC2 - PS/2 Mouse

Almost any BIOS since the PS/2 uses this int (at least AH=0xC2) for the PS/2 mouse. The full range of calls on INT 15h are available at your nearest RBIL, but the mouse calls are discussed briefly here.

There are two extremely simple calls: AX=0xC200, which enables or disables the mouse (BH=01h for enabled, 00h for disabled), and AX=0xC201, which simply resets the mouse regardless of what's in BX.

You'll have to look for stuff on these controls to really learn how to use them though.

<- Real mode assembly II  |  Real mode assembly IV ->
Personal tools