⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ioportb.txt

📁 控制pc speaker发生的汇编程序.c++编写启动发声与停止发生程序
💻 TXT
字号:
//1,控制pc Speaker发生的汇编程序 
.386p
model flat
_TEXT segment dword public use32 "CODE"

_InPortB proc near
push ebp
mov ebp, esp
mov dx, word ptr [ebp + 8]
in al, dx
pop ebp
ret
_InPortB endp

_OutPortB proc near
push ebp
mov ebp, esp
mov dx, word ptr [ebp + 8]
mov al, byte ptr [ebp + 12]
out dx, al
pop ebp
ret
_OutPortB endp

public _InPortB
public _OutPortB

_TEXT ends

end

//2,c++调用程序
//---------------------------------------------------------------------------
void Sound( int aFreq )                //启动发声  
{
    //aFreq 发生的频率
    if ((aFreq>=20) && (aFreq<=20000))
    {
        aFreq=1193181/aFreq;
        Byte b=InPortB(0x61);
        if((b&3)==0)
        {
            OutPortB(0x61,Byte(b|3));
            OutPortB(0x43,0xb6);
        }
        OutPortB(0x42,(Byte)aFreq);
        OutPortB(0x42,(Byte)(aFreq>>8));
    }
}
//---------------------------------------------------------------------------
void NoSound( void )                   //启动发声           
{
    Byte b=Byte(InPortB(0x61)&0xfc);
    OutPortB(0x61,b);
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -