8086組合語言21鍵電子琴

2021-09-30 00:09:06 字數 4504 閱讀 4838

建議使用dosbox進行qwq

(編寫環境:masm5.0,dosbox0.74)

說明qwertyu對應高音區的do lai mi fa so la xi

asdfghj對應中音區

zxcvbnm對應低音區

可以在table中修改對應區域的頻率,或者在此基礎上加上半音,搞個十二平均律的qwq

org 100h

assume cs:seg2,ds:seg1

seg1 segment

pstart db 'program start.',0dh,0ah,'$'

pend db 'program will end when input' ,27h,'esc',27h,'.',0dh,0ah,'$'

sec db ?

table dw 130

dw 146

dw 164

dw 174

dw 196

dw 220

dw 246

dw 261

dw 293

dw 329

dw 349

dw 392

dw 440

dw 493

dw 523

dw 587

dw 659

dw 698

dw 784

dw 880

dw 987

seg1 ends

stack segment para stack 'stack'

sta db 48 dup(?)

top equ length sta

stack ends

seg2 segment

assume cs:seg2,ds:seg1,ss:stack,es:seg1

start: mov ax,seg1

mov ds,ax

mov dx,offset pstart

mov ah,09h

int 21h

mov dx,offset pend

mov ah,09h

int 21h

mov ax,stack

mov ss,ax

mov ax,top

mov sp,ax

mov al,90h

out 63h,al

wait1: mov ah,01h

int 21h

cmp al,1bh

je cse

cmp al, 'a'

je ka

cmp al, 's'

je ks

cmp al, 'd'

je kd

cmp al, 'f'

je kf

cmp al, 'g'

je kg

cmp al, 'h'

je kh

cmp al, 'j'

je kj

jmp wait2

kj: jmp keyj

ka: jmp keya

ks: jmp keys

kd: jmp keyd

kf: jmp keyf

kg: jmp keyg

kh: jmp keyh

cse: jmp keyesc

wait2: cmp al, 'q'

je kq

cmp al, 'w'

je kw

cmp al, 'e'

je ke

cmp al, 'r'

je kr

cmp al, 't'

je kt

cmp al, 'y'

je ky

cmp al, 'u'

je ku

jmp wait3

ku: jmp keyu

kt: jmp keyt

kr: jmp keyr

ke: jmp keye

kq: jmp keyq

kw: jmp keyw

ky: jmp keyy

wait3: cmp al, 'z'

je kz

cmp al, 'x'

je kx

cmp al, 'c'

je kc

cmp al, 'v'

je kv

cmp al, 'b'

je kb

cmp al, 'n'

je kn

cmp al, 'm'

je km

cmp al, 'p'

je kp

jmp find

kp: jmp keyp

km: jmp keym

kn: jmp keyn

kb: jmp keyb

kc: jmp keyc

kx: jmp keyx

kz: jmp keyz

kv: jmp keyv

keyp: in al,61h

and al,0fch

out 61h,al

jmp wait1

find: mov ah,0bh

int 21h

and al,1111111b

call delay

jnz find

in al,61h

and al,0fch

out 61h,al

jmp wait1

keyz: mov bx,table

jmp soundf

keyx: mov bx,table+2

jmp soundf

keyc: mov bx,table+4

jmp soundf

keyv: mov bx,table+6

jmp soundf

keyb: mov bx,table+8

jmp soundf

keyn: mov bx,table+10

jmp soundf

keym: mov bx,table+12

jmp soundf

keya: mov bx,table+14

jmp soundf

keys: mov bx,table+16

jmp soundf

keyd: mov bx,table+18

jmp soundf

keyf: mov bx,table+20

jmp soundf

keyg: mov bx,table+22

jmp soundf

keyh: mov bx,table+24

jmp soundf

keyj: mov bx,table+26

jmp soundf

keyq: mov bx,table+28

jmp soundf

keyw: mov bx,table+30

jmp soundf

keye: mov bx,table+32

jmp soundf

keyr: mov bx,table+34

jmp soundf

keyt: mov bx,table+36

jmp soundf

keyy: mov bx,table+38

jmp soundf

keyu: mov bx,table+40

jmp soundf

soundf: mov dx,12h

mov ax,348ch

div bx

call sound

call delay

jmp find

keyesc: mov ah,4ch

int 21h

sound proc near

push ax

mov al,10110110b

out 43h,al

pop ax

out 42h,al

mov al,ah

out 42h,al

in al,61h

or al,03h

out 61h,al

retsound endp

delay proc near

push cx

push ax

mov ax,0fffh

x11: mov cx,100

x12: loop x12

dec ax

jnz x11

pop ax

pop cx

retdelay endp

seg2 ends

end start

8086組合語言

cmc 進製位求反指令 stc 進製位置為1指令 cld 方向標誌置1指令 std 方向標誌位置1指令 cli 中斷標誌置0指令 sti 中斷標誌置1指令 nop 無操作 hlt 停機 wait 等待 esc 換碼 lock 封鎖 附上 藍色理想 的彙編學習心得位址 從今天開始溫習彙編了 1 基本概...

8086組合語言知識大綱

乙個儲存單元儲存乙個位元組 乙個cpu有n根位址線,則可以說這個cpu的位址匯流排的寬度為n。這樣的cpu最多可以尋找2的n次方個記憶體單元。位址匯流排的寬度決定了cpu的定址能力。資料匯流排的寬度決定了cpu和外界的資料傳送速度。8根資料匯流排一次可以傳送乙個8位二進位制資料 1個位元組 8086...

8086組合語言 LEA指令

格式 lea 暫存器,間接運算元 注意第二運算元只能是間接運算元 data array byte xuyan code mov eax,offset array lea ebx,eax 1 mov ecx,0 mov al,ebx 最後ecx中的值是十進位制117,因為 u 的ascii碼是117d...