title: Counting zeros in an array assembly 8086
body: <p>I wrote this code to count the number of zeros in the array vec:</p>
  
  <pre><code>.model small
  .stack 100h           
  .data
      vec dw 1,2,0,3,0,4,5,6,0,0,5
      m1 dw 0
  .code
      mov ax,@data
      mov ds,ax
      mov di,1 ;di is our running index
  number_of_zeros:
      mov ax,vec[di]
      cmp ax,0
      je increment_m1 ;case its zero
      inc di;case its not zero
      cmp di,11
      jl number_of_zeros
      cmp di,11
      je end
  increment_m1:
      inc m1
      inc di
      cmp di,11
      jl number_of_zeros
      cmp di,11
      je end
  end:
      mov ax,m1
  </code></pre>
  
  <p>It's not displaying the correct output. I'm expecting to see AX=4, but instead, when the program finished running I can see that AX=3.</p>
  
  <p>I think the problem is with how I access individual elements in the array. For some reason that I can't figure out, at the first iteration it says that vec[1]=0200</p>
  
  <p>Edit: Ok I correct the code, it does indeed give the desired outcome BUT...It still shows weird values for vec[di]. I still think I'm accessing it wrong and i got the correct result because of chance. I'd like someone to review it.</p>