title: C Inline ASM: passing integers to a register
body: <p>I'm trying to make a simple kernel but I'm stucked on a cursor screen movement.
  My function, for move the cursor, is written in Assembly, but the rest of the kernel is in C, so I have to make a C function for call that function. And that's the C function:</p>
  
  <pre><code>void setCursor(unsigned int x, unsigned int y) {
      asm("mov (%0), %%bl" :: "r" (y) : "%bl");
      asm("mov (%0), %%bh" :: "r" (x) : "%bh");
      asm("call set_cursor");
  }
  </code></pre>
  
  <p>In this function, I try to move the var <code>unsigned int x</code> to register <code>bh</code> and the other, <code>unsigned int y</code>, to register <code>bl</code>, and then call the function to move the cursor.</p>
  
  <p>The problem is when I call this function, the cursor disappear from the screen. I think the values <code>x</code> and <code>y</code> and registers values <code>bl</code> and <code>bh</code> are not the same. For give you an idea of that clue, I tested to pass values directly in the asm directive and it works:</p>
  
  <pre><code>void setCursor(unsigned int x, unsigned int y) {
      asm("mov $1, %bl");
      asm("mov $2, %bh");
      asm("call set_cursor");
  }
  </code></pre>
  
  <p>Any help is welcome. And thanks in advance. :D</p>
  
  <p><strong>Assembly output from compiler</strong>
  Ubuntu 12.04 64bit compiling in 32bit</p>
  
  <pre><code>setCursor:
  .LFB12:
      .cfi_startproc
      pushl   %ebp
      .cfi_def_cfa_offset 8
      .cfi_offset 5, -8
      movl    %esp, %ebp
      .cfi_def_cfa_register 5
      movl    12(%ebp), %eax
      pushl   %ebx
      .cfi_offset 3, -12
  #APP
  # 131 "./kernel/screen.c" 1
      mov (%eax), %bl
  # 0 "" 2
  #NO_APP
      movl    8(%ebp), %eax
  #APP
  # 132 "./kernel/screen.c" 1
      mov (%eax), %bh
  # 0 "" 2
  # 133 "./kernel/screen.c" 1
      call set_cursor
  # 0 "" 2
  #NO_APP
      popl    %ebx
      .cfi_restore 3
      popl    %ebp
      .cfi_def_cfa 4, 4
      .cfi_restore 5
      ret
      .cfi_endproc
  </code></pre>