staseg segment para stack 'stack'
dw 32h dup(?)
staseg ends
dseg segment
table dw 262,294,330,349,392,440,494,523
dseg ends
codes segment 'code'
assume ss:staseg,cs:codes,ds:dseg
start: mov ax,dseg
mov ds,ax
new_note:
mov ah,0
int 16h
cmp al,0dh
je exit
mov bx,offset table
cmp al,'1'
jb new_note
cmp al,'8'
ja new_note
and ax,0fh
shl ax,1
sub ax,2
mov si,ax
mov di,[bx+si]
mov bx,20
call gensound
jmp new_note
exit: mov ah,4ch
int 21h
gensound proc
mov al,10110110b
out 43h,al
mov dx,12h
mov ax,34deh
div di
out 42h,al
mov al,ah
out 42h,al
in al,61h
mov ah,al
or al,3
out 61h,al
wait1: mov cx,8ff0h
delay1: loop delay1
dec bx
jnz wait1
mov al,ah
out 61h,al
ret
gensound endp
codes ends
end start