0% found this document useful (0 votes)
2 views3 pages

Exp6

Uploaded by

Sumit Rathod
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views3 pages

Exp6

Uploaded by

Sumit Rathod
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Name: Sumit Raghunath Rathod

UID: 2023800094

Experiment No. 6

AIM: Program to generate sound using BIOS interrupts in assembly language.

CODE: .model small


.DATA

;Divisor=1193180/Frequency
;The constant 1193180 Hz (or 1.19318 MHz) is the input clock frequency of
the Programmable Interval Timer (PIT) chip which controls the PC speaker.

TONES DW 4971, 25 ;Sa : Frequency=240Hz


DW 20, 1 ;pause
DW 4419, 25 ;Re : Frequency=270Hz
DW 20, 1 ;pause
DW 3977, 25 ;Ga : Frequency=300Hz
DW 20, 1 ;pause
DW 3729, 25 ;Ma : Frequency=320Hz
DW 20, 1 ;pause
DW 3314, 25 ;Pa : Frequency=360Hz
DW 20, 1 ;pause
DW 2983, 25 ;Dha : Frequency=400Hz
DW 20, 1 ;pause
DW 2651, 25 ;Ni : Frequency=450Hz
DW 20, 1 ;pause
DW 2486, 25 ;Sa : Frequency=480Hz
DW 20, 1 ;pause
.CODE

MOV AX,@DATA
MOV DS,AX

MOV SI,0 ;set up pointer to tones table


NEXT: MOV CX,TONES[SI] ;read frequency division value
CMP CX,0 ;if frequency divisor=0 exit
JZ EXIT
MOV DX,TONES[SI+2] ;else read duration value
ADD SI,4 ;point to next divisor/duration pair
CMP DX,1 ;if duration=1 pause
JZ PAUSE
CALL SPKRON ;turn speaker on
CALL LDTIMER ;set speaker frequency
CALL DELAY ;wait for chosen duration
CALL SPKROFF ;turn speaker off
JMP NEXT
PAUSE:MOV DX,CX
PAUSE2: MOV CX,50H ;pause is a multiple of 50000
ticks
TICK: LOOP TICK
DEC DX ;decrement pause counter
JNZ PAUSE2
JMP NEXT
EXIT: MOV AX,4C00H
INT 21H

SPKRON PROC NEAR


IN AL,61H ;read current state of port 61H
OR AL,3 ;set speaker control bits
OUT 61H,AL
RET
SPKRON ENDP

SPKROFF PROC NEAR


IN AL,61H ;read current state of port 61H
AND AL,0FCH ;clear speaker control bits
OUT 61H,AL
RET
SPKROFF ENDP

DELAY PROC NEAR


WAIT1:MOV CX,0FFFFH
WAIT2:LOOP WAIT2
DEC DX
JNZ WAIT1
RET
DELAY ENDP

LDTIMER PROC NEAR


MOV AL,0B6H ;timer 2 control word
OUT 43H,AL
MOV AL,CL ;output lower byte of count
OUT 42H,AL
MOV AL,CH ;output upper byte of count
OUT 42H,AL
RET
LDTIMER ENDP

END

EXPLANATION: The program uses BIOS interrupts to produce sound. Each sound has a
specific frequency and duration defined in the TONES table. The program
begins by initializing the data segment and setting a pointer to the tones
table. Each tone's frequency divisor and duration values are read
sequentially. If the duration is set to 1, the program adds a pause between
tones, otherwise it activates the speaker, sets the frequency, waits for the
specified duration, and then deactivates the speaker. This process repeats
until all tones are played.

CONCLUSION: I understood how to produce sounds using BIOS interrupts by executing


the above code. The code provided a comprehensive look at assembly
programming's capabilities in controlling hardware directly.

You might also like