title: I am unable to draw a circle using midpoint algorithm in 8086 Assembly with Direct Memory Access
body: <p>I have an assignment in which I am supposed to make shapes move and change shapes with colors. I haven't been successful at drawing an octant of a circle in the first place. Supposed to use Intel 8086 Assembly Language using TASM in DMA mode. (mode 19)
  I was thinking if I could finish making a circle, I could animate it and change shapes. I could not figure out whether the Algorithm is wrong or the code.</p>
  
  <pre><code>.model small
  .stack 256
  
  .code 
  startaddr   dw  0a000h  ;start of video memory   
  color   db  3 
  xc dw  160
  yc dw 100
  r dw  50 ; radius
  x dw 0 
  y dw 50 ;radius
  pk dw 1
  temp dw 1
  
  plot macro r1, r2, r3 ;x,y,color
      mov ax, r2
      mov bx, 320
      mul bx
      add ax, r1
      mov di, ax
      mov al, r3
      mov es:[di], al
  endm
  
  start:    
    mov ax, yc
    add y, ax
    mov ah,00    
    mov al, 13h    
    int 10h           ;switch to 320x200 mode  
    mov es, startaddr
    mov dx, y
    mov ax, xc
    add x, ax
    plot x, dx, color
    mov bx, r
    mov pk, bx
    sub pk, 1
    neg pk
    cmp pk, 0
    jge pk1
  
  drawc:
      mov bx, x
      sub bx, xc
      mov ax, y
      sub ax, yc
      mov temp, ax
      cmp bx, temp
      jge keypress
  
      mov dx, y
      plot x, dx, color
  
  peekay:
      cmp pk, 0
      jg pk1
      mov ax, x
      mov bx, 2
      mul bx
      add ax, pk
      mov pk, ax
      inc x ;x+1
      jmp drawc
  
  pk1:
      dec y
      mov ax, x
      sub ax, y
      mov bx, 2
      mul bx
      add ax, pk
      mov pk, ax
      inc x
      jmp drawc
  
  keypress:    
    mov ah,00    
    int 16h           ;await keypress  
  
    mov ah,00    
    mov al,03    
    int 10h   
  
    mov ah,4ch    
    mov al,00         ;terminate program    
    int 21h 
  end start
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/oHfDa.jpg" rel="nofollow noreferrer">Output</a></p>