Change of registry value: error or feature



  • There's a code on 😄

    #include <stdint.h>
    

    void a()
    {
    asm volatile("int $0x10": :"b"(0x0700));
    }

    void b(uint8_t color)
    {
    asm volatile("int $0x10" : :"b"(color));
    }

    int main(){
    a();
    b(7);
    return 0;
    }

    For compilation by gcc 5.3 with options -S -O2 -march=i686 -m32 inside function main This assembler code is produced:

    pushl   %ebx
    movl $1792, %ebx /1792=0x0700/
    int $0x10
    movb $7, %bl
    int $0x10
    xorl %eax, %eax
    popl %ebx
    ret

    It appears that before the second interruption in the register %ebx 0x07, i.e. the register %bh I don't know. Is that a compilator's fault or something special about a built-in assembler? If it's the last one, where's the documentation? I also noticed that if I indicated another type of variable: asm volatile("int $0x10" : :"b"((uint16_t)color));that's how it works.



  • You're using the Compiler of Language C while you're making assembler boxes. The compiler can't figure out what you want. He doesn't know what he's doing. int 0x10 and what registers he needs at the entrance. If you make an assemble box, the correctness of its implementation is entirely on you. Which means you have to transmit the parameter of the type with which your interruption works, not least. The compiler never finds that eight battles should be loaded in a 16-bit register because after you cause the BX to interrupt. That's what you're bringing the type to int16, just like you do.

    With documentation, https://gcc.gnu.org/onlinedocs/gcc-3.4.6/gcc/Extended-Asm.html the first thing you found google. Read:

    The input operands need not be lvalues. The compiler cannot check whether the operands have data types that are reasonable for the instruction being executed. It does not parse the assembler instruction template and does not know what it means or even whether it is valid assembler input.

    That's what it says, the compiler doesn't check the type of Operand data. It doesn't solve the assembler instructions, and it doesn't know what they mean, and even that it's a correct entry. P.S. Who knows English well, tell me exactly how to sound.




Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2