📄 sound0.asm
字号:
DATAS SEGMENT para 'data'
freq dw 300
chnrate label byte
max db 4
act db ?
acchnrate db 4 dup (?)
msg1 db 'press I to input the change rate;press Q to quit:',13,10,'$'
msg2 db 'please input the rate of change:',13,10,'$'
errormsg db 'Wrong instruction ,please input again!',13,10,'$'
DATAS ENDS
STACKS SEGMENT stack para 'stack'
db 64 dup('stack...')
STACKS ENDS
CODES SEGMENT
main proc far
ASSUME CS:CODES,DS:DATAS,SS:STACKS
MOV AX,DATAS
MOV DS,AX
repeat:
mov ah,09h
lea dx,msg1
int 21h
mov ah,08
int 21h
cmp al,'q'
jz exit
cmp al,'Q'
jz exit
cmp al, 'i'
jz product
cmp al,'I'
jz product
lea dx,errormsg
mov ah,09h
int 21h
jmp repeat
product:
mov ah,09h
lea dx,msg2
int 21h
mov ah,10
lea dx,chnrate
int 21h
mov ah,2
mov dl,13
int 21h
mov dl,10
int 21h
;得到输入的变化率
sub ax,ax
sub cx,cx
sub bx,bx
mov cl,act
mov dl,10
lea si,acchnrate
convert:
mov al,[si]
sub al,30h
push cx
dec cx
and cx,cx
jz add1
multiply:
mul dl
loop multiply
add1:
pop cx
add bx,ax
inc si
loop convert
mov ax,bx
lea si,freq
mov bx,20
callproc:
call changefre
jmp repeat
exit:
mov ax,4c00h
int 21h
main endp
changefre proc near
mov di,[si]
add ax,di
next :
call sound
inc di
cmp di,ax
jne next
ret
changefre endp
sound proc near
push di
push ax
push dx
push bx
mov al,0b6h
out 43h,al ;初始化43端口
mov dx,12h
mov ax,348ch ;系统固有频率
div di
out 42h,al
mov al,ah
out 42h,al
in al,61h
mov ah,al
or al,3 ;打开蜂鸣器
out 61h,al
lenth: ;延时10ms
mov cx,633
waitf:
in al,61h ;测试 第 4位是否 为 1 得到 15.6 ns的 延时
and al,10h
jz waitf
loop waitf
dec bx
jne lenth
mov al,ah
and al,0fch
out 61h,al
pop bx
pop dx
pop ax
pop di
ret
sound endp
CODES ENDS
END main
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -