我一直试图在装配中画一个盒子并将其水平移动 沿着屏幕,打印方格纸本身的代码对我有用,但是当我尝试使其移动时,效果不是很好,如果您明白我的意思,我可以看到他在移动,但不是完整的正方形。
我的代码:在Assembly Tasm中
STA SEGMENT STACK
DB 0FFFeH DUP(?)
STA ENDS
DATA SEGMENT
;-----------
;VARIABLES HERE
xpos dw 50h
ypos dw 50h
color db 9h
constat equ 0ffffh
siNum dw ?
diNum dw ?
numOFtime dw 0h
;-------------
DATA ENDS
CODE SEGMENT
ASSUME CS:CODE,DS:DATA,SS:STA
START :
MOV AX,DATA
MOV DS,AX
;start coding here:
mov ah, 0 ; Set display mode
mov al, 13h ; 13h = 320x200, 256 colors
int 10H ; Video BIOS Services
mov cx,50h
mov dx,50h
mov si,25H
mov di,25H
PrintSquare:
;------------------------------------------------------------------------
;cx = xpos , dx = ypos, si = x-length, di = y-length, al = color
didi:
mov color,9h
mov bp,0h
do:
add cx,si
here:
mov bh,0h
mov al,color
mov ah, 0Ch ; write pixel at coordinate
int 10h ; draw pixel!
dec cx
cmp cx,xpos
ja here
inc dx
inc bp
cmp bp,25h
jbe do
call drawBlackBox
inc numOFtime
inc xpos; incrising to make the sqaure moving horizontically
mov cx,xpos; cx gets the xposition
mov dx,ypos
cmp numOFtime,constat
jb didi
mov ah,004Ch ; terminate program
int 21h
;
drawBlackBox proc
mov color,0h ; black color
mov bp,0h
mov cx,xpos
mov dx,ypos
do1:
add cx,si
here1:
mov bh,0h
mov al,color
mov ah, 0Ch ; write pixel at coordinate
int 10h ; draw pixel!
dec cx
cmp cx,xpos
ja here1
inc dx
inc bp
cmp bp,25h
jbe do1
mov cx,xpos
ret
drawBlackBox endp
CODE ENDS
END START