汇编钢琴

;电子琴

data segment
    note dw 262,294,330,349,392,440,494,523,578,659,698
data ends

code segment
    assume ds:data , cs:code
main proc far
    mov ax,data
    mov ds,ax
    
begin:
    call input
    call sound
    cmp si,80h    
    jnz begin
    
    mov ah,4ch
    int 21h
main endp

input proc near
    push ax
    push bx    
    mov ah,01
    int 21h 
    sub al,30h
    mov bl,2
    mul bl
    sub al,2
    mov si,al
    mov di,note[si]
    pop bx
    pop ax
    ret
input endp


sound proc near
    mov al,0b6h
    out 43,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
wait1:
    mov cx,15
delay:
    loop delay
    dec bx
    jnz wait1
    mov al,ah
    out 61h,al
    ret
sound endp

code ends
    end main

 

posted @ 2016-06-06 23:06  式微胡不归  阅读(216)  评论(0编辑  收藏  举报