title: How to change value under memory address in C inline assembly (GCC)
body: <p>In one of the exercises in my assembler course we have to create a program that will change all uppercase letters in char* to lowercase. </p>
  
  <pre><code> char *a = "AAA BB CCC";
   char *b;
   asm(
   ".intel_syntax noprefix;"
     "xor ecx, ecx;"
     "xor eax, eax;"
     "lea eax, [%[a]];"  // getting address of the first char into eax
    "loop:"
     "inc ecx;" // loop variable
     "cmp ecx, 10;" // 10 cycles for very character in *a
     "jne lowercase;"
     "jmp end;"
   "lowercase:"
     "mov bl, [eax];" // copy value stored under eax address to bl
     "add bl, 32;" // make it lowercase in ASCII
     "mov [eax], bl;" // copy it back to address stored in eax
     "inc eax;" // move pointer to the next char
     "jmp loop;"
   "end:"
     "lea %[b], [eax];" 
   ".att_syntax prefix;"
     : [b] "=r" (b)
     : [a] "r" (a)
    : "eax", "ebx", "ecx"
   );
  </code></pre>
  
  <p>My idea was to get address of the first char, increase it by 32 (making it lowercase in ASCII), save it on the same address, than move pointer to the next char and so on. Getting first char and adding 32 to it works fine, its this line that throws "Segmentation fault":</p>
  
  <pre><code>"mov [eax], bl;"
  </code></pre>
  
  <p>From what I understand it should change value under address held in eax to value of bl. I feel like I'm missing something obvious, but I'm pretty new to this and everything I found so far on the net leads me to believe that this is how I should do it.</p>