I know that x86 instructions can have a maximum of 4 bytes of prefixes, e.g Lock, rep, segment overrides etc.
Is there any particular order in which they should appear, in case multiple prefixes are used?
I know that x86 instructions can have a maximum of 4 bytes of prefixes, e.g Lock, rep, segment overrides etc.
Is there any particular order in which they should appear, in case multiple prefixes are used?
the order can be found in volume 2A of the Intel Software Developer's Manual.
In a nutshell:
F2
and F3
prefixes cancel each other out. The one that comes later has precedence.66
prefix is ignored if either F2
or F3
are used (as mandatory prefixes in a long instruction). This of course doesn't apply to rep movsw
where both those prefixes are simply prefixes, not part of the opcode.66
, F2
or F3
for the rest, the order shouldn't matter.
a5
indicates movsl
(resp. movsd
in Intel syntax) because the default operand size is 32 bit. So to get movsw
, you need to use a 66
prefix. Thus, rep movsw
is 66 f3 a5
which you say is invalid. This is strange. –
Hest movsw
is not an SSE instruction, so the answer should be updated to make clear, that this only applies to SSE instructions. And again, the answer you link to does not cite an authoritative source and neither does the reddit comment it cites. Could be just implementation defined behaviour. –
Hest movsw
and movsd
, but we know that both of those instructions are usable with REP prefixes in any mode, using a 66
operand-size prefix when necessary. –
Sickler Quote from Intel® 64 and IA-32 Architectures Software Developer’s Manual Volume 2A: Instruction Set Reference, A-M
Instruction prefixes are divided into four groups, each with a set of allowable prefix codes. For each instruction, it is only useful to include up to one prefix code from each of the four groups (Groups 1, 2, 3, 4). Groups 1 through 4 may be placed in any order relative to each other.
The architecture volume of the intel developer manuals details the layout at lenght, however, from what I remember last time I read it, the order for most didn't matter, except the REX
/REX.W
prefix which must occupy the slot closest to the start of the actual instruction bytes (aka it takes the slot most on the right)
© 2022 - 2024 — McMap. All rights reserved.
rep movsw
in 32 bit mode? – Hest