title: Strange behavior in ASM (x64 Intel - Linux) with RAX register and DIV instruction
body: <p>I wrote this code in asm x64 on an Intel processor on Linux and it should counts the number of digits of RDI content and returns the result into RAX.
  It simply divides RAX by 10 until RAX equals 0 (until quotient equals 0). At each loop, RCX increases :</p>
  <pre><code>bits 64
  global _start
  
  section .text
  
  _start:
      mov rdi,1234
      
      push rcx
      push rsi
      push rdx
  
      mov rsi,0xa
      mov rax,rdi
      xor rcx,rcx
  
  func_loop:
      cmp rax,0x0
      jz func_fin
      inc rcx
      div rsi
      jmp func_loop
  
  func_fin:
      mov rax,rcx
  
      pop rdx
      pop rsi
      pop rcx
  
      mov rax,0x3c ; sys_exit
      mov rdi,0x0
      syscall
  </code></pre>
  <p>When executed, the program seems to be in an infinite loop... GDB tells me this :</p>
  <p><a href="https://i.stack.imgur.com/7mej7.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/7mej7.png" alt="enter image description here" /></a></p>
  <p>Could you tell me why RAX content is suddenly changing from 123 to 7378697629483820658 ?
  Did i misunderstand the use of DIV instruction ?</p>
  <p>Thank you for all your attention to this.</p>