0

How to use _emit to emit bytes in clang compiler?

e.g(in MSVC):

#define emit_nop() _asm _emit 0x90
cYeR
  • 145
  • 1
  • 10
  • clang does not support `_emit` (at least not that I know about it). You can use the `asm` keyword for a similar effect, but I wonder what you are trying to achieve. – fuz Apr 10 '19 at 17:56

1 Answers1

1

In compilers that support GNU extensions, there's no need for a separate emit keyword, just use GNU C inline assembly:

asm(".byte 0x90");   // implicitly   asm volatile

Or .long to emit a 32-bit constant.

GNU C inline asm is not parsed to detect clobbers or anything, so you could just asm("nop");

If you want to use instructions that modify registers, you normally need to tell the compiler about it with GNU C Extended inline assembly (output/input/clobbers). See https://stackoverflow.com/tags/inline-assembly/info.

Peter Cordes
  • 328,167
  • 45
  • 605
  • 847