;this program simulates a musical keyboard with keys 1-8. key 9 exits .model small .stack 100h .data octave dw 0,0,2280,2031,1810,1708,1522,1356,1208,1140 pause dw ? pause1 dw ? key db ? .code init: mov ax,@data ;initialize data sector mov ds,ax mov ax,3 ;initialize video mode: text int 10h mov al,10110110b ;initialize speakers out 43h,al top: in al,64h ;check port 64 AND al,1 ;if no keys are pressed cmp al,1 ; do nothing jne top in al,60h ;read in key pressed cmp al,10 ;perform action necessary if certain key is found je fin ;exit condition - key '9' cmp al,9 jbe inRange jmp top ;no conditions are matched inRange: AND ah,0 mov si,ax ;give si the index of the note mov key,al call soundOn note: in al,60h ;will continue playing the sound until a new key is pressed cmp al,key ; not pressing the key is considering the same as pressing je note ; a new key call soundOff jmp top ;check for a new key press fin: mov ah,4ch ;return control to OS int 21h ;************************* soundOn: ;this method sets a note and plays it shl si,1 ;fix si length mov ax,octave+si ;set the appropriate note to be played out 42h,al ; mov al,ah ; out 42h,al ; in al,61h ;outputs the note OR al,00000011b ; out 61h,al ret ;************************* soundOff: ;this method stops the speaker in al,61h AND al,11111100b ;set 61h port to stop sound out 61h,al ret end