title: How to print the length of a string in assembly
body: <p>I am learning assembly using the following hello world program</p>
  
  <pre><code>section .text
      global _start     ;must be declared for linker (ld)
  
  _start:             ;tells linker entry point
     mov  edx,len     ;message length
     mov  ecx,msg     ;message to write
     mov  ebx,1       ;file descriptor (stdout)
     mov  eax,4       ;system call number (sys_write)
     int  0x80        ;call kernel
  
     mov  eax,1       ;system call number (sys_exit)
     int  0x80        ;call kernel
  
  section .data
      msg db 'Hello, world!', 0xa  ;our string
      len equ $ - msg              ;length of our string
  </code></pre>
  
  <p>The original question I had was what is meant by the length of the string. Does it mean the number of chars or the length in memory (number of bytes)?
  To check this I wanted to print the variable len. How can I do that? I naively tried to define the new variable</p>
  
  <pre><code>    len2 equ $ - len
  </code></pre>
  
  <p>and then instead run </p>
  
  <pre><code>   mov  edx,len2     ;message length
     mov  ecx,len     ;message to write
     mov  ebx,1       ;file descriptor (stdout)
     mov  eax,4       ;system call number (sys_write)
     int  0x80        ;call kernel
  </code></pre>
  
  <p>to try to print len, but this printed nothing. How can I print the number that is represented by len?</p>