⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 a_song.asm

📁 a song under dos use masm6.0 to get exe to go music can change any time
💻 ASM
字号:
;#Make_Exe#
.model small
;=============================
;===通用发声程序,PIT控制======
;=============================
.data 
msg db 'PIT control the sound programmer.',13,10,'any key to go on...',13,10,'$' 
mus_freq dw 262,262,262,196,330,330,330,262,262,330,392,392 
dw 349,330,294,294,330,349,349,330,294,262,330 
dw 262,330,294,193,247,294,262 
dw -3 
mus_time dw 12 dup(50) 
dw 2 dup(50),100,8 dup(50) 
dw 6 dup(50),100
 
.stack

.code
Start:
;=============================
;===主入口====================
;=============================
main proc far
 push ds
 mov ax,0
 push ax
 ;
 mov ax,@data
 mov ds,ax
 ;===programmer infomation
 lea dx,msg
 mov ah,09h
 int 21h
 ;
 mov ah,01h
 int 21h
 ;===init frequency table
 lea si,mus_freq
 ;===init time table
 lea bp,ds:mus_time
freqGO:
 ;===get next frequency
 mov di,[si]
 cmp di,-3
 je end_musGO
 ;===get next delay-time
 mov cx,ds:[bp]
 ;===call sound modules to sound as frequency and delay time
 call WM_SoundModule;DI,CX
 ;===increase to fetch next frequency and time
 add si,2
 add bp,2
 jmp freqGO
end_musGO:
 Ret
main Endp
;=============================
;===发声程序子模块宏===========
;===参数:DI,CX
;===DI:频率,默认为896HZ
;===CX:产生0.010s的倍延迟,默认为100,可以产生1s的延迟.
;=============================
WM_SoundModule proc near;DI_,CX_
 ;===save registers
 push ax
 push bx
 push cx
 push dx
 push si
 ;===save param for using
 push cx
 ;===select divisor
 mov al,10110110B
 out 43h,al
 ;===get frequency by data of DI
 mov dx,12h
 mov ax,348ch
 div di;save frequency into ax
 ;===init PIT by frequency
 out 42h,al
 mov al,ah
 out 42h,al
 ;===now init sound port
 in al,61h
 mov ah,al;save into ah to restore port
 ;===turn on speaker
 or al,00000011B
 out 61h,al
 ;===delay kernel,10s,loop 20 
 pop cx
LoopTimesGO:
 call WM_DelayModule
 loop LoopTimesGO
 ;===turn off speaker
 mov al,ah
 out 61h,al
 ;===recover register datas
 pop si
 pop dx
 pop cx
 pop bx
 pop ax
Ret
WM_SoundModule endp
;=============================
;===延迟0.01s的模块===========
;=============================
WM_DelayModule proc near
 ;===save registers
 push ax
 push cx
 ;===init outer delay counter
 mov cx,663;CX_
 ;===the first 15.08us delay
DelayDelayGO:
 in al,61h
 ;===check PB4,if it has changed
 and al,00010000B
 cmp al,ah
 je DelayDelayGO
 ;===save PB4 status
 mov ah,al
 loop DelayDelayGO
 ;===recover registers
 pop cx
 pop ax
Ret
WM_DelayModule endp
     End Start


⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -