ioportb.txt
来自「控制pc speaker发生的汇编程序.c++编写启动发声与停止发生程序」· 文本 代码 · 共 56 行
TXT
56 行
//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 + =
减小字号Ctrl + -
显示快捷键?