Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!


Vista with 16-bits masm : unable to play tune smoothly

[color=Purple]Hi all,

Hereby i would like to asking for consult regarding the problem that i encountered when attempt to output a music tune with masm16 bits programing..

below is my code

title music sound
;title sound-"pak belalang"- lagu P.Ramli
.model small


mov al, 0b6h ;control byte: conter 2, lsb, msb, binary
out 43h, al ;send the control byte to ctrl reg.


;load counter 2 value for 8C2
mov ax, 0239h ; for 8C2 note
out 42h, al ; lower byte
mov al, ah
out 42h, al ; higher byte
;turn the speaker on
call spk8

spk8 proc ;
;turn the speaker on
in al, 61h ; get the current setting of port b
mov ah, al
or al, 00000011b
out 61h, al ; turn the speaker on
call delay
call delay
call delay
call delay
call delay
;call delay
;call delay
;call delay
mov al, ah
out 61h, al ; turn off the speaker
call delay_off

spk8 endp

delay proc near
mov cx, 19157 ;16578*15.08 microseconds = 250 ms
push ax

in al,61h
and al, 10h
cmp al, ah
je wait1
mov ah, al
loop wait1

pop ax
delay endp

delay_off proc near
mov cx, 15326 ; 1326*15.08 micro seconds = 20ms
push ax
tunggu: in al, 61h
and al,10h ; check pb4
cmp al,ah ;
mov ah,al ; save the new pb4 status
loop tunggu ; continue until cx becomes 0
pop ax
delay_off endp


[color=Purple]At the end, i am able to assemble the code.. yet the sound is weird when run in Vista . 'Tok tok tok' sound is heard. But this code run smoothly with window XP.

Kindly advise pls where should i concern on my code in order to make it output the correct pitch.
Thanks & regards


  • I'm surprised it works under XP.
    Direct hardware access, like you're program is doing, is something that windows is trying to stop. Each time your program wants to talk to hardware, it has to "ask" the O/S if it's ok. If the O/S is doing something else, say, checking your hard drive for illegal software, or phoning home, or sending spam, it can delay your program from having access to the hardware.

    Vista is doing more background tasks than XP apparently.

    You could:
    a) turn off services that vista is running so that your program runs smoother.
    b) try calling the "delay" routine less often, or with a smaller delay
    c) change your delay routine to use a time based service instead of more direct hardware access.
    d) try your program inside DOSBox, which can help with older 16bit programs that do direct hardware accesses.

Sign In or Register to comment.