?? a_song.asm
字號:
;#Make_Exe#
.model small
;=============================
;===通用發(fā)聲程序,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
;=============================
;===發(fā)聲程序子模塊宏===========
;===參數(shù):DI,CX
;===DI:頻率,默認(rèn)為896HZ
;===CX:產(chǎn)生0.010s的倍延遲,默認(rèn)為100,可以產(chǎn)生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
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -