我的代码是在Assembly8086上编写的,我在通过循环生成像素时遇到问题,如何设置一定数量的行和列来停止生成?
org 100h
mov ah, 0 ; set display mode function.
mov al, 13h ; mode 13h = 320x200 pixels, 256 colors.
int 10h ; set it!
setrow db '50'
setcol db '50'
mov ax, setcol
mov bx, setrow
mov cx, 10 ; column
mov dx, 20 ; row
mov al, 15 ; white
mov ah, 0ch ; put pixel
int 10h
addpixel:
inc cx
int 10h
cmp ax,cx
JNE addpixel
ret
答案 0 :(得分:0)
使用loop
指令。
mov cx, 100 ; number of times to loop
addpixel:
; draw the pixel here
; remember not to mess up cx
loop addpixel
使用int 10h
绘制像素很慢,非常慢。直接写入视频存储器更快更简单,模式13h为0xa000:0000。
push 0xa000
pop es
mov di, 20*320+10 ; col=10, row=20
mov cx, 100 ; number of pixels to draw
mov al, 15 ; white
rep stosb ; write 100 white pixels
答案 1 :(得分:0)
杜斯特,
所有源代码行都引用了' setcol'和' setrow'在这个小程序中没用/没用过
执行cmp ax,cx
AX时只包含BIOS功能编号和使用的颜色!所以这个比较完全是错误的。
如图所示,您的程序显示从(10,20)开始并向右移动的水平线。因为(大多数)BIOS不太关心功能参数,所以当这条线到达(319,20)屏幕的右边界时,不知道会发生什么!
我有兴趣了解运行此程序时屏幕上发生了什么?
答案 2 :(得分:0)
像这样构建你的代码:
org 100h
mov ah, 0 ;set display mode function
mov al, 13h ;mode 13h= 320x200 pixels, 256 colors.
int 10h ;set it!
jmp short omit_variables ;jump over the variables, otherwise they'll be interpreted false.
left_border dw 0 ;The first X-Value you want to draw. Use DW instead of DB, cause cx and
dx are 16 bit registers
upper_border dw 0 ;The uppermost row.
right_border dw 319 ;The right border.
bottom_border dw 199 ;The lowermost row.
omit_variables:
mov cx, [left_border]
mov dx, [upper_border]
looping:
mov al, 15 ;white
mov ah, 0ch ;put pixel
int 10h
inc cx
cmp cx, [right_border]
jb looping ;Repeat the inner loop until cx is over the maximal X value
mov cx, [left_border]
inc dx
cmp dx, [bottom_border]
jb looping ;Repeat the outer loop until dx is over the maximal Y value
ret