INCLUDE PCMAC.INC
.MODEL SMALL ; Small memory model
.586 ; Pentium Instruction Set
.STACK 100h ; Stack area, saves 256 bytes
.DATA
;--------------Other Messages----------------
Explan1 DB 'This program is designed to play various key frequencies. $'
Explan2 DB 'a,s,d,f,j,k, and l are normal notes while w, r, i, and p $'
Explan3 DB 'are sharps/flats. The n key is octave up and the m key is $'
Explan4 DB 'octave down, while the enter key is used to exit. $'
;-----------Input Setup----------------------
Char_Array DB 'a', 's', 'd', 'f', 'j', 'k', 'l', 'i', 'p', 'r', 'w'
Freq_Array DW 440, 494, 550, 588, 660, 698, 800, 310, 370, 278, 466
Freq_Array2 DW 880, 988, 1100, 1174, 1320, 1396, 1600, 622, 740, 554, 932
Freq_Array3 DW 1760, 1976, 2200, 2348, 2640, 2792, 3200, 1244, 1480, 1108, 1864
Newline DB 13,10, '$'
;----------------Variables-------------------
Octave DB 1
Save DW 0
divider DD 1e294h
.CODE
Main PROC
;----------Display Explanation---------------
mov ax, @DATA
mov ds, ax
_PutStr Explan1
_PutStr Newline
_PutStr Explan2
_PutStr Newline
_PutStr Explan3
_PutStr Newline
_PutStr Explan4
CharLoop:
mov bx, 0
_BIOSCh
cmp al, 'n' ; increase octave
je HandleLS
cmp al, 'm' ; decrease octave
je HandleRS
cmp ah, 1Ch ; was char an enter?
je Ext
CArrayLoop:
cmp al, [Char_Array+bx] ; does the keypress match a letter?
je FArrayH
inc bx ; if not move on
cmp bx, 11 ; end of array?
je CharLoop
jmp CArrayLoop
FArrayH:
cmp Octave, 1
jl HandleLower
je FArray1
cmp Octave, 2
je FArray2
cmp Octave, 3
je FArray3
jg HandleUpper
HandleLower:
mov Octave, 1 ; if n key is pressed too many times bound it
jmp FArray1
HandleUpper:
mov Octave, 3 ; if m key is pressed too many times bound it
jmp FArray3
FArray1:
mov Save, ds
mov ax, [Freq_Array+bx]
call SndSpeak
jmp RestoreLoop
FArray2:
mov Save, ds
mov ax, [Freq_Array2+bx]
call SndSpeak
jmp RestoreLoop
FArray3:
mov Save, ds
mov ax, [Freq_Array3+bx]
call SndSpeak
jmp RestoreLoop
HandleLS:
inc Octave
jmp CharLoop
HandleRS:
dec Octave
jmp CharLoop
RestoreLoop:
mov ds, Save
jmp CharLoop
;----------Close Program-----------
Ext:
mov ax, 4c00h
int 21h
;----------------------------------
Main ENDP
SndSpeak PROC
mov bx, ax
mov eax, divider
div bx
mov cx, ax
cli ;no interrupts
mov al, 10110110b ;get ready byte
out 043h, al
mov al, cl ;frequency divisor low byte
out 042h, al
mov al, ch ;frequncy divisor high byte
out 042h, al
; Switch speaker on
in al, 061h ;get port 61h contents
or al, 00000011b ;enable speaker
out 061h, al
; Wait CX clock ticks
sti ;must allow clock interrupt
mov cx, 12 ; change to number in other students code
mov cx, 6 ;About 1 second (1/18.2*t=num) t=time num=number of clock ticks
mov ax, 040h ;point DS to BIOS
mov es, ax
mov si, 06ch
push ds ;save the data segment
mov ds, ax
waitlp: mov ax, [si] ;get low word of tick counter
wait1: cmp ax, [si] ;wait for it to change
je wait1
loop waitlp ;count CX changes
pop ds ;restore the data segment
; Switch speaker off
in al, 61h ;get port contents
and al, 11111100b ;disable speaker
out 61h, al
ret
sndspeak ENDP
END Main
There is my code, the tones seem to play but changing the octave does nothing, and repeated key presses of the same note in the same octave sound differently

.