code segment
assume cs:code
D1=131
D2=147
D3=165
D4=175
D5=196
D6=220
D7=247
Z1=262
Z2=294
Z3=330
Z4=349
Z5=392
Z6=440
Z7=494
G1=523
G2=587
G3=659
G4=714
G5=784
G6=880
G7=988
oldint8 dd ?
oldint9 dd ?
time dw 0
ascii DB 10H,11H,12H,13H,14H,15H,16H
DB 1EH,1FH,20H,21H,22H,23H,24H
DB 2CH,2DH,2EH,2FH,30H,31H,32H
music dw d1,d2,d3,d4,d5,d6,d7
dw z1,z2,z3,z4,z5,z6,z7
dw g1,g2,g3,g4,g5,g6,g7
newint8: dec cs:word ptr time
jz closev
new8_0: jmp cs:oldint8
closev: push ax
in al,61h
and al,0fdh
out 61h,al
pop ax
jmp new8_0
voice: mov cx,ax
mov dx,12h
mov ax,34dch
div cx
push ax
mov al,0b6h
out 43h,al
pop ax
out 42h,al
xchg al,ah
out 42h,al
in al,61h
or al,03h
out 61h,al
ret
newint9: in al,60h
push ax
in al,61h
or al,80h
out 61h,al
and al,7fh
out 61h,al
mov al,20h
out 20h,al
sti
pop ax
push ax
cmp al,80h
jb new90
mov cs:word ptr time,04h
jmp quit
new90: push cs
pop es
mov di,offset ASCII
mov cx,22d
cld
repnz scasb
jcxz quit
sub di,offset ascii
dec di
shl di,1
mov ax,es:[di+music]
mov cs:word ptr time,0h
call voice
quit: pop ax
cmp al,01h
jnz meun
lds dx,cs:oldint8
mov ax,2508h
int 21h
lds dx,cs:oldint9
mov ax,2509h
int 21h
mov ax,4c00h
int 21h
meun: sti
jmp meun
start:mov ax,cs
mov ds,ax
mov ax,3508h
int 21h
mov cs:Word ptr oldint8,bx
mov cs:word ptr oldint8+2,es
mov ax,3509h
int 21h
mov cs:Word ptr oldint9,bx
mov cs:word ptr oldint9+2,es
mov ax,2508h
mov dx,offset newint8
int 21h
mov ax,2509h
mov dx,offset newint9
int 21h
jmp meun
code ends
end start
编译运行一下 ,你会发现的计算机也能用来弹奏乐曲。:)