+ -
当前位置:首页 → 问答吧 → [修改程序]字符串以单词为单元循环显示

[修改程序]字符串以单词为单元循环显示

时间:2010-11-23

来源:互联网

Assembly code

.model small

.486

.data

show db "I am glad to see you."

range dw 20 ;字符串长度

front dw ?   ;首指针

rear dw ?    ;尾指针

flag db ?  ;为远跳转准备

times db 100   ;循环次数

.code

.startup

  

;功能:把位置加1,并限制在长度为area的循环队列中

;参数:position为当前的位置,area:队列长度

cycle macro position,increase,area     ;
       add position,increase

       .if(position>area)

       sub position,area

       dec position   

       .endif

       endm


again:

  mov flag,0

  mov front,0

  mov rear,20

  .repeat    

    mov si,front   

   .repeat      ;此循环为显示从front到rear的字符

    mov ah,02h

    mov dl,show[si]

    int 21h     ;输出show[si]的字符

    cycle si,1,range  ;si加1并使其在循环为rang的队列中

   .until(si==rear)

   mov dl,show[si]

   int 21h

    ;延时程序段

   mov ecx,245678h  ;
  next:NOP

  loopd next  ;

   ;将光标移到本行前面

   mov ah,03h 

   mov bh,0    

   int 10h  ;读当前光标位置   

   mov dl,0  ;修改光标的列  ;
   mov ah,02h

   int 10h  

    ;查找下个显示的开头和结尾

   mov si,front  

  .repeat

    inc si

   .until(show[si]==' '||show[si]=='.')

   .if(show[si]==' ')

   inc si

   mov front,si   ;设置头指针

   dec si  

   mov rear,si    ;设置尾指针

   .endif

.until(show[si]=='.')


jump:

cmp flag,1

je again    ;跳转到目的位置again


dec times 

mov flag,1

cmp times,0

jne jump  ;跳转到比较近的地方

.exit 0

end



这个程序只是移动的显示字符串,现在要把这个字符串每一次移动改变后的字符串都输出来,以便于肉眼能够清晰的看到,进行对比几次移动后的字符串。

作者: kartik   发布时间: 2010-11-23

把移动改为延迟显示,直接显示下一个单词。

作者: asmlearn   发布时间: 2010-11-24