汇编语言,在屏幕上移动图片

时间:2015-12-01 17:26:08

标签: assembly x86 irvine32

我是汇编语言的新手,非常复杂的语言。阅读本书后,我试图将图片移动到屏幕上,延迟时间为300.这就是本书中的程序所说的内容。 "将图片从10,10移动到20,10,延迟时间为300"

我想知道如何添加这个并希望让图片在屏幕上移动,本书并没有真正解释这对我的理解有益。

这是我制作的节目。

   TITLE  call demos          (calldemoline.asm)
;  
; Last update:Dec 1, 2015   
INCLUDE Irvine32.inc
 .data
    deltax byte ?
    number byte ?
    symbol byte ?
    y1 byte 10
.code    
 main proc
       call clrscr
      mov ecx,7
     mov eax,ecx
     add eax,ecx
     inc eax   ;ecx+1
     mov number,al

     picture:
         movzx eax,number
        mov deltax, cl          
        mov al,'-'
        mov symbol,al
        call drawline
        mov al,number
        sub al,cl
        sub al,cl
        mov deltax,al
        mov al,'x'
        mov symbol,al
        call drawline
        movzx eax,number
        mov deltax, cl          
        mov al,'-'
        mov symbol,al
        call drawline
        call crlf
     loop picture
      exit
main ENDP
 drawline proc
     push ecx
  movzx ecx, deltax
        mov al,symbol
     draw:
           call writechar
       loop draw
      pop ecx
     ret
    drawline endp
END main

1 个答案:

答案 0 :(得分:2)

有两个问题:

1)如何放置图片?
2)如何移动它?

1)您的绘图操作实际上是光标当前位置的call writechar序列。使用call clrscrcall crlf,您可以将光标移动到左侧边框。要将光标移动到另一个位置,Irvine库提供函数Gotoxy

试一试:

...
mov dh, 0                   ; Row = 0
picture:

    mov dl, 10              ; Col = 10
    call Gotoxy

    ... (no change)

    ; call crlf
    inc dh                  ; Instead of call crlf
loop picture
...

2)要移动图片,您必须在绘制新图片之前将旧图片空白。清算在您的情况下很容易:而不是写' - '和' x'只是写一个空间。我刚刚将绘图块加倍并更改了字符:

INCLUDE Irvine32.inc

.data
    deltax byte ?
    number byte ?
    symbol byte ?
    y1 byte 10

    col BYTE 9              ; Column of the first clearing action
    row BYTE 0

.code
main PROC
    call clrscr

    mov ecx,7
    mov eax,ecx
    add eax,ecx
    inc eax   ;ecx+1
    mov number,al

    L1:
    call clear_picture
    inc col                 ; Next column
    call draw_picture
    mov eax, 300
    call Delay
    cmp col, 20             ; Was picture drawed at column 20?
    jne L1                  ; No, once one

    L2:
    exit
main ENDP

draw_picture PROC USES ECX
    movzx eax, row              ; Preserve row
    push eax

    picture:
    mov dl, col
    mov dh, row
    call Gotoxy

    movzx eax,number
    mov deltax, cl
    mov al,'-'
    mov symbol,al
    call drawline

    mov al,number
    sub al,cl
    sub al,cl
    mov deltax,al
    mov al,'x'
    mov symbol,al
    call drawline

    movzx eax,number
    mov deltax, cl
    mov al,'-'
    mov symbol,al
    call drawline

    inc row                     ; Instead of call crlf
    loop picture

    pop eax                     ; Restore row
    mov row, al
    ret
draw_picture ENDP

clear_picture PROC USES ECX
    movzx eax, row              ; Preserve row
    push eax

    picture:
    mov dl, col
    mov dh, row
    call Gotoxy

    movzx eax,number
    mov deltax, cl
    mov al,' '
    mov symbol,al
    call drawline

    mov al,number
    sub al,cl
    sub al,cl
    mov deltax,al
    mov al,' '
    mov symbol,al
    call drawline

    movzx eax,number
    mov deltax, cl
    mov al,' '
    mov symbol,al
    call drawline

    inc row                     ; Instead of call crlf
    loop picture

    pop eax                     ; Restore row
    mov row, al
    ret
clear_picture ENDP

drawline PROC
    push ecx
    movzx ecx, deltax
    mov al,symbol

    draw:
    call writechar
    loop draw

    pop ecx
    ret
drawline ENDP

END main