在BIOS中发出哔声

时间:2015-04-18 07:58:25

标签: c++ assembly interrupt bios

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

我如何在Assembly或C ++中执行此操作? 显然我想通过BIOS Speaker制作Beep Sound。
请记住我的意思是BIOS发言人

它有中断吗?我搜索了但没有发现.. 我使用了一些中断但是没有这样做。以下代码:

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

从Speaker,Not Bios产生声音

我该怎么做?有任何中断吗?

3 个答案:

答案 0 :(得分:1)

尝试添加此代码。

.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.

   };
}

答案 1 :(得分:1)

在任何现代Windows操作系统中实现此功能的唯一方法是编写内核模式驱动程序。原因是inout指令在用户模式下不可用,并且没有可用蜂鸣器的API。

但是,如果你只是愿意深入研究低级编程,可以考虑编写自己的bootloader甚至自己的BIOS(使用虚拟机)。

答案 2 :(得分:-1)

尝试在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.
   };
}
相关问题