title: For Loops and Transversing through arrays in x86 Assembly Code
body: <p>I am trying to create a program using x86 Assembly (TASM) that transverses through 2 sets of arrays and does a basic addition between the two arrays using a for loop. However, i have never used a for loop or an array in assembly, so im quite confused on how i would go about implementing it. </p>
  
  <p>so let say i have this pusodo code:</p>
  
  <pre><code>for i := 0 to n-1 do
          s := a[ i] + b[ i]; 
          ...
  endfor;
  </code></pre>
  
  <p>An this is my code so far which takes the <code>array a and b</code> in <code>si and di</code> respectively and the size <code>n</code> in <code>cx</code>, how would i implement the above pusodo code in my code?</p>
  
  <pre><code>m   dw  ?
  s   dw  ?
  
  
      .code
  
      extrn   putint: proc
  
      public  maxp_ip
  
  maxp_ip proc ;(n)
  
  ; computes the max-plus inner product between two vectors a and b of length n
  ; input: CX = n
  ;        SI = a
  ;        DI = b  
  ; output: AX = m
  
  ; save regs
      push si
      push di 
      push ax ; assigned to m
      push bx ; assigned to s
      push cx 
  
  ; m := -32768   
      mov m, -32768
  
  ; for i := 0 to n-1 do
  </code></pre>
  
  <p>Note that the above code isnt my entire code, just the part where i want to implement the for loop and addition. Also, could you please explain how I would do this, with sample code (I am a visual learner, so i need to see how to do it, sorry). Thanks.</p>