flat assembler
Message board for the users of flat assembler.
![]() |
Author |
|
DimonSoft 10 Sep 2018, 18:18
Different encodings. See Intel Software Developer’s Manual.
For 16-bit mode using eax (32-bit register) requires the $66 prefix. In 32-bit mode the prefix is not required since the operand is of default size, so it basically is equal to the one in 16-bit mode except for the size-override prefix. In 64-bit mode the byte values $40–$4F that used to be INC/DEC instructions became so called REX prefixes which are specific to 64-bit mode. So, the encoding of INC is different here (uses $FF escape byte). |
|||
![]() |
|
trogne 10 Sep 2018, 18:55
Thanks, I understand the 16-bit prefix, but not the 64-bit prefix.
What do you mean by "byte values $40–$4F" and "REX prefix" ? Why the extra 1 in second part : 11111111 11000000 instead of 11111111 01000000 ? |
|||
![]() |
|
trogne 10 Sep 2018, 19:09
Oh I think I see.
The range "01000000" ($40) to "01001111" ($4F) pertains to 64-bit mode (REX prefix). So the encoding is different : the INC instruction is instead "11000000", and DEC is "11001000". That's right ? |
|||
![]() |
|
DimonSoft 10 Sep 2018, 20:12
The encoding of INC and DEC becomes a 2-byte opcode where the first byte has value $FF and it is used as the first byte for a few other instructions as well, and the second byte is used to determine which of those instructions is actually used. Note also that if you change the register the second byte value will change. AFAIR, it will be the least-significant 3 bits having values 000 = EAX, 001 = ECX, 010 = EDX 011 = EBX, etc.
|
|||
![]() |
|
Mikl___ 11 Sep 2018, 00:02
Hi, trogne!
look here examples of INC instruction in 64-bit mode |
|||
![]() |
|
Tomasz Grysztar 11 Sep 2018, 06:59
Let me try provide a wider image.
There are two different ways to encode INC REG, one short and one long. Similarly, there are two ways of encoding DEC REG: 01000RRR - INC REG (RRR = 000 for EAX) 11111111 11000RRR - INC REG 01001RRR - DEC REG 11111111 11001RRR - DEC REG Assemblers generate the shorter form whenever possible, the longer usually has no advantages. But in long mode the short form no longer exists, these encodings have been taken over to mean REX prefix. Therefore the long one remains the only option. In addition to that, instruction without prefixes (as the ones shown above) uses the size of register that is native to the mode. 66h prefix (01100110) changes the size to 32-bit when in 16-bit mode, or to 16-bit in all other modes. USE16 01000000 - INC AX 01100110 01000000 - INC EAX 11111111 11000000 - INC AX 01100110 11111111 11000000 - INC EAX USE32 01000000 - INC EAX 01100110 01000000 - INC AX 11111111 11000000 - INC EAX 01100110 11111111 11000000 - INC AX USE64 (short form of INC/DEC does not exist) 11111111 11000000 - INC EAX 01100110 11111111 11000000 - INC AX 01001000 11111111 11000000 - INC RAX The last instruction above uses REX prefix. |
|||
![]() |
|
trogne 11 Sep 2018, 18:30
Thank you
![]() |
|||
![]() |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.