title: C / Assembly: how to change a single bit in a CPU register?
body: <p>I'm a new researcher on the software fault injection field, and currently my ultimate goal is to write a simple piece of code that is able to change a single bit in a CPU register. I was thinking of doing it in C (with some Assembly calls included amongst the code). With that in mind, I found here in Stack Overflow this great thread &amp; simple example on how to access the contents of a 32 bit CPU register: <a href="https://stackoverflow.com/questions/3022046/is-it-possible-to-access-32-bit-registers-in-c">Is it possible to access 32-bit registers in C?</a> This way, I was able to write this simple code:</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  
  int main()
  {
      register int value;
  
      register int ecx asm("ecx");
      printf("Contents of ecx: %d\n", ecx);
  
      asm("movl %%ecx, %0;" : "=r" (value) : ); //Assembly: this stores the ecx value into the variable value
      printf("Contents of value: %d\n", value);
  
      return 0;
  }
  </code></pre>
  
  <p>This seems to be a great introduction to this theme, and the answers provided there gave me great insight and information sources (I'm already reading the GCC documentation), but now I need to move further, i. e., I need to understand how can I change the contents of a single bit in a CPU register (or at least, to start, something simpler: how can I change a CPU register value?). If someone can give me a hint or tell me the most approriate source to look for it, I'd be deeply grateful.</p>
  
  <p>All the best &amp; thanks in advance,
  João</p>
  
  <p>P.S.: Don't know if this helps, but I'm working on a CentOS 6.5 32 bit system (although the CPU is a 64 bit one, more precisely a Intel Pentium Dual CPU E2180 @ 2.00 GHz). Also, I have had previous contact with Assembly, but it was like 10 years ago, on a single course unit for a couple of months, so currently I'm trying to review the little knowledge I have on the language.</p>