How to draw a square (int 10h) using loops?

青春壹個敷衍的年華 提交于 2019-12-06 07:32:44
mov ah, 0   ; set display mode function.
mov al, 13h ; mode 13h = 320x200 pixels, 256 colors.
int 10h     ; set it!

mov cx, 10  ;col
mov dx, 10  ;row
mov ah, 0ch ; put pixel

colcount:
inc cx
int 10h
cmp cx, 30
JNE colcount

mov cx, 10  ; reset to start of col
inc dx      ;next row
cmp dx, 30
JNE colcount

(Based on your code) this should draw a square,

each time drawing 20 pixels in a row(by increasing cx-col), then going to the next row(increase dx-row) and drawing 20 pixels in that row.

This will create a square by drawing 20pixels each row in 20 rows

The answer presented by YonBruchim indeed draws a rectangle of 20x20 dots at (11,10)-(30,29) but starts out with an extra dot at (10,10)!
This BIOS call also needs you specify the video page number in BH (mostly 0) and the pixel color in AL (15 for bright white).
As already pointed out by Ruud never assume AX will be preserved by any API call.

Personally I don't like constructs like
cmp cx,30 jne colcount
Rather use
cmp cx,30 jb colcount
The latter is more forgiving if ever CX 'sits' at the wrong end of the value range you are expecting!

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!