3 ms·
This doesn't sound right. REP prefixes are pretty rare. Depending on compiler they are used rarely, for a few specific operations (like rep movsd for memcpy) o
by msm_ 3y ago
This doesn't sound right.
REP prefixes are pretty rare. Depending on compiler they are used rarely, for a few specific operations (like rep movsd for memcpy) or usually never.
Most common prefixes are by far REX prefixes in 6h4 64bit assembly (don't believe me? Look at the 64bit code in vim and see all those `H` letters around. It's REX.W). Segment override prefixes are another class of prefixes that are used in handwritten assembly (in bootloader or special runtime functions) but almost never used by compilers.
In older code, most common prefixes are 0x66h (it doesn't even has opcode, there's no way to emit it directly) and maybe 0x67h.
They are all used to modify some aspect of the next executing instruction, for example the "default" register size is 32bit, but you can change it with a prefix. I think an example will help.
$ echo 31c0 | xxd -r -ps | ndisasm -b64 /dev/stdin 00000000 31C0 xor eax,eax
$ echo 6631c0 | xxd -r -ps | ndisasm -b64 /dev/stdin
00000000 6631C0 xor ax,ax
$ echo 4831c0 | xxd -r -ps | ndisasm -b64 /dev/stdin 00000000 4831C0 xor rax,rax
And there are also the extensions of base, SIB and Mod/RM fields, mentioned by the article (to the extended set of high registers):
$ echo 4431c0 | xxd -r -ps | ndisasm -b64 /dev/stdin 00000000 4431C0 xor eax,r8d
$ echo 4131c0 | xxd -r -ps | ndisasm -b64 /dev/stdin
00000000 4131C0 xor r8d,eax