当前位置:网站首页>Design of music box based on assembly language
Design of music box based on assembly language
2022-07-05 11:58:00 【**inevitable**】
Music box design based on assembly language ( You can switch songs halfway )
The main function of this program is to play music , You can choose the song to play , You can switch music halfway , You can also quit playing music . The procedure is as follows :
; Menu display
DISPLAY MACRO B ; Define a macro instruction , That is, a piece of code that needs to be executed repeatedly , Or a set of instructions abbreviated to a macro
LEA DX,B
MOV AH,9 ; call 9 Interrupt number , Display the menu on the screen
INT 21H
ENDM
DATA SEGMENT
MENU DB 0DH,0AH,'1: <<liang zhi lao hu>>' ; song 1: Two tigers
DB 0DH,0AH,'2: <<xin nian hao>>' ; song 2: Happy New Year
DB 0DH,0AH,'3: <<fen shua jiang>>' ; song 3: whitewasher
DB 0DH,0AH,'q: EXIT' ; Quit playing music
DB 0AH,0AH,'$'
music1_fre DW 263,294,330,263 ; music 1 The frequency of
DW 263,294,330,263
DW 330,349,392
DW 330,349,392
DW 392,440,392,349,330,263
DW 392,440,392,349,330,263
DW 263,196,263
DW 263,196,263,0
music1_time DW 10 dup(20), 40 ; music 1 The beat of the music
DW 2 dup(20), 40
DW 4 dup(10), 20, 20
DW 4 dup(10), 20, 20
DW 2 dup(20), 40
DW 2 dup(20), 40
music2_fre dw 262,262,262,196
dw 330,330,330,262
dw 262,330,392,392
dw 349,330,294
dw 294,330,349,349
dw 330,294,330,262
dw 262,330,294,196
dw 247,294,262,0
music2_time dw 3 dup(12,12,25,25),12,12,50
dw 3 dup(12,12,25,25),12,12,50
music3_fre dw 392,330,392,330
dw 392,330,262
dw 294,349,330,294
dw 392
dw 392,330,392,330
dw 392,330,262
dw 294,349,330,294
dw 262
dw 294,294,349,349
dw 330,262,392
dw 294,349,330,294
dw 392
dw 392,330,392,330
dw 392,330,262
dw 294,349,330,294
dw 262
dw 0
music3_time dw 3 dup(10h,10h,10h,10h,10h,10h,20h,10h,10h,10h,10h,40h)
dw 10h,10h,10h,10h,10h,10h,20h,10h,10h,10h,10h,20h
DATA ENDS
STACK SEGMENT
STACK ENDS
CODE SEGMENT
ASSUME DS:DATA,CS:CODE
START:
MOV AX,DATA
MOV DS,AX
MOV AH,0
MOV AL,0
INPUT: ; The main program that controls music playback
DISPLAY MENU ; Show menu
MOV AH,1
INT 21H ; call 1 Interrupt number , Enter which music to play or quit playing
stop_music:
CMP AL,'q' ; If the input character is q, Then interrupt , Stop playing music
JZ end_music
music1:
CMP AL,'1'
JNZ music2 ; If the entered number is not 1, Jump to music 2 The subroutine of then judges
lea SI,music1_fre ; The music 1 The offset address of the frequency is assigned to SI
lea BP,music1_time ; The music 1 The offset address of the beat is assigned to BP
CALL play_music ; Call the play music subroutine
JMP INPUT ; The cycle continues to enter , Until you press ‘4’, That is, quit playing
music2:
CMP AL,'2'
JNZ music3 ; If the entered number is not 2, Jump to music 3 The subroutine of then judges
lea SI,music2_fre ; The music 2 The offset address of the frequency is assigned to SI
lea BP,music2_time ; The music 2 The offset address of the beat is assigned to BP
CALL play_music ; Call the play music subroutine
JMP INPUT ; The cycle continues to enter , Until you press ‘4’, That is, quit playing
music3:
CMP AL,'3'
JNZ INPUT ; If the entered number is not 3, Jump to continue typing
lea SI,music3_fre ; The music 2 The offset address of the frequency is assigned to SI
lea BP,music3_time ; The music 2 The offset address of the beat is assigned to BP
CALL play_music ; Call the play music subroutine
JMP INPUT ; The cycle continues to enter , Until you press ‘4’, That is, quit playing
end_music:
MOV AH,4CH
INT 21H
;*******************************************************************
sound proc near
PUSH AX
PUSH BX
PUSH CX
PUSH DX
PUSH DI
;8253 Chip settings
MOV AL,0B6H ;8253 initialization
OUT 43H,AL ;43H yes 8253 The port address of the chip control port
MOV DX,12H ; high 16 position
MOV AX,34dch ; low 16 position
DIV DI ; Calculate the frequency division value , Assign to ax.DI The frequency value of the sound stored in .
OUT 42H,AL ; Send low first 8 Bit to counter ,42h yes 8253 Chip channel 2 Port address of
MOV AL,AH
OUT 42H,AL ; Evacuation height 8 Bit counter
; Set up 8255 chip , Control the loudspeaker on / Turn off
IN AL,61H ; Read 8255 B Original value of port
MOV AH,AL ; Save the original value
OR AL,3 ; Make two positions lower 1, Turn on the switch
OUT 61H,AL ; Turn on the speaker , A voice
WAIT1:
MOV CX,28000
DELAY1:
nop
loop DELAY1
DEC BX
JNZ WAIT1
MOV AL,AH ; Restore the original value of the speaker port
OUT 61H,AL
POP DI
POP DX
POP CX
POP BX
POP AX
RET
sound ENDP
;*************************************************************
play_music PROC NEAR ; Play music subroutine
PUSH DS
SUB AX,AX
PUSH AX
play_start:
MOV AH,1
INT 16H ; Here is the key to switching music
JNZ INPUT
MOV DI,[SI] ; note
CMP DI,0 ; Judge whether the note is 0, by 0 End playing music subroutine
JE end_paly
MOV BX,[BP] ; Rhythm
CALL sound
ADD SI,2
ADD BP,2
JMP play_start ; Continue to execute the music playing subroutine , Until the end of a piece of music
end_paly:
RET
play_music endp
;*******************************************************************
CODE ENDS
END START
After the program is executed , Press the number key 1 Play music 1, Press the number key 2 Play music 2, Press the number key 3 Play music 3, Press down ‘q’ Key to exit music playing . In the process of playing music, you can switch music or exit , such as , Press the number key 2 Play music 2, Press the number key during playback 1 Will stop playing music 2 Turn to music 1. Switch song implementation mainly uses int 16h interrupt , Here you can refer to a blogger's explanation of the interruption :https://blog.csdn.net/qingkongyeyue/article/details/68490194?ops_request_misc=%7B%22request%5Fid%22%3A%22160579825619725222420556%22%2C%22scm%22%3A%2220140713.130102334.pc%5Fall.%22%7D&request_id=160579825619725222420556&biz_id=0&utm_medium=distribute.pc_search_result.none-task-blog-2~all~first_rank_v2~rank_v28-16-68490194.first_rank_ecpm_v3_pc_rank_v2&utm_term= assembly int+16 interrupt &spm=1018.2118.3001.4449
边栏推荐
- C operation XML file
- View all processes of multiple machines
- 【load dataset】
- Hiengine: comparable to the local cloud native memory database engine
- HiEngine:可媲美本地的云原生内存数据库引擎
- [singleshotmultiboxdetector (SSD, single step multi frame target detection)]
- Pytorch softmax regression
- 11.(地图数据篇)OSM数据如何下载使用
- Principle of persistence mechanism of redis
- 石油化工企业安全生产智能化管控系统平台建设思考和建议
猜你喜欢
查看rancher中debug端口信息,并做IDEA Remote Jvm Debug
《增长黑客》阅读笔记
一次生产环境redis内存占用居高不下问题排查
codeforces每日5题(均1700)-第五天
splunk配置163邮箱告警
Thoughts and suggestions on the construction of intelligent management and control system platform for safe production in petrochemical enterprises
Liunx prohibit Ping explain the different usage of traceroute
redis主从模式
pytorch-权重衰退(weight decay)和丢弃法(dropout)
pytorch-多层感知机MLP
随机推荐
abap查表程序
COMSOL -- establishment of 3D graphics
[deploy pytoch project through onnx using tensorrt]
【 YOLOv3中Loss部分计算】
跨平台(32bit和64bit)的 printf 格式符 %lld 输出64位的解决方式
Wireless WiFi learning 8-channel transmitting remote control module
【无标题】
Riddle 1
Linux安装部署LAMP(Apache+MySQL+PHP)
汉诺塔问题思路的证明
[yolov5.yaml parsing]
yolov5目标检测神经网络——损失函数计算原理
COMSOL -- 3D casual painting -- sweeping
Unity xlua monoproxy mono proxy class
Yolov5 target detection neural network -- calculation principle of loss function
ACID事务理论
HiEngine:可媲美本地的云原生内存数据库引擎
Project summary notes series wstax kt session2 code analysis
Linux Installation and deployment lamp (apache+mysql+php)
Use and install RkNN toolkit Lite2 on itop-3568 development board NPU