title: NASM x64 maximum value in array
body: <p>I would be very grateful if you could give me some advice because I struggle with it very long and I don't know why it prints 288230376151711745 instead of maximum value.</p>
  
  <pre><code>#include &lt;iostream&gt;
  
  using namespace std;
  
  extern "C" long long max(long long [], int);
  
  int main()
  {
  
  long long maxi;
  int n = 3;
  long long arr[3] = {53,434,4};
  
  maxi = max(arr, n); // (rdi, rsi)
  cout &lt;&lt; maxi &lt;&lt; endl;
  return 0;
  
  }
  </code></pre>
  
  <p>////////////////////////////////////////</p>
  
  <pre><code>global max
  
  section .text
  
  max:
  mov rax, 0
  mov rax, [rdi]
  mov rbx, 0
  
  _loop:
  
  cmp rbx, rsi
  je _end
  
  cmp [rdi + rbx+8],rax
  ja _assign
  inc rbx
  jmp _loop
  
  _assign:
  
  mov rax, [rdi + rbx+8]
  inc rbx
  jmp _loop
  
  _end:
  
  ret
  </code></pre>