Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Modify the TONE.ASM program so that the 0.25-second 1 KHz tones plays five times

ID: 3807255 • Letter: M

Question

Modify the TONE.ASM program so that the 0.25-second 1 KHz tones plays five times, once each second. Hint: Use DOS INT 21H Function 2CH (Get Time)

I need help getting the following code to work. I can get it to beep once, but once I added the code between the ********************** sections it wont beep five times.

Can someone correct the following code?

;Program TONE.ASM: Generate a tone through the PC speaker for 1/4 second once every 5 seconds.
;
.MODEL SMALL
.DATA
OUTER DW 125 ;outer loop count
INNER DW 1000 ;inner loop count
NOW       DB 00
.CODE
.STARTUP
CALL SPKRON ;turn speaker on
MOV CX,1190 ;divisor for 1 KHz tone
CALL LDTIMER ;set speaker frequency
       CALL DELAY ;wait for chosen duration
       CALL SPKROFF ;turn speaker off
.EXIT

SPKRON PROC NEAR
IN AL,61H ;read current state of port 61h
OR AL,3 ;set speaker control bits
OUT 61H,AL ;output new state
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 ;output new state
RET
SPKROFF ENDP

DELAY PROC NEAR
MOV DX,OUTER
WAIT1: MOV CX,INNER
WAIT2: NOP
NOP
NOP
NOP
LOOP WAIT2
DEC DX
JNZ WAIT1
;*****************************************
       MOV AH,2CH  
       INT 21H       
       MOV NOW,DH  
WAIT3:   MOV AH,2CH  
       INT 21H      
       CMP NOW,DH  
       JZ   WAIT3      
;*****************************************
       RET
DELAY ENDP


      
;Note: Output frequency equals 1,190,000 divided by CX

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 / Answer

Program TONE.ASM: Generate a 1 KHz tone on the PC speaker for 5 seconds.
;
.MODEL SMALL
.DATA
;Note: You will have to adjust these values to get the 5 seconds.
;The current values give just over 1 second on a 1.3 GHz machine.
OUTER
DW
40
;outer loop count
INNER
DW
500
;inner loop count
.CODE
.STARTUP
CALL SPKRON
MOV
CX,1190
CALL LDTIMER
CALL DELAY
CALL SPKROFF
.EXIT
SPKRON NEAR
AL,61H
AL,3
61H,AL ;read current state of port 61h
;set speaker control bits
;output new state SPKROFF PROC
IN
AND
OUT
RET
SPKROFF ENDP NEAR
AL,61H
AL,0FCH
61H,AL ;read current state of port 61h
;clear speaker control bits
;output new state DELAY NEAR
DX,OUTER
CX,INNER SPKRON WAIT1:
WAIT2: DELAY PROC
IN
OR
OUT
RET
ENDP ;turn speaker on
;divisor for 1 KHz tone
;set speaker frequency
;wait for chosen duration
;turn speaker off PROC
MOV
MOV
NOP
NOP
NOP
NOP
LOOP
DEC
JNZ
RET
ENDP WAIT2
DX
WAIT1 ;Note: Output frequency equals 1,190,000 divided by CX
LDTIMER PROC
MOV
OUT
MOV
OUT
MOV
OUT
RET
LDTIMER ENDP
END NEAR
AL,0B6H
43H,AL
AL,CL
42H,AL
AL,CH
42H,AL ;timer 2 control word
;output lower byte of count
;output upper byte of count

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote