title: Comparing numbers in inline c assembly
body: <p>I'm trying to get a feel for inline assembly in c, and I have never done any assembly programming before, so I'm trying to convert random pieces of code I have to assembly.
  I got a problem with the code below, what I wanted it to do was returning 0x20 (32) if a is below
  0x20 (32) or above 0x7e (126). (thats unprintable characters) However it also turns the characters
  between those numbers into 0x20 (32)</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  int foo(int a) {
    asm (
      "mov $0x20, %%ebx;"
      "cmp %%eax, %%ebx;"
      "jl l1;"
      "mov $0x7e, %%ebx;"
      "cmp %%eax, %%ebx;"
      "jg l1;"
      "jmp l2;"
      "l1: movl $0x20, %%eax;"
      "l2:;"
  
      : "=a" (a)
      : "a" (a)
      : "%ebx"
    );
    return a;
  }
  int main(void) {
    int i;
    for (i = 0; i &lt;= 255; i++) {
      printf("%i: %i\n", i, foo(i));
    }
  }
  </code></pre>
  
  <p>This outputs<br>
  0: 32<br>
  1: 32<br>
  2: 32<br>
  ...<br>
  31: 32<br>
  32: 32<br>
  33: 32<br>
  34: 32<br>
  35: 32<br>
  ...<br>
  125: 32<br>
  126: 32<br>
  127: 32<br>
  128: 32<br>
  ...</p>