2013-06-22 46 views
1

我試圖用8086程序集生成特定頻率的聲音。我搜索並搜索了許多關於連接揚聲器的代碼(不是PC揚聲器)。然而,他們似乎都沒有工作。下面是我的代碼:在程序集中生成聲音8086

mov  al, 182   ; meaning that we're about to load 
    out  43h, al   ; a new countdown value 

    mov  ax, 2153  ; countdown value is stored in ax. It is calculated by 
          ; dividing 1193180 by the desired frequency (with the 
          ; number being the frequency at which the main system 
          ; oscillator runs 
    out  42h, al   ; Output low byte. 
    mov  al, ah   ; Output high byte. 
    out  42h, al    

    in  al, 61h   
          ; to connect the speaker to timer 2 
    or  al, 00000011b 
    out  61h, al   ; Send the new value 

我覺得這是應該產生一個聲音,直到我們以某種方式設法告訴揚聲器關閉。儘管如此,聽不到任何聲音。你能告訴我代碼有什麼問題嗎?

+0

該代碼確實嘗試訪問PC揚聲器。你如何運行它? – duskwuff

+0

在emu8086模擬器中。它有什麼問題嗎? – user2511906

+0

根據我正在閱讀的內容[在Emu8086硬件頁面上](http://emu86.com/virtual_devices.html),它不模擬PC硬件,所以在I/O端口沒有揚聲器試圖訪問。如果您需要,請使用[DOSBox](http://www.dosbox.com/)之類的東西。 – duskwuff

回答

1

總結這一點:你的代碼看起來很好。問題在於你在一個不適用於PC平臺的8086仿真器上運行它(因此沒有連接到該I/O端口的揚聲器)。

-1

生成正弦波在零交叉處開始和結束可能更容易,然後使用內置的OS功能重複播放文件。