print macro msg
lea dx,msg
mov ah,09h
int 21h
endm
read macro n,j1,j2
mov cx,0ah
j1:mov ah,01h
int 21h
cmp al,0dh
je j2
sub al,30h
mov bl,al
mov ax,n
mul cx
xor bh,bh
add ax,bx
mov n,ax
jmp j1
j2 :nop
endm
.model small
.stack 100h
.data
f db 0
n db 0
msg1 db 10,13,'Enter the center $'
msg2 db 10,13,'X cordinate: $'
msg3 db 10,13,'y cordinate: $'
msg4 db 10,13,'Enter the radius: $'
xc dw 0
yc dw 0
x dw 0
y dw 0
p dw 0
r dw 0
.code
main proc
mov ax,@data
mov ds,ax
;read center(x,y)
print msg1
print msg2
read xc,ju1,ju2
print msg3
read yc,ju3,ju4
print msg4
read r,ju,ju6
;selecting screen
mov ah,00
int 10h
;select mode 12
mov al,12h
int 10h
;plot the center
mov ah,0ch
mov al,05
mov cx,xc
mov dx,yc
int 10h
;draw circle(midpoint algorithm)
;y=r
mov ax,r
mov y,ax
;plot initial point
call plot
;p=1-r
mov ax,01
mov dx,r
xor dx,0ffffh
inc dx
add ax,dx
mov p,ax
;while(x<y)
loop1: mov ax,x
cmp ax,y
jnc jump1
;x++
inc x
;if(p<0)
mov ax,p
rcl ax,01
jnc jump2
;p+=2*x+1
mov ax,x
rcl ax,01
inc ax
add ax,p
jmp jump3
;else
;y++
;p+=2*(x-y)+1;
jump2: dec y
mov ax,x
mov dx,y
xor dx,0ffffh
inc dx
add ax,dx
rcl ax,01
jnc jump4
or ax,8000h
jump4: inc ax
add ax,p
jump3: mov p,ax
;plot point
call plot
jmp loop1
jump1: mov ah,00
int 16h
mov ax,0003
int 10h
stop:mov ah,4ch
int 21h
main endp
plot proc
mov ah,0ch
mov al,02
mov cx,xc
add cx,x
mov dx,yc
add dx,y
int 10h
mov cx,xc
add cx,x
mov dx,yc
sub dx,y
int 10h
mov cx,xc
sub cx,x
mov dx,yc
add dx,y
int 10h
mov cx,xc
sub cx,x
mov dx,yc
sub dx,y
int 10h
mov cx,xc
add cx,y
mov dx,yc
add dx,x
int 10h
mov cx,xc
add cx,y
mov dx,yc
sub dx,x
int 10h
mov cx,xc
sub cx,y
mov dx,yc
add dx,x
int 10h
mov cx,xc
sub cx,y
mov dx,yc
sub dx,x
int 10h
ret
plot endp
end
No comments:
Post a Comment