问题
When computer starts to boot, It makes a beep sound from the BIOS Speaker.
How do i can do this in Assembly or C++ ?
Clearly I want to make Beep Sound by BIOS Speaker.
Remember i mean BIOS Speakers
Does it have any interrupt for that ? I searched about that but nothing found.. I used some interrupt But the didn't do this. the following code :
int main(){
cout<<"\a";
}
Produced the sound from the Speaker, Not Bios
How can i do this ? with any interrupt ?
回答1:
Try to add this code, too.
.pause1:
mov cx, 65535
.pause2:
dec cx
jne .pause2
dec bx
jne .pause1
in al, 61h ; Turn off note (get value from
; port 61h).
and al, 11111100b ; Reset bits 1 and 0.
out 61h, al ; Send new value.
So, the result is:
void beep(){
__asm{
MOV al, 182 ; Prepare the speaker for the
out 43h, al ; note.
mov ax, 2280 ; Frequency number (in decimal)
; for C.
out 42h, al ; Output low byte.
mov al, ah ; Output high byte.
out 42h, al
in al, 61h ; Turn on note (get value from
; port 61h).
or al, 00000011b ; Set bits 1 and 0.
out 61h, al ; Send new value.
mov bx, 4 ; Pause for duration of note.
.pause1:
mov cx, 65535
.pause2:
dec cx
jne .pause2
dec bx
jne .pause1
in al, 61h ; Turn off note (get value from
; port 61h).
and al, 11111100b ; Reset bits 1 and 0.
out 61h, al ; Send new value.
};
}
回答2:
The only way you can implement this in any modern Windows OS is, I guess, writing Kernel Mode driver. The reason is that in
or out
instructions are not available in user mode, and there is no API for beeper available.
- http://en.wikipedia.org/wiki/Protection_ring
- https://msdn.microsoft.com/en-us/library/windows/hardware/ff554836(v=vs.85).aspx
However, if you're just willing to dig into low-level programming, consider writing own bootloader or even own BIOS (using virtual machine).
回答3:
Try to include this procedure in your C++ program.
void beep(){
__asm{
MOV al, 182 ; Prepare the speaker for the
out 43h, al ; note.
mov ax, 2280 ; Frequency number (in decimal)
; for C.
out 42h, al ; Output low byte.
mov al, ah ; Output high byte.
out 42h, al
in al, 61h ; Turn on note (get value from
; port 61h).
or al, 00000011b ; Set bits 1 and 0.
out 61h, al ; Send new value.
mov bx, 4 ; Pause for duration of note.
};
}
来源:https://stackoverflow.com/questions/29714604/make-beep-sound-in-bios