Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to make all kinds of sounds in assembly language

2025-03-26 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly introduces "how to make all kinds of sounds in assembly language". In daily operation, I believe many people have doubts about how to make all kinds of sounds in assembly language. The editor has consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful to answer the doubts about "how assembly language can make all kinds of sounds". Next, please follow the editor to study!

9. Ringing design

9.1 Design requirements:

It is required to know how to use the bell. Design a program to receive input characters from the keyboard, such as the number N, then ring N times, if the input is non-numeric, it will not ring.

9.2 Design ideas:

Judge the input between 0,9, give the N value to BP, set the bell delay times CX output N times of ringing.

9.3 Program list:

DATA SEGMENT pkey DB 0AHMagol 0DHMagne0DHMagne0DHrectem0DHMIRE0DHMIANRO input the NRU (ERR DB 0AH0AHre0DHM0DHM0DHM0DH0DH0DHMAL 0DHM0DHMIANG input the N again:','$'DATA ENDS CODE SEGMENT ASSUME CS:CODE,DS:DATASTATE: MOV AX,DATA MOV DS,AX MOV ES,AX LEA DX,pkey MOV AH,09H INT 21H When the DOS function is called, the output string is INPUT: MOV AH,01H INT 21H CMP AL,'9' JA eero CMP AL,'0' JB eero SUB AL,30H; if the input is 0x9, AL is the number of rings SUB AH,AH MOV BP,AX; BP is the number of rings N xiang: MOV CX,4 CX: ring delay time MOV AH,02H MOV DL,07H INT 21H; DOS function call, ring LP: LOOP LP; ring delay DEC BP JNZ xiang Ring N times JMP STATE eero: LEA DX,ERR MOV AH,9 INT 21H; output error string JMP INPUTCODE ENDSEND STATE

9.4 running results and analysis of the program:

Set the number of CX to the number of delay and the number of BP to the number of rings. Calling the ring feature to ring through delay will initially confuse the number of delays with the number of rings and cause errors.

Fig. 9 result of bell design

10. A sound program that requires external speakers

10.1 machine gun sound

PROGRAM SEGMENT MAIN PROC FAR ASSUME CS:PROGRAM ORG 100HSTRAT:MOV CX,20DNEW_SHOT:PUSH CX CALL SHOOT MOV CX,4000H SILENT:LOOP SILENT POP CX LOOP NEW_SHOT INT 20H MAIN ENDP SHOOT PROC NEAR MOV DX,140H MOV BX,20H IN AL,61H AND AL,11111100B SOUND:XOR AL,2 OUT 61H,AL ADD DX 9248H MOV CL,3 ROR DX,CL MOV CX,DX AND CX,1FFH OR CX,10 WAIT: LOOP WAIT DEC BX JNZ SOUND AND AL,11111100B OUT 61H,AL RET SHOOT ENDP PROGRAM ENDS END STRAT

10.2 Music playback

Define data segments data segment infor1 db 0Dh, 0AH, "welocom you to come here listeng! $" mus_freg dw 330 dup 294 262 dup 294 dup; frequency table dw 3 dup (294), 330392392 dw 330 dup 294 dup 294 dw 294 dup 294 330 dup (25), 50 The tempo table dw 2 dup (25pc25 dup) dw 12 dup (25), the 100data ends; stack segment defines stack segment stack db 200dup (?) stack ends;- string output macro-SHOWBM MACRO b LEA DX,b MOV AH,9 INT 21H ENDM -Music address macro-ADDRESS MACRO A Magi B LEA SI,A LEA BP,DS:BENDM; code snippet defines code segment assume ds:data, ss:stack, cs:codestart: mov ax, data mov ds, ax mov ax, stack mov ss, ax mov sp, 200address mus_freg, mus_time call musicexit: mov ah, 4cH int 21h -vocal-gensound proc near push ax push bx push cx push dx push di mov al, 0b6H out 43h, al mov dx, 12 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, alwait1: mov cx 3314 call waitfdelay1: dec bx jnz wait1 mov al, ah out 61h, al pop di pop dx pop cx pop bx pop ax ret gensound endp -- waitf proc near push axwaitf1: in al,61h and al,10h cmp al,ah je waitf1 mov ah,al loop waitf1 pop ax retwaitf endp -vocal call function-music proc near xor ax, axfreg: mov di, [si] cmp di, 0FFFFH je end_mus mov bx, ds: [bp] call gensound add si, 2 add bp, 2 jmp fregend_mus: retmusic endpcode ends end start so far The study of "how to make all kinds of sounds in assembly language" is over. I hope to be able to solve everyone's doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report