编写程序实现demo.exe演示笑脸小球运动效果

 

 

; 编写程序实现demo.exe演示效果。
;提示:小球运动行号列号变化规律是
;   碰到上壁则行号变为自增规律
;   碰到下壁则行号变为自减规律
;   碰到左壁则列号变为自增规律
;   碰到右壁则列号变为自减规律
;当运动到的地方已经有小球存在时,将其颜色变为绿色
;思路分析:主函数中调用三个子程序
;       (1)判断边界(2)显示笑脸(3)延时
;初始化:行dh=0,列dl=0,
;        行方向bh=1,列方向bl=1

assume cs:code
code segment
start: mov dx,0
       mov bh,1
       mov bl,1

       mov cx,50*80  ;显示出50*80个笑脸后结束
mains: call judge
       call show_str
       call delay
       loop mains

       mov ax,4c00h
       int 21h

;名称:judge
;功能:判断边界
;参数:(dh)=行,(dl)=列
judge: 
  judgeh:cmp dh,24
         je seth24
         cmp dh,0
         je seth0
         jmp short ok0
  seth24: mov bh,-1
         jmp short judgel
   seth0:mov bh,1
     ok0:nop

  judgel:cmp dl,79
         je setl79
         cmp dl,0
         je setl0
         jmp short ok1
  setl79:mov bl,-1
         jmp short ok1
   setl0:mov bl,1
     ok1:ret

名称:show_str
;功能:在屏幕上显示字符‘笑脸’
;参数:(dh)=行,(dl)=列,(bh)=行方向,(bl)=列方向
show_str: push ax
          push bx
          push dx
          mov ax,0b800h
          mov es,ax
          mov si,0
          add dh,bh
          add dl,bl

          ;计算dh*160+dl*2
          mov al,160
          mul dh
          mov dh,0
          add ax,dx
          add ax,dx
          mov si,ax
          cmp byte ptr es:[si],1
          jne next
   mov byte ptr es:[si],1
          mov byte ptr es:[si+1],02h
    next: mov byte ptr es:[si],1
       
          pop dx
   add dh,bh
   add dl,bl
   pop bx
          pop ax
          ret
;名称:delay
;功能:延时
;参数:无
delay:push cx
      mov cx,020ffh
   s0:push cx
      mov cx,020ffh
   s1:nop
      loop s1
      pop cx
      loop s0
      pop cx
      ret

code ends
end start

 


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章