gccassemblyx86djgpp

djgpp gpp pass variable inline assembly


using DJGPP with compiler gpp and intel syntax
How to pass variable into inline assembly?
the error is follows:
undefined reference to `n'

The code:

void geninterrupt (int n) {
        asm("mov al, byte ptr [_n]");
        asm("mov byte ptr [genint+1], al");
        asm("jmp genint");
    asm("genint:");
        asm("int 0");
}

Solution

  • djgpp uses the gcc constraint system for extended asm.

    void geninterrupt (int n) {
            __asm__ __volatile__("mov byte ptr [genint+1], al\n\t"
            "genint: int 0" : : "a" (n));
    }
    

    You will need to list the clobbered registers if the interrupt changes any.