6

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?

5

2 Answers 2

5

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.

2

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.

2
  • So it modifies the bits of PIT, which would lets say allow timer interrupts if they are disabled? Feb 13, 2013 at 8:00
  • @InvaderZim: I am not sure that interrupts will fire if disabled and no longer have the books or magazines that cover this stuff. It's also possible that Bo Persson is right that this is keyboard code. But, I distinctly remember port 0x61 being related to making sound with the PC speaker. Google may help. I'd suggest searching for "port 0x61 PC assembler" (without the quotes) and see what you find. As stated by Bo Persson, out 0x20, 0x20 lets the PIC know you're done handling the interrupt.
    – JimR
    Feb 13, 2013 at 15:34

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.