当前位置:网站首页>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
边栏推荐
- [deploy pytoch project through onnx using tensorrt]
- 【 YOLOv3中Loss部分计算】
- iTOP-3568开发板NPU使用安装RKNN Toolkit Lite2
- Multi table operation - sub query
- Redirection of redis cluster
- How can China Africa diamond accessory stones be inlaid to be safe and beautiful?
- [singleshotmultiboxdetector (SSD, single step multi frame target detection)]
- 如何让你的产品越贵越好卖
- 中非 钻石副石怎么镶嵌,才能既安全又好看?
- 【load dataset】
猜你喜欢
[calculation of loss in yolov3]
【TFLite, ONNX, CoreML, TensorRT Export】
Codeworks 5 questions per day (1700 average) - day 5
简单解决redis cluster中从节点读取不了数据(error) MOVED
1个插件搞定网页中的广告
mmclassification 训练自定义数据
redis主从模式
【 YOLOv3中Loss部分计算】
yolov5目標檢測神經網絡——損失函數計算原理
[singleshotmultiboxdetector (SSD, single step multi frame target detection)]
随机推荐
Hash tag usage in redis cluster
ABAP table lookup program
Codeforces Round #804 (Div. 2)
C operation XML file
COMSOL -- establishment of 3D graphics
Redis集群的重定向
POJ 3176 cow bowling (DP | memory search)
[crawler] Charles unknown error
JS for loop number exception
HiEngine:可媲美本地的云原生内存数据库引擎
Troubleshooting of high memory usage of redis in a production environment
【ijkplayer】when i compile file “compile-ffmpeg.sh“ ,it show error “No such file or directory“.
【pytorch 修改预训练模型:实测加载预训练模型与模型随机初始化差别不大】
Mongodb replica set
Pytorch weight decay and dropout
你做自动化测试为什么总是失败?
redis主从模式
【load dataset】
View all processes of multiple machines
多表操作-自关联查询