将coords(x0,y0)中的像素复制到(x1,y1)

时间:2017-01-08 03:58:17

标签: assembly x86 x86-16 dosbox

我正在尝试将一堆像素从屏幕位置复制到其他位置。想象一下,我在坐标(100,120)上有一个8x8的绿色方块,我想将方块复制到坐标(150,60)。

我正在使用图形模式13h。这意味着320x200,所以我的方块从地址38500开始(使用y * 320 + x)。

DS指向0A0000h。

如何将此方块复制到其他坐标(19350)?

我试过这样的事情:

  MOV SI,38500
  MOV DI,19350
INIT:
  MOV CX,4          ; loop 4 times
COPY_BOX:
  MOV AX,DS:[SI]    ; copy two pixels
  MOV DS:[DI],AX
  ADD SI,2          ; move to the next two pixels
  ADD DI,2
  LOOP COPY_BOX
  ADD SI,312        ; drop one line and position on the first pixel
  ADD DI,312
  JMP INIT          ; copy next row of pixels

; do this for the 8 rows

我做错了什么?

1 个答案:

答案 0 :(得分:2)

JMP INIT          ; copy next row of pixels

这是你的程序进入无限循环的地方 您只需要重复代码 height = 8次 我通过将这些小计数器放在CHCL

中解决了这个问题
  MOV SI,100+120*320 ;(100,120)
  MOV DI,150+60*320  ;(150,60)
  MOV CH,8           ; loop 8 times vertically
INIT:
  MOV CL,4           ; loop 4 times horizontally
COPY_BOX:
  MOV AX,DS:[SI]     ; copy two pixels
  MOV DS:[DI],AX
  ADD SI,2           ; move to the next two pixels
  ADD DI,2
  DEC CL
  JNZ COPY_BOX
  ADD SI,320-8       ; drop one line and position on the first pixel
  ADD DI,320-8
  DEC CH
  JNZ INIT   

如果您愿意使用字符串原语,它可能如下所示:

  CLD
  PUSH DS             ; 0A000h
  POP  ES
  MOV  SI,100+120*320 ;(100,120)
  MOV  DI,150+60*320  ;(150,60)
  MOV  AX,8           ; loop 8 times vertically
INIT:
  MOV  CX,4           ; 4 x 2 pixels
  REP MOVSW           ; copy 1 line of pixels
  ADD  SI,320-8       ; drop one line and position on the first pixel
  ADD  DI,320-8
  DEC  AX
  JNZ  INIT