3

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()?

1

1 Answer 1

2

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

Sign up to request clarification or add additional context in comments.

3 Comments

Thanks Carl (for both this and the pack(pop) question, I'm having a lot of difficulties tonight..), but I got this error with your code: invalid 'asm': operand number missing after %-letter __asm__(" movb %[x], %al \n"
Whoops - missed some % signs. Fixed now. I also had to change to an m constraint.
IT WORKS!!!! Thank you very much mate!! Also thank you very much for both the useful links !! :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.