1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
| assume cs:codeseg, ds:dataseg, ss:stackseg dataseg segment mus_freq dw 262,262,262,196,330,330,330,262 dw 262,330,392,392,349,330,294 dw 294,330,349,349,330,294,330,262 dw 262,330,294,196,247,294,262,-1 mus_time dw 3 dup(12,12,25,25),12,12,50 dw 3 dup(12,12,25,25),12,12,50 dataseg ends stackseg segment db 100h dup (0) stackseg ends codeseg segment start: mov ax, stackseg mov ss, ax mov sp, 100h mov ax, dataseg mov ds, ax lea si, mus_freq lea di, mus_time play: mov dx, [si] cmp dx, -1 je end_play call sound add si, 2 add di, 2 jmp play end_play: mov ax, 4c00h int 21h sound: push ax push dx push cx mov al,0b6h ; 8253芯片设置 out 43h,al mov dx,12h mov ax,34dch div word ptr [si] out 42h, al mov al, ah out 42h, a ;设置8255芯片, 控制扬声器的开/关 in al,61h mov ah,al or al,3 ;延时 mov dx, [di] wait1: mov cx, 28000 delay: nop loop delay dec dx jnz wait ;恢复扬声器端口原值 mov al, ah out 61h, al pop cx pop dx pop ax ret codeseg ends end start
|