📄 gun.asm
字号:
dataseg segment
mess1 db 40 dup('*'),40 dup(' ')
db 'This is a program of making gun sound.',13,10
db 40 dup(' '),20 dup(' *'),'$'
mess2 db 'Please input the time(NULL-exit,?*10):$'
mess3 db 'What do you want to do?',17 dup(' '),'(a---again,q---quit)$'
mess4 db 'Do you really want to quit?(y/n)',5 dup(' '),'$'
mess5 db 20 dup(' *'),40 dup(' '),13,10,'$'
freq dw 90
col db 0
row db 0
time label byte
t_max db 2
t_act db ?
t_fld db 2 dup(?)
key label byte
k_max db 2
k_act db ?
k_fld db 2 dup (?)
dataseg ends
;-------------------------------------------------------
codeseg segment para 'code'
assume cs:codeseg,ds:dataseg
main proc far
mov ax,dataseg
mov ds,ax
mov ah,00 ;320*200彩色屏幕
mov al,04
int 10h
mov ah,0bh ;背景色
mov bh,00
mov bl,1
int 10h
call clear
lea dx,mess1
mov ah,09h
int 21h
start: call crlf
call crlf
lea dx,mess2
mov ah,09h
int 21h
lea dx,time
mov ah,0ah
int 21h
call crlf
cmp t_act,0 ;当不输入时直接退出
je exit1
lea si,t_fld
mov al,[si]
sub al,30h
mov bl,10
mul bl
mov cl,al
cmp cl,0
je start
loop1: mov di,freq
call gensound
call silent
dec cx
cmp cx,0
je next
jmp loop1
next:
call clear ;调用清屏子程序
call crlf
lea dx,mess5
mov ah,09h
int 21h
lea dx,mess3 ;询问接下来的动作
mov ah,09h
int 21h
lea dx,key
mov ah,0ah
int 21h
cmp k_fld,71h ;输入q则退出
je exit1
cmp k_fld,61h ;输入a则重新开始
je start
exit1: mov ax,4c00h
int 21h
main endp
;---------------------------------------------------------
gensound proc near
push ax
push bx
push cx
push dx
push di ;发声频率在DI寄存器中
;对43端口送控制字,对定时器2进行初始化
mov al,0b6h
out 43h,al
mov dx,12h
mov ax,348ch ;12348h/给定频率=产生给定频率声音的计数值
div di
;对42端口装入计数值(533h*896/频率),以建立将产生的频率
out 42h,al ;
mov al,ah
out 42h,al
in al,61h
mov ah,al
or al,3
out 61h,al
mov bx,1000
wait1: mov cx,0ffffh ;时间延迟
delay1: loop delay1
dec bx
jnz wait1
mov al,ah
out 61h,al
pop di
pop dx
pop cx
pop bx
pop ax
ret
gensound endp
;---------------------------------------------------------------------------
silent proc near
push ax
push bx
push cx
push dx
push di
xor cx,cx
mov bx,1000
delay2: mov cx,10000
loop2: loop loop2
dec bx
jnz delay2
pop di
pop dx
pop cx
pop bx
pop ax
ret
silent endp
;------------回车换行----------------------
crlf proc near
mov dl,0ah
mov ah,02h
int 21h
mov dl,0dh
mov ah,02h
int 21h
ret
crlf endp
;-------------------清屏子程序---------------
clear proc near
push ax
push bx
push cx
push dx
mov al,0 ;页号
mov bx,0 ;卷入行属性
mov cx,0 ;左上角行/列
mov dx,0 ;右上角行/列
line1:
mov ah,0ch ;写像素
int 10h
inc cx
cmp cx,320
jne line1
mov cx,0
inc dx
cmp dx,200
jne line1
mov ax,0600h
call l20curs
pop dx
pop cx
pop bx
pop ax
ret
clear endp
;-----------------置光标位置-----------------------------------
l20curs proc near
mov ah,02
sub bh,bh ;页号
mov dh,row ;行
mov dl,col ;列
int 10h
ret
l20curs endp
;----------------------------------------------------------------
codeseg ends
end main
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -