PAGE 75, 132 TITLE BEEP - John Lockwood - 10/96, revised 10/97 ; Copyright 1996-1997, John Lockwood CR EQU 13 LF EQU 10 extrn dosxit:near, kbdin:near, dspmsg:near, binasc:near ;====== SECTION 3: Define stack segment =================================== stkseg segment stack ; *** STACK SEGMENT *** db 64 dup ('STACK ') stkseg ends ;====== SECTION 4: Define code segment ==================================== cseg segment public 'CODE' ; *** CODE SEGMENT *** assume cs:cseg, ds:cseg, ss:stkseg, es:nothing ;====== SECTION 6: Main procedure ========================================= pbuf db 7 dup(?) crlf db CR,LF,'$' freq_msg db ' Freq = $' count_msg db ' Hz, Count = $' main proc far mov ax, cseg ; Initialize DS register mov ds, ax mov al,10110110b ; Timer2, Load L+H, square wave, binary out 43h,al ; Write timer control byte in al,61h or al,00000011b ; Enable Timer2 & Turn on speaker out 61h,al mloop: call kbdin cmp al,'0' ; 0 to quit je mdone sub al,'0' mov ah,0 mov cl,8 ; Freq * 256 (Hz) shl ax,cl mov dx,offset freq_msg call dspmsg mov bx,offset pbuf call binasc mov dx,offset pbuf call dspmsg ; Print Freq mov bx,ax mov ax,34DCh ; DX:AX=1,193,180 (tics/sec) mov dx,12h ; AX = ------------------------- div bx ; BX=Freq (1/sec) mov dx,offset count_msg call dspmsg mov bx,offset pbuf call binasc mov dx,offset pbuf call dspmsg ; Print count mov dx,offset crlf call dspmsg out 42h,AL ; Write Low byte to Timer Channel 2 mov al,ah ; out 42h,AL ; Write High byte to Timer Channel 2 jmp mloop mdone: in al,61h and al,11111100b ; Turn off speaker out 61h,al call dosxit ; Exit to DOS main endp cseg ends end main