title: finding average, min and max in assembly
body: <p>I'm having a problem in finding the average, min and max of an array in assembly language. i created a simple array with C++ and created a test.asm file to pass it through. i figured out the average, but now its the min and max i cant seem to figure out.</p>
  
  <pre><code>#include &lt;iostream&gt;
  using namespace std;
  
  extern "C"
  int test(int*, int);
  
  int main()
  {
  const int SIZE = 7;
  int arr[SIZE] = { 1,2,3,4,5,6,7 };
  
  int val = test(arr, SIZE);
  
  
  cout &lt;&lt; "The function test returned: " &lt;&lt; val &lt;&lt; endl;
  
  return 0;
  }
  </code></pre>
  
  <p>This is my test.asm that adds all the values and returns 4.</p>
  
  <pre><code>.686
  .model flat
  
  .code
  
  
  _test PROC ;named _test because C automatically prepends an underscode, it is needed to interoperate
  push ebp
  mov ebp,esp ;stack pointer to ebp
  
  mov ebx,[ebp+8] ; address of first array element
  mov ecx,[ebp+12]
  mov ebp,0
  mov edx,0
  mov eax,0
  
  
  loopMe:
  cmp ebp,ecx
  je allDone
  
  
  add eax,[ebx+edx]
  add edx,4
  add ebp,1
  jmp loopMe
  
  allDone:
  mov edx,0
  div ecx
  
  pop ebp
  ret
  _test ENDP
  
  END
  </code></pre>
  
  <p>I am still trying to figure out how to find the min since the max will be done in a similar way. I assume you use the cmp to compare values but everything i tried so far hasn't been successful. I'm fairly new to assembly language and its hard for me to grasp. Any help is appreciated.</p>