0

I got this procedure for drawing a rectangle using int 10h/ah=0Ch to draw each pixel:

proc drawRect  ;this function gets the coords of the upper left point of the rect and the height and width, as well as the color of it, and draw
mov cx, [n1]    ;n1=x, n2=y, n3=width, n4=height, al=color
mov dx, [n2]
add [n3], cx
add [n4], dx
row:
    mov dx, [n2]
    column:
        mov ah, 0Ch     ;draws a pixel on the given color and coords, due to the loops.
        mov bh, 0
        int 10h

        inc dx
        cmp dx, [n4]
        jbe column
    inc cx
    cmp cx, [n3]
    jbe row
ret
endp drawRect

the problem is that it takes too much time to draw, for example, in order to draw a rectangle 500x500 pixels it takes about 1.5 seconds, which is way too long than I expected. Is there any faster way to draw it?

plsHelpMe
  • 15
  • 6
  • 3
    On a normal PC-compatible system, you can access the VGA framebuffer directly instead of going through slow BIOS interrupts. Either write an efficient memset yourself with SSE2 instructions like `movntdqa` for writing to the framebuffer, or use `rep stosb` (especially on modern CPUs; on classic 8086 you'll want `rep stosw`, and branch to see if you need one more store at the end if the size was odd.) – Peter Cordes Jul 27 '23 at 23:55
  • I second direct VRAM access is your best option ... using BIOS call for every pixel is too complex while with direct VRAM access is just matter of single instruction. See [Graphics mode in assembly 8086](https://stackoverflow.com/a/48664419/2521214) and its sublinks ... – Spektre Jul 28 '23 at 07:33
  • If you can, draw a whole line with one call instead of a single point, or better yet, draw a whole rectangle with one call instead of drawing lines — this (among other things) is the purpose of graphics packages. – Erik Eidt Jul 28 '23 at 16:46

0 Answers0