| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 687 人关注过本帖
标题:求大神,汇编程序执行太慢
只看楼主 加入收藏
wdzfbq
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2012-1-2
结帖率:0
收藏
已结贴  问题点数:20 回复次数:2 
求大神,汇编程序执行太慢
stack segment
    dw 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里
搜索更多相关主题的帖子: 330 continue please 
2012-01-02 15:31
zaixuexi
Rank: 12Rank: 12Rank: 12
来 自:上海
等 级:火箭侠
威 望:8
帖 子:858
专家分:3233
注 册:2010-12-1
收藏
得分:20 
执行太慢?delay太高?

技术问题,请不要以短消息方式提问
2012-01-02 21:24
zaixuexi
Rank: 12Rank: 12Rank: 12
来 自:上海
等 级:火箭侠
威 望:8
帖 子:858
专家分:3233
注 册:2010-12-1
收藏
得分:0 
程序代码:
stack segment
    dw 512 dup(?)                                                                  ;uint16_t task_stack[512];uint16_t sp = sizeof(stack);
stack ends

data segment
music_freq                                                                         ;uint16_t 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                                                                 ;uint16_t music_time = 800;   
messg1 db 'Thank you for using it','$'                                             ;const char *
messg2 db 0ah,0dh,'it is a music program','$'                                      ;const char *
messg3 db 0ah,0dh,'please choose mode(Q:exit other key:continue)','$'              ;const char *
messg4 db 0ah,0dh,'input error!$'                                                  ;const char *
messg5 db 0ah,0dh,'you can play the music now(key:0-F,Q:exit the program)!','$'    ;const char *
messg6 db 0ah,0dh,'$'                                                              ;const char *
messg7 db 0ah,0dh,'thank you for using it,any key to exit!','$'                    ;const char *
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                   ;puts(messg1);
    lea dx,messg2
    mov ah,09h
    int 21h                   ;puts(messg2);
    lea dx,messg3
    mov ah,09h
    int 21h                   ;puts(messg3);
input:
    mov ah,01h
    int 21h
    cmp al,'Q'
    jz exit                   ;if (getchar() == 'Q') goto exit;
    lea dx,messg5
    mov ah,09h
    int 21h                   ;puts(messg5);
    lea dx,messg6
    mov ah,09h
    int 21h                   ;puts(messg6);
l1:
    mov ah,01h                ;char ch;
    int 21h
    cmp al,'Q'
    jz exit1                  ;if ((ch = getchar()) == 'Q') goto exit1;
    cmp al,30h
    jb error
    cmp al,46h
    ja error                  ;else if ((ch < '0') || (ch > 'F')) goto error;
    cmp al,40
    jb num                    ;else if (ch < '(') goto num; ????
    jmp abcdef                ;else goto abcdef;
num:
    sub al,30h               
    mov dl,2
    mul dl
    lea bx,music_freq         ;uint16_t *mf = music_freq;
    mov si,ax                 ;uint16_t i = (uint16_t)((ch - (uint8_t)0x30) << 1);
    mov cx,[bx+si]            ;uint16_t freq = mf[i];
    mov dx,800
    call gensound             ;gensound(800, freq);
    jmp l1                    ;goto l1;
abcdef:
    sub al,31h
    mov dl,2
    mul dl
    lea bx,music_freq
    mov si,ax                 ;i = (uint16_t)((ch - (uint8_t)0x31) << 1);
    mov cx,[bx+si]            ;count = mf[i]
    mov dx,800
    call gensound             ;gensound(800, freq);
    jmp l1                    ;goto l1;
error:
    lea dx,messg4
    mov ah,09h
    int 21h                   ;puts(messg4);
    jmp l1                    ;goto l1;
exit:
    mov ah,4ch
    int 21h                   ;exit(0);
exit1:
    lea dx,messg7
    mov ah,09h
    int 21h                   ;puts(messg7);
    mov ah,01h
    int 21h                   ;getchar();
    mov ah,4ch
    int 21h                   ;exit(0);
main endp

gensound proc near            ;void gensound(uint16_t time, uint16_t freq);
    push dx                   ;task_stack[--sp] = time;
                              ;#define D6 (6) #define D4 (4) #define D1 (1)
                              ;#define _TIMER(2) #define _RHRL (3) #define _MODE (3) #define _BIN(0)
                              ;#define TIMER2 (_TIMER << D6) #define LHMODE (_RHRL << D4)
                              ;#define MODE3 (_MODE << D1) #define BIN _BIN
    mov al,0b6h               ;#define CTRL_WORD (TIMER2 | LHMODE | MODE3 | BIN)
                              ;#define TIMER_CONTROLLER (0x43)
    out 43h,al                ;write_port(TIMER_CONTROLLER, CTRL_WORD);/*pseudocode*/
    mov dx,8h
    mov ax,3208h
    div cx                    ;uint16_t pulse = 0x83208 / freq;
                              ;#define TIMER2_PORT (0x42)
    out 42h,al                ;write_port(TIMER2_PORT, LOBYTE(pulse));/*pseudocode*/
    mov al,ah
    out 42h,al                ;write_port(TIMER2_PORT, HIBYTE(pulse));/*pseudocode*/
                              ;#define 8255_PB (0x61)
    in  al,61h                ;uint8_t pb = read_port(8255_PB);
    mov ah,al
                              ;#define SET_PB0 (1) #define SET_PB1 (1 << 1)
    or  al,3                  ;pb |= (SET_PB0 | SET_PB1);
    out 61h,al                ;write_port(8255_PB, pb);
l3:
    push dx                   ;task_stack[--sp] = 0x83208 % freq;
    push ax                   ;task_stack[--sp] = pulse;
    mov dx,8h
    mov ax,0f05h              ;uint32_t init_t = 80f05h;
s1:
    sub ax,1
    sbb dx,0                  ;--init_t;
    jnz s1                    ;if (HIWORD(init_t) != 0) goto s1;
    pop ax                   
    pop dx                    ;init_t = MAKELONG(task_stack[sp++], task_stack[sp++]);
    dec bx                    ;????
    jnz l3                    ;if (???? != 0) goto l3;
    mov al,ah               
    out 61h,al                ;write_port(8255_PB, HIBYTE(LOWORD(init_t));
    pop dx                    ;time = task_stack[sp++];
    ret                       ;return;
gensound endp
code     ends
end     start
你先看看

技术问题,请不要以短消息方式提问
2012-01-02 23:40
快速回复:求大神,汇编程序执行太慢
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.016110 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved