Search code examples
cassemblyinline-assemblyjittcc

Use raw binary blob of instructions in C code


I'm working with jit compilation by TCC (Tiny C Compiler) but it have a limited support for assembly and I get frequently stuck by this... I would like to know if there is some kind of trick to insert raw instructions into inline assembly? Such as:

mov -0x18(%rbp), %rax
finit
flds (%rax)

/* Custom unsupported binary instructions here */

flds (%rcx)

I know it won't be an easy maintainable thing, but I would like to keep TCC unmodified.


Solution

  • If it supports standard GAS / unix-assembler directives like .byte 0x00, 0x12, you can emit any byte sequence you want. (Also .word or .long if you want to use write a 16 or 32-bit immediate as a single 32-bit number.)

    GNU as manual