Reputation: 838
This is the code:
push ax
in al, 0x61
or al, 0x80 ; 10000000b
out 0x61, al
and al, 0x7F ; 01111111b
out 0x61, al
mov al, 0x20
out 0x20, al
pop ax
What does it do? I only know its connected to the timer interrupt. What's on 0x61
and 0x20
?
Upvotes: 6
Views: 4441
Reputation: 92231
There is probably an in al, 0x60
instruction close by.
Ports 0x60 and 0x61 talk to the keyboard controller in a PC. Port 0x60 contains the key pressed, and 0x61 has status bits.
Toggling the high bit of the status port signals that you have gotten the key and want the next one.
Port 0x20 is the interrupt controller, where you acknowledge that you have processed the interrupt.
Upvotes: 5
Reputation: 16113
This has nothing to do with C++. It is purely x86 assembly language with a compiler specific wrapper to allow inline assembly in a compiler. The compiler could be Turbo C, Turbo Pascal or a Microsoft compiler or any compiler that follows the Borland/Microsoft Inline assembly conventions...
This is IBM PC (and clones) code
port 0x61 is related to the PC speaker using the PIT (programmable interval timer)
port 0x20 is related to the PIC (programmable interrupt controller)
Look around for code that plays sound with the PC speaker (not a sound card) and you will find similar code.
Upvotes: 3