使用PC扬声器生成音乐音

问题描述 投票:0回答:1

我有这样一段代码。

IDEAL
MODEL small
STACK 100h
DATASEG
CODESEG

PROC PLAY
        mov al, 182         
        out 43h, al          

        out 42h, al        
        mov al, ah          
        out 42h, al 
        in al, 61h         
        or al, 00000011b   
        out 61h, al        
        mov bx, 15         
pauseSound:
        mov cx, 65535
pause2:
        dec cx
        jne pause2
        dec bx
        jne pauseSound

        in  al, 61h         

        and al, 11111100b   
        out 61h, al         

        RET
    END PLAY

start:      


       mov ax, 2712
       call PLAY


       MOV AX, 3834
       call PLAY
exit :

    mov ax, 4C00h
    int 21h
    END start

这个程序需要先播放一个声音几秒钟 然后再播放另一个声音几秒钟 但是我只听到第一个声音,没有听到第二个声音,问题出在哪里?谢谢您

assembly x86 tasm dosbox
1个回答
1
投票

指令 END 告诉 TASM 打破程序集,而且它还指定了程序的入口点。在TASM源代码中应该只有一个这样的指令,通常在最后一行。由于你的打字错误,TASM只装配了子程序 PLAY 而且它不够聪明,没有警告你,。PROC PLAY 没有正确终止。

改变 END PLAYENDP PLAY 你的程序就可以工作了。

更新我把你的程序和

> tasm Meow.asm
Turbo Assembler  Version 4.0  Copyright (c) 1988, 1993 Borland International
Assembling file:   Meow.asm
Error messages:    None
Warning messages:  None
Passes:            1

然后链接并在Windows 10 64bit的DOSBox中运行。

> ver
> DOSBox version 0.74-2. Reported DOS version 5.00.
> tlink Meow.obj
Turbo Link  Version 3.01 Copyright (c) 1987,1990 Borland International
> Meow.exe
>

它播放了两个高音和低音的音调,每个音调大约0. 8秒,然后退出,完全符合预期。

如果它在你的系统上只播放了很短的时间,请尝试增加定时常数。mov bx, 15. 你也可以在 pause2但一般来说,测量时间的方法是 jne pause2 在较新的电脑上是非常不可靠的,尤其是在仿真器上。

© www.soinside.com 2019 - 2024. All rights reserved.