2016-03-01 99 views
1

我试图用8086汇编程序绘制一个圆。我尝试使用midpoint circle algorithm,这可悲的是由于某种原因导致绘制倾斜的方块(下面的屏幕截图)。作为参考,我重写了python中的算法,并设法绘制一个没有问题的圆圈。使用8086汇编语言绘制一个圆圈

我有一种感觉,我的负数字操作有些问题,但不能让我明白,因为Turbo Debugger几乎没有告诉我什么。你能指导我朝着正确的方向吗? 我附上下面的代码:

; Program: graph.asm 
.MODEL small 
.STACK 256 

.DATA 

.CODE 

jmp start 
;========================================= 
; Basic program to draw a circle 
;========================================= 
mode db 18 ;640 x 480 
x_center dw 300 
y_center dw 200 
y_value dw 0 
x_value dw 100 
decision dw 1 
colour db 1 ;1=blue 
;========================================= 
start: 
mov ah,00 ;subfunction 0 
mov al,mode ;select mode 18 
int 10h ;call graphics interrupt 
;========================== 
mov bx, x_value 
sub decision, bx 
mov al,colour ;colour goes in al 
mov ah,0ch 

drawcircle: 
mov al,colour ;colour goes in al 
mov ah,0ch 

mov cx, x_value ;Octonant 1 
add cx, x_center ;(x_value + x_center, y_value + y_center) 
mov dx, y_value 
add dx, y_center 
int 10h 

mov cx, x_value ;Octonant 4 
neg cx 
add cx, x_center ;(-x_value + x_center, y_value + y_center) 
int 10h 

mov cx, y_value ;Octonant 2 
add cx, x_center ;(y_value + x_center, x_value + y_center) 
mov dx, x_value 
add dx, y_center 
int 10h 

mov cx, y_value ;Octonant 3 
neg cx 
add cx, x_center ;(-y_value + x_center, x_value + y_center) 
int 10h 

mov cx, x_value ;Octonant 7 
add cx, x_center ;(x_value + x_center, -y_value + y_center) 
mov dx, y_value 
neg dx 
add dx, y_center 
int 10h 

mov cx, x_value ;Octonant 5 
neg cx 
add cx, x_center ;(-x_value + x_center, -y_value + y_center) 
int 10h 

mov cx, y_value ;Octonant 8 
add cx, x_center ;(y_value + x_center, -x_value + y_center) 
mov dx, x_value 
neg dx 
add dx, y_center 
int 10h 

mov cx, y_value ;Octonant 6 
neg cx 
add cx, x_center ;(-y_value + x_center, -x_value + y_center) 
int 10h 

inc y_value 

condition1: 
cmp decision,0 
ja condition2 
mov cx, y_value 
mov ax, 2 
imul cx 
add cx, 1 
inc cx 
add decision, cx 
mov bx, y_value 
mov dx, x_value 
cmp bx, dx 
ja readkey 
jmp drawcircle 

condition2: 
dec x_value 
mov cx, y_value 
sub cx, x_value 
mov ax, 2 
imul cx 
inc cx 
add decision, cx 
mov bx, y_value 
mov dx, x_value 
cmp bx, dx 
ja readkey 
jmp drawcircle 



;========================== 
readkey: 
mov ah,00 
int 16h ;wait for keypress 
;========================== 
endd: 
mov ah,00 ;again subfunc 0 
mov al,03 ;text mode 3 
int 10h ;call int 
mov ah,04ch 
mov al,00 ;end program normally 
int 21h 

END Start 

尝试在汇编 Attempt in Assembler 尝试在Python Attempt in Python

预先感谢帮助!

+0

你画了一个L1范数圈而不是L2范数圈。我猜你的程序集实现实际上并没有对x和y值进行平方。 – 2016-03-01 16:33:40

+1

好吧,但C中的维基百科示例(https://en.wikipedia.org/wiki/Midpoint_circle_algorithm)不涉及任何平方,是吗?我还没有在我的Python实现中使用任何平方,但它的工作原理。 – Devon

+0

你说得对,我的错误。那么看起来你实际上并没有增加。 – 2016-03-01 16:44:51

回答

0

这是你的汇编代码的广场吸引了来自公式:

|x| + |y| = constant 

这意味着你的价值没有得到平方

+0

您的回答看起来不清楚。请参考[如何写出一个好答案](https://stackoverflow.com/help/how-to-answer)来扩展您的答案。 – Teocci