What is the maximum number of bytes a complete instruction would require in x64 asm code?
Something like a jump to address might occupy up to 9 bytes I suppose: FF 00 00 00 00 11 12 3F 1F but I don't know if that's the maximum number of bytes a x64 instruction can use
The x86 instruction set (16, 32 or 64 bit, all variants/modes) guarantees / requires that instructions are at most 15 bytes. Anything beyond that will give an "invalid opcode". You can't achieve that without using redundant prefixes (e.g. multiple 0x66 or 0x67 prefixes, for example).
The only instruction that actually takes 64-bits as a data item is the load constant to register (Intel syntax:
mov reg, 12345678ABCDEF00h
, at&t syntax:movabs $12345678ABCDEF00, %reg
) - so if you wanted to jump more than 31 bits forward/backward, it would be a move of the target location into a register, and then call/jump to the register. Using 32-bit immediates and displacements (in relative jumps and addressing modes) saves four bytes on many instructions in 64-bit mode.From the Intel® 64 and IA-32 Architectures Software Developer’s Manual:
You can construct instructions that would encode to more than 15 bytes, but such instructions would be illegal and would probably not execute.
https://web.archive.org/web/20131109063453/https://www.onlinedisassembler.com/blog/?p=23
Another long instruction without repeating prefixes
http://www.sandpile.org/x86/opc_enc.htm