;speaker output example

Connect speaker


; initialization of 8254 timer
	MOV        AL,B6        ; control word for mode-3
        OUT        43,AL        ; to control port of speaker

	MOV	CX,ffff
Again:
	
;"counter" (port 42) of speaker needs to be loaded with value 
;that is 1193180/desired frequency.
;ex:  tone of 238 Hz = 1193180/5000      5000=1388h        
	MOV	AX,1388
;output low and then high bytes of AX to port 43
        OUT	42,AL
        MOV	AL,AH	;move high byte to low for output
        OUT 	42,AL

	CALL KillTime
        
	MOV	AX,9C4		;=2500 dec.  ~580 Hz

        OUT	42,AL
        MOV	AL,AH	;move high byte to low for output
        OUT 	42,AL
                
	CALL KillTime                                
                
	LOOP	Again                                
                
        ;To stop the sound, set cntr to zero		
	
	HLT
		
PROC KillTime
	PUSH	DX	;save registers will use
	PUSH	BX
		
	MOV	DX,ffff
 burncpu:			
	mul	bl		;kill time
	mul	bl
	mul	bl
	dec	DX
	JNZ	burncpu
		
	POP	BX	;restore registers
	POP	DX
	RET         
				