📄 4.asm
字号:
title musex--TONE OF DO -RE-MI
STACK SEGMENT PARA STACK 'STACK'
DB 200 DUP('STACK.......')
STACK ENDS
dseg segment para 'data'
mus_freq DW 220,262,330,330,330,294,330,330,330,294,330,294,262,262,100,330,294
DW 330,294,262,294,262,247,262,247,220,220,100,220,262
DW 330,330,330,294,330,330,330,294,330,294,262,262,100,330,294
DW 330,294,262,294,330,220,220,100,-1
mus_time DW 12 DUP(25),50,4 DUP(25)
DW 25,50,25,25,50,25,25,25,25,50,25,25,25,25
DW 12 DUP(25),50,4 DUP(25)
DW 25,50,25,25,50,50,100,25,25
dseg ends
cseg segment para 'code'
assume cs:cseg,ss:stack,ds:dseg
tone proc far
push ds ;put return addr.
sub ax,ax ; on stack
push ax
mov ax,dseg ;initialize DS
lea si,mus_freq ;freq table offset in SI
next:lea bp,mus_time ;time table offset in BP
freq:mov di,[si] ;read next frequency
cmp di,-1 ;end of tone?
je end_f ;yes,one time is end
mov bx,ds:[bp] ;no,fetch the duration
mov al,0b6h ;put magic number
out 43h,al ; into timer2
mov dx,12h
mov ax,533h*896
div di ;(dx,ax)/(DI)
out 42h,al ;LSB into timer2
mov al,ah
out 42h,al ;MSB into timer2
in al,61h
mov ah,al
or al,3 ;turn speake on
out 61h,al
long:mov cx,2801 ;length of tone
delay:loop delay
dec bx
jnz long
mov al,ah ;recover the port
out 61h,al
add si,2 ;inc the freq pointer
cont: add bp,2 ;update mus_t pointer
jmp freq ;go process next note
end_f:
mov al,48h ;reset port
out 61h,al
ret
tone endp
cseg ends
;
end tone
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -