两首歌曲的汇编演示(发声代码)...

类别:编程语言 点击:0 评论:0 推荐:

第一次作发声代码:

        title music -- a music of 'Mary  had a little lamb'
        extrn soundf :far  ;link  music+soundf
        stack   segment para stack 'stack'
                db 64 dup('stack...')
        stack ends

        dseg    segment para'data'
        mus_freg dw 330,294,262,294,3 dup(330)
                 dw 3 dup(294),330,392,392
                 dw 330,294,262,294,4 dup(330)
                 dw 294,294,330,294,262,-1
        mus_time dw 6 dup(25),50
                 dw 2 dup(25,25,50)
                 dw 12 dup(25),100
        dseg ends

        cseg segment para 'code'
                assume cs:cseg,ss:stack,ds:dseg
        music proc far
                mov ax,dseg
                mov ds,ax
                lea si,mus_freg
                lea bp,ds:mus_time
        freq:
                mov di,[si]
                cmp di,-1
                je music
               ; je end_mus
                mov bx,ds:[bp]
                call soundf
                add si,2
                add bp,2
                jmp freq
        end_mus:
                mov ax,4c00h
                int 21h
        music endp
        cseg ends
                end music

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

       title music -- a music of 'Mary  had a little lamb'
        extrn soundf :far
        stack   segment para stack 'stack'
                db 64 dup('stack...')
        stack ends

        dseg    segment para'data'
        mus_freg dw 330,392,330,294,330,392,330,294,330
                 dw 330,392,330,294,262,294,330,392,294
                 dw 262,262,220,196,196,220,262,294,330,262
                 dw -1
        mus_time dw 3 dup(500),250,250,500,250,250,1000
                 dw 2 dup(500,500,250,250),1000
                 dw 3 dup(500,250,250),1000
        dseg ends

        cseg segment para 'code'
                assume cs:cseg,ss:stack,ds:dseg
        music proc far
                mov ax,dseg
                mov ds,ax
                lea si,mus_freg
                lea bp,ds:mus_time
        freq:
                mov di,[si]
                cmp di,-1
                je music
               ; je end_mus
                mov bx,ds:[bp]
                call soundf
                add si,2
                add bp,2
                jmp freq
        end_mus:
                mov ax,4c00h
                int 21h
        music endp
        cseg ends
                end music

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


        title  soundf -- the speaker beeper   
        public soundf
        cseg    segment para 'code'
                assume cs:cseg
        soundf  proc far
                push ax
                push bx
                push cx
                push dx
                push di
                mov al,0b6h
                out 43h,al
                mov dx,12h
                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,al
        waitl:
                mov cx,6630
                call waitf
                mov al,ah
                out 61h,al
                pop di
                pop dx
                pop cx
                pop bx
                pop ax
                ret
        soundf endp
        waitf proc near
                push ax
        waitf1:
                in al,61h
                and al,10h
                cmp al,ah
                je waitf1
                mov ah,al
                loop waitf1
                pop ax
                ret
        waitf endp
       cseg ends
      ;---------------------------------------------------
       end


下载代码:http://blogfile0.tom.com/file/0/9/3/f_85909_7938.rar

本文地址:http://com.8s8s.com/it/it24081.htm