这个x86汇编语言代码与IO端口0x61和0x20有什么关系?

时间:2013-02-13 07:42:21

标签: assembly x86 interrupt

这是代码:

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

它做什么?我只知道它连接到定时器中断。 0x610x20上的内容是什么?

3 个答案:

答案 0 :(得分:3)

附近可能有in al, 0x60条指令。

端口0x60和0x61与PC中的键盘控制器通信。端口0x60包含按下的键,0x61具有状态位。

切换状态端口的高位信号表示您已获得密钥并希望下一个密钥。

端口0x20是中断控制器,您可以在此确认已处理中断。

答案 1 :(得分:2)

这与C ++无关。它纯粹是x86汇编语言,具有编译器特定的包装器,允许在编译器中进行内联汇编。编译器可以是Turbo C,Turbo Pascal或Microsoft编译器或遵循Borland / Microsoft Inline汇编约定的任何编译器......

这是IBM PC(和克隆)代码

端口0x61与使用PIT(可编程间隔定时器)的PC扬声器相关

端口0x20与PIC(可编程中断控制器)

有关

查看使用PC扬声器(不是声卡)播放声音的代码,您会发现类似的代码。

答案 2 :(得分:0)

asm {
    push ax            //normal push opr
    in al, 0x61        // in for input. 0x61 is hexadecimal number. just like 14,15 as in decimal.in c++ we use 0x

    or al, 0x80 // 10000000b  //or operation b/w lower butes of accumulator and 0x80
    out 0x61, al  //output 
    and al, 0x7F // 01111111b  //and opr b/w al and 0x7f
    out 0x61, al  //
    mov al, 0x20   //move 0x20 into  lower bytes of accumulator(al) 
    out 0x20, al   
    pop ax      //remove accumulator from stack.
    }
相关问题