Minimal runnable example
.byte
spits out bytes wherever you are. Whether there is a label or not pointing to the byte, does not matter.
If you happen to be in the text segment, then that byte might get run like code.
Carl mentioned it, but here is a complete example to let it sink in further: a Linux x86_64 implementation of true
with a nop
thrown in:
.global _start
_start:
mov $60, %rax
nop
mov $0, %rdi
syscall
produces the exact same executable as:
.global _start
_start:
mov $60, %rax
.byte 0x90
mov $0, %rdi
syscall
since nop
is encoded as the byte 0x90
.
One use case: new instructions
One use case is when new instructions are added to a CPU ISA, but only very edge versions of the assembler would support it.
So project maintainers may choose to inline the bytes directly to make it compilable on older assemblers.
See for example this Spectre workaround on the Linux kernel with the analogous .inst
directive: https://github.com/torvalds/linux/blob/94710cac0ef4ee177a63b5227664b38c95bbf703/arch/arm/include/asm/barrier.h#L23
#define CSDB ".inst 0xe320f014"
A new instruction was added for Spectre, and the kernel decided to hardcode it for the time being.