title: Length of a string using NASM
body: <p>I have tries to write a code in NASM to get the length of the given string. But is gives some garbage value as a length. The code is the following one:</p>
  
  <pre><code>    section .data
          a db "nitin",10,0
          msg db "length = %d",10,0
      section .text
          global main
          extern printf
      main:
           nop
           xor eax,eax
           mov eax, a
           xor edx,edx
      length:
           mov dl, byte[eax]
           cmp dl,0
           je print
           inc eax
           jmp length
  
      print:
           pusha
           push eax
           push msg
           call printf
           add esp,8
           popa
      done:
           nop
  </code></pre>
  
  <p>The result is shown:
           Length =132445678</p>
  
  <p>Can you please help me to sort out my mistake?</p>
  
  <p>thank you   </p>