求大神,汇编程序执行太慢
stack segmentdw 512 dup(?)
stack ends
data segment
music_freq dw 262,294,330,350,393,441
dw 495,525,589,661,700,786
dw 882,990,1112,1248
music_time dw 800
messg1 db 'Thank you for using it','$'
messg2 db 0ah,0dh,'it is a music program','$'
messg3 db 0ah,0dh,'please choose mode(Q:exit other key:continue)','$'
messg4 db 0ah,0dh,'input error!$'
messg5 db 0ah,0dh,'you can play the music now(key:0-F,Q:exit the program)!','$'
messg6 db 0ah,0dh,'$'
messg7 db 0ah,0dh,'thank you for using it,any key to exit!','$'
data ends
code segment
assume cs:code,ds:data,ss:stack
main proc far
start:
mov ax,data
mov ds,ax
mov ax,stack
mov ss,ax
lea dx,messg1
mov ah,09h
int 21h
lea dx,messg2
mov ah,09h
int 21h
lea dx,messg3
mov ah,09h
int 21h
input: mov ah,01h
int 21h
cmp al,'Q'
jz exit
lea dx,messg5
mov ah,09h
int 21h
lea dx,messg6
mov ah,09h
int 21h
l1: mov ah,01h
int 21h
cmp al,'Q'
jz exit1
cmp al,30h
jb error
cmp al,46h
ja error
cmp al,40
jb num
jmp abcdef
num: sub al,30h
mov dl,2
mul dl
lea bx,music_freq
mov si,ax
mov cx,[bx+si]
mov dx,800
call gensound
jmp l1
abcdef: sub al,31h
mov dl,2
mul dl
lea bx,music_freq
mov si,ax
mov cx,[bx+si]
mov dx,800
call gensound
jmp l1
error: lea dx,messg4
mov ah,09h
int 21h
jmp l1
exit: mov ah,4ch
int 21h
exit1: lea dx,messg7
mov ah,09h
int 21h
mov ah,01h
int 21h
mov ah,4ch
int 21h
main endp
gensound proc near
push dx
mov al,0b6h
out 43h,al
mov dx,8h
mov ax,3208h
div cx
out 42h,al
mov al,ah
out 42h,al
in al,61h
mov ah,al
or al,3
out 61h,al
l3: push dx
push ax
mov dx,8h
mov ax,0f05h
s1: sub ax,1
sbb dx,0
jnz s1
pop ax
pop dx
dec bx
jnz l3
mov al,ah
out 61h,al
pop dx
ret
gensound endp
code ends
end start
在l1循环那里,执行的速度太慢了。不知道怎么回事,或者怎么改?作用就是输入0-9和A-F得到对应的music-freq里的数字输入到CX里