Murugan.com
Murugan Andezuthu Dharmaratnam

  |  HOME   |  BLOG   |  TWITTER   |  ARTICLES   |  8086  |  C++   |  VC++   |  ASP .NET   |  VB .NET   |  JAVA SCRIPT   |  MS SQL   |  PHP   |  MY   |  VIDEOS   |  DOWNLOADS   |  CONTACT ME   |  



8086 assembly language program to play sound using pc speaker


Home  > 8086  > 8086 assembly language program to play sound using pc speaker 
       
You could create sound from the PC Speaker in 8086 Assembly Language by communicate with the speaker controller using IN and OUT instructions. 


This is what u need to do
      1, Set up the speaker by sending the value 182 to port 43h. .
      2. Send the frequency number to port 42h. U can check the table below for the same. 
      3, To start the beep, bits 1 and 0 of port 61h must be set to 1. Since the other bits of port 61h have other uses, they must not be modified. Therefore, you must use an IN instruction first to get the value from the port, then do an OR to set the two bits, then use an OUT instruction to send the new value to the port.
      4. Pause for the duration of the beep.
      5.Turn off the beep by resetting bits 1 and 0 of port 61h to 0. Remember that since the other bits of this port must not be modified, you must read the value, set just bits 1 and 0 to 0, then output the new value.

The following code fragment generates a beep with a frequency of 261.63 Hz (middle C on a piano keyboard) and a duration of approximately one second:

        mov     al, 182         ; Prepare the speaker for the
        out     43h, al         ;  note.
        mov     ax, 4560        ; Frequency number (in decimal)
                                ;  for middle 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, 25          ; 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.

Another way to control the length of beeps is to use the timer interrupt. This gives you better control over the duration of the note and it also allows your program to perform other tasks while the note is playing.


Note 	Frequency 	Frequency #
C 	130.81 	9121
C# 	138.59 	8609
D 	146.83 	8126
D# 	155.56 	7670
E 	164.81 	7239
F 	174.61 	6833
F# 	185.00 	6449
G 	196.00 	6087
G# 	207.65 	5746
A 	220.00 	5423
A# 	233.08 	5119
B 	246.94 	4831
Middle C 	261.63 	4560
C# 	277.18 	4304
D 	293.66 	4063
D# 	311.13 	3834
E 	329.63 	3619
F 	349.23 	3416
F# 	369.99 	3224
G 	391.00 	3043
G# 	415.30 	2873
A 	440.00 	2711
A# 	466.16 	2559
B 	493.88 	2415
C 	523.25 	2280
C# 	554.37 	2152
D 	587.33 	2031
D# 	622.25 	1917
E 	659.26 	1809
F 	698.46 	1715
F# 	739.99 	1612
G 	783.99 	1521
G# 	830.61 	1436
A 	880.00 	1355
A# 	923.33 	1292
B 	987.77 	1207
C 	1046.50 	1140
8086 Assembly Lanaugage Clear the screen

8086 Assembly Lanaugage Program to Draw a box

8086 Assembly Writing Directly to Video Memory B800

8086 Assembly Causes a Delay in terms of 1 60 of a second Delay Macro

8086 Assembly Hello World Application

8086 Assembly Terminate the program and return to Dos prompt

8086 Assembly Language Wati for a keystroke or pause macro

8086 Assembly Language Delay Macro

8086 Game Programming Collusion Detection

8086 Assembly Game Collusion Detection Macro

8086 Assembly Lanuage Set the video display mode

8086 Write matrix of bytes to a memory game pogramming

8086 Assembly Language code procedure for delay

8086 Code Type String or Display String

8086 Assembly Language Convert from Hex to ascii

8086 Assembly Language Press Any Key to Continue Dialog

8086 Assembly Dialogbox or display a box with shadow in text mode

8086 Assembly cls clrscr or clear the screen

8086 assembly language read a string using standard input keyboard

8086 assembly language compare two strings strcmp procedure

8086 Assemly file io proc procedure to open a file

8086 Interrupt List

8086 Assembly Close FIle. Close a file opened for read write

8086 assembly language

8086 Assembly Language Sound Blaster Programming Play wav File

8086 assembly language program to play sound using pc speaker



  |  HOME   |  BLOG   |  TWITTER   |  ARTICLES   |  8086  |  C++   |  VC++   |  ASP .NET   |  VB .NET   |  JAVA SCRIPT   |  MS SQL   |  PHP   |  MY   |  VIDEOS   |  DOWNLOADS   |  CONTACT ME   |  

Copyright 2009 @ Murugan Andezuthu Dharmaratnam