Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gcc Inline ASM input variable

I've this code:

void  geninterrupt (int x) {
    __asm__(
    "movb x, %al \n"
        "movb %al, genint+1 \n"
        "jmp genint \n"
    "genint: \n"
        "int $0 \n"
    );
}

How can I make movb use the argument of geninterrupt()?

like image 811
Luca D'Amico Avatar asked Feb 03 '26 06:02

Luca D'Amico


1 Answers

You need to use the constraints fields correctly:

void  geninterrupt (int x) {
  __asm__("  movb %[x], %%al \n"
          "  movb %%al, genint+1 \n"
          "  jmp genint \n"
          "genint: \n"
          "  int $0 \n"
         : /* no outputs */
         : [x] "m" (x) /* use x as input */
         : "al" /* clobbers %al */
         );
}

Here's a good how-to about GCC inline assembly and a link to the relevant GCC documentation.

Edit: since your GCC seems to not be able to handle the labeled operands

like image 129
Carl Norum Avatar answered Feb 05 '26 01:02

Carl Norum



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!