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?

Ciro Santilli OurBigBook.com
  • 347,512
  • 102
  • 1,199
  • 985
Invader Zim
  • 796
  • 2
  • 14
  • 39

2 Answers2

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.

Bo Persson
  • 90,663
  • 31
  • 146
  • 203
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.

JimR
  • 15,513
  • 2
  • 20
  • 26
  • So it modifies the bits of PIT, which would lets say allow timer interrupts if they are disabled? – Invader Zim Feb 13 '13 at 08: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 '13 at 15:34