What is the use of .byte assembler directive in gnu assembly?

前端 未结 4 1404
借酒劲吻你
借酒劲吻你 2020-12-10 03:41

While going through some C code having inline assembly I came across the .byte (with a Dot at the beginning) directive.

On checking the assembly reference on web I f

4条回答
  •  被撕碎了的回忆
    2020-12-10 04:26

    Here's an example with inline assembly:

    #include 
    void main() {
       int dst;
       // .byte 0xb8 0x01 0x00 0x00 0x00 = mov $1, %%eax
       asm (".byte 0xb8, 0x01, 0x00, 0x00, 0x00\n\t"
        "mov %%eax, %0"
        : "=r" (dst)
        : : "eax"  // tell the compiler we clobber eax
       );
       printf ("dst value : %d\n", dst);
    return;
    }
    

    (See compiler asm output and also disassembly of the final binary on the Godbolt compiler explorer.)

    You can replace .byte 0xb8, 0x01, 0x00, 0x00, 0x00 with mov $1, %%eax the run result will be the same. This indicated that it can be a byte which can represent some instruction eg- move or others.

提交回复
热议问题