词条 | 计算机发声汇编程序 |
释义 | data segment freq dw 196,220 dw 262,262,262,262,262,220,196 dw 262,262,262,262,294,262,220,262 dw 294,294,294,294,294,262,220 dw 294,294,294,294,330,294,330,392 dw 440,440,392,440,392,330 dw 294,294,330,294,262,220,196,220 dw 262,262,262,262,262,220 dw 262,196,220 dw 440,440,392,440,524,440 dw 392,330,294,262,220,196,220 dw 262,262,262,262,294,262 dw 262,330,392 dw 440,440,440,440,524,440 dw 392,392,392,440,392,330,294 dw 262,262,262,262,294 dw 330,330,294 dw 262,262,262,262,524,440 dw 392,392,392,440,392,330,392 dw 440,524,524,440,392 dw 392,330,392 dw 440,440,440,440,524,440 dw 392,392,392,440,392,330,294 dw 262,262,262,262,392 dw 330,330,294 dw 262,262,262,262,294,330 dw 392,392,330,392,330,392 dw 440 dw 19,19,196,660,294,294,262 dw 262,-1 time dw 400,400 dw 400,200,400,400,800,400,400 dw 400,200,400,200,200,800,400,400 dw 400,200,400,400,800,400,400 dw 400,200,400,200,200,800,400,400 dw 400,800,400,800,400,400 dw 400,200,200,400,400,800,400,400 dw 400,200,400,400,800,800 dw 1600,800,800 dw 400,800,400,800,400,400 dw 400,400,400,400,800,400,400 dw 400,800,400,800,400,200 dw 2400,400,400 dw 400,800,400,800,400,400 dw 400,800,200,200,800,400,400 dw 400,800,400,800,800 dw 2400,400,400 dw 400,800,400,800,400,400 dw 400,800,200,200,800,400,400 dw 800,400,800,400,200 dw 2400,400,400 dw 400,800,400,800,400,400 dw 400,800,200,200,800,400,400 dw 400,800,400,800,800 dw 2400,400,400 dw 400,800,400,800,400,400 dw 400,800,400,800,400,400 dw 3200 dw 800,400,400,400,400,400,400 dw 4000 data ends code segment assume cs:code,ds:data start: mov ax,data mov ds,ax ;初始化数据段寄存器 lea si,freq ;把freq在数据段的偏移存入si lea di,time ;把time在数据段的偏移存入di l1: mov cx,[si] cmp cx,-1 je exit ;如果初始化失败,就像看到的一样,cx的值是负一那么就退出了 mov bx,[di] call gensound add si,2 add di,2 jmp l1 ;每次从time中取一个字,然后调用gensound exit: mov ax,4c00h int 21h ;bx(放延时计数值)、cx(放频率计数值)为入口参数。 gensound proc near push dx MOV AL,0B6H ;位组合格式:通道2,两字节计数,模式3,二进制编码, 得到控制字; OUT 43H,AL ;将控制字数送43H端口(方式寄存器) mov dx,12h mov ax,3280h div cx ;计算123280h/cx--->dx,ax out 42h,al ;把商的低字节(频率计数值)写入42h端口(定时器通道2) mov al,ah out 42h,al ;再把商的高字节写入到42h端口 in al,61h mov ah,al or al,3 ;控制音长的时间可以简单地通过反复执行循环指令来得到 out 61h,al ;接通扬声器 push ax l2: mov dx,8h ;送基准延时值 mov ax,0f05h s1: sub ax,1 sbb dx,0 ;DX:AX减去了1(sbb指令是带借位减法指令:(dx)=(dx)-0-CF) jnz s1 ;kill time dec bx ;这是第一次使用bx,也就是传入参数。 jnz l2 ;kill time pop ax mov al,ah ;果然是保护AH的值的 out 61h,al ;恢复扬声器原来的设置 pop dx ret gensound endp code ends end start |
随便看 |
百科全书收录4421916条中文百科知识,基本涵盖了大多数领域的百科知识,是一部内容开放、自由的电子版百科全书。