title: C++ Passing arguments to inline assembler function
body: <p>I have problem with inline asm in C++. I'm trying to implement fast strlen, but it is not working - when I use <code>__declspec(naked)</code> keyword debugger shows address of input as 0x000000, when I don't use that keyword, eax is pointing for some trash, and function returns various values.</p>
  
  <p>Here's code:</p>
  
  <pre><code>   int fastStrlen(char *input) // I know that function does not calculate strlen
  {                              // properly, but I just want to know why it crashes
      _asm                       // access violation when I try to write to variable x
      {
          mov ecx, dword ptr input
              xor eax, eax
          start:
              mov bx, [ecx]
              cmp bl, '\0'
              je Sxend
              inc eax
              cmp bh, '\0'
              je Sxend
              inc eax
              add ecx, 2
              jmp start
          Sxend:
              ret
      }
  }
  
  int _tmain(int argc, _TCHAR* argv[])
  {
      char* test = "test";
      int x = fastStrlen(test);
      cout &lt;&lt; x;
      return 0;
  }
  </code></pre>
  
  <p>can anybody point me out what am I doing wrong?</p>