Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/assembly/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 在BIOS中发出嘟嘟声_C++_Assembly_Interrupt_Bios - Fatal编程技术网

C++ 在BIOS中发出嘟嘟声

C++ 在BIOS中发出嘟嘟声,c++,assembly,interrupt,bios,C++,Assembly,Interrupt,Bios,当计算机启动时,它会从BIOS扬声器发出嘟嘟声 如何在汇编或C++中实现这一点? 显然,我想通过BIOS扬声器发出嘟嘟声。 记住我指的是BIOS扬声器 这有什么中断吗?我到处找,但什么也没找到。。 我使用了一些中断,但没有这样做。以下代码: int main(){ cout<<"\a"; } intmain(){ CUT尝试将此过程包含在C++程序中。 void beep(){ __asm{ MOV al, 182 ; Prepare

当计算机启动时,它会从BIOS扬声器发出嘟嘟声

如何在汇编或C++中实现这一点? 显然,我想通过BIOS扬声器发出嘟嘟声。
记住我指的是BIOS扬声器

这有什么中断吗?我到处找,但什么也没找到。。 我使用了一些中断,但没有这样做。以下代码:

int main(){
   cout<<"\a";
}
intmain(){

CUT

尝试将此过程包含在C++程序中。

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.
因此,结果是:

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.

   };
}

我想,在任何现代Windows操作系统中实现这一点的唯一方法就是编写内核模式驱动程序。原因是
in
out
指令在用户模式下不可用,而且没有适用于蜂鸣器的API


但是,如果你只想深入研究低级编程,考虑编写自己的引导加载程序,甚至是自己的BIOS(使用虚拟机)。.

你的操作系统是什么?windows?还有其他方法吗?在汇编中?好吧,windows取消了对windows 7内置扬声器的支持。@immibis:我可以为此编写驱动程序吗?:)
In
out
是特权指令。它们在用户模式应用程序中无法工作。可能,你的嘟嘟声是从PC扬声器或耳机发出的;没有来自PC BIOS扬声器的声音。那么您确定您的设备不会产生任何声音吗?