当前位置:网站首页>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
边栏推荐
- 一次生产环境redis内存占用居高不下问题排查
- C operation XML file
- mmclassification 训练自定义数据
- How does redis implement multiple zones?
- 手机 CPU 架构类型了解
- Yolov 5 Target Detection Neural Network - Loss Function Calculation Principle
- [deploy pytoch project through onnx using tensorrt]
- 【云原生 | Kubernetes篇】Ingress案例实战(十三)
- 简单解决redis cluster中从节点读取不了数据(error) MOVED
- Unity xlua monoproxy mono proxy class
猜你喜欢

【TFLite, ONNX, CoreML, TensorRT Export】

How can China Africa diamond accessory stones be inlaid to be safe and beautiful?

【TFLite, ONNX, CoreML, TensorRT Export】

Pytorch MLP

【pytorch 修改预训练模型:实测加载预训练模型与模型随机初始化差别不大】

abap查表程序
![[untitled]](/img/56/6a9a4bcab6503872942fff7a365def.jpg)
[untitled]

查看rancher中debug端口信息,并做IDEA Remote Jvm Debug

Multi table operation - sub query

redis主从模式
随机推荐
byte2String、string2Byte
Multi table operation - Auto Association query
Prevent browser backward operation
ACID事务理论
[singleshotmultiboxdetector (SSD, single step multi frame target detection)]
[deploy pytoch project through onnx using tensorrt]
Programmers are involved and maintain industry competitiveness
无线WIFI学习型8路发射遥控模块
简单解决redis cluster中从节点读取不了数据(error) MOVED
[cloud native | kubernetes] actual battle of ingress case (13)
Principle of persistence mechanism of redis
Troubleshooting of high memory usage of redis in a production environment
pytorch-权重衰退(weight decay)和丢弃法(dropout)
12. (map data) cesium city building map
Linux Installation and deployment lamp (apache+mysql+php)
Empêcher le navigateur de reculer
C operation XML file
COMSOL -- three-dimensional graphics random drawing -- rotation
Solve readobjectstart: expect {or N, but found n, error found in 1 byte of
Pytorch linear regression