; Draw a circle with a given center and radius
; Input: cx, cy, r
; Output: Circle drawn on the screen
section .data
section .text
global _start
_start:
; Set video mode 0x13 (320x200x256)
mov ax, 0x0013
int 0x10
; Set circle center and radius
mov cx, 160 ; x-coordinate of the center
mov cy, 100 ; y-coordinate of the center
mov r, 50 ; radius
; Initialize x and y
mov x, r
mov y, 0
; Initial decision parameter
mov d, 3 - 2 * r
; Loop to draw all points in the first octant
draw_circle:
; Draw eight points of the circle using Bresenham's algorithm
mov ax, cx + x
mov bx, cy + y
call plot_pixel
mov ax, cx + y
mov bx, cy + x
call plot_pixel
mov ax, cx - x
mov bx, cy + y
call plot_pixel
mov ax, cx - y
mov bx, cy + x
call plot_pixel
mov ax, cx - x
mov bx, cy - y
call plot_pixel
mov ax, cx - y
mov bx, cy - x
call plot_pixel
mov ax, cx + x
mov bx, cy - y
call plot_pixel
mov ax, cx + y
mov bx, cy - x
call plot_pixel
; Update decision parameter
cmp d, 0
jle inc_y
sub d, 4 * x + 6
sub x, 1
inc_y:
add d, 4 * y + 6
add y, 1
; Repeat the loop until x >= y
cmp x, y
jg draw_circle
; Wait for a key press
call wait_for_key
; Set video mode 0x03 (80x25x16)
mov ax, 0x0003
int 0x10
; Exit to the operating system
mov ax, 0x4c00
int 0x21
; Plot a pixel at the given location
; Input: ax = x-coordinate, bx = y-coordinate
; Output: Pixel plotted on the screen
plot_pixel:
; Calculate the memory offset of the pixel
mov di, bx
imul di, 320
add di, ax
shl di, 1
; Plot the pixel in video memory
mov al, 0xff
mov es, [0x9000]
mov [es:di], al
ret
; Wait for a key press
; Input: None
; Output: Key code stored in ax
wait_for_key:
mov ah, 0
int 0x16
ret