This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revision | |||
| en:multiasm:papc:chapter_6_6 [2026/06/22 12:25] – pczekalski | en:multiasm:papc:chapter_6_6 [2026/06/22 12:47] (current) – pczekalski | ||
|---|---|---|---|
| Line 97: | Line 97: | ||
| In 64-bit mode, the CS, SS, DS and ES segment overrides are ignored. | In 64-bit mode, the CS, SS, DS and ES segment overrides are ignored. | ||
| - | The **branch hint** prefixes can appear together with conditional jump instructions. These prefixes can be used to support the branch prediction unit of the processor | + | The **branch hint** prefixes can appear together with conditional jump instructions. These prefixes can be used to support the processor' |
| - | The **operand size** and **address size override** prefixes can change the default size of operands and addresses. For example, if the processor operates in 32-bit mode, using the 0x66 prefix changes | + | The **operand size** and **address size override** prefixes can change the default size of operands and addresses. For example, if the processor operates in 32-bit mode, using the 0x66 prefix changes an operand |
| <code asm> | <code asm> | ||
| ;encoding | ;encoding | ||
| Line 107: | Line 107: | ||
| </ | </ | ||
| - | We can notice | + | We can see that, because the default operand size is a 32-bit doubleword, the 16-bit version (WORD PTR) uses the 0x66 prefix. It is also visible that the 8-bit version (BYTE PTR) has a different opcode (0xC6, 0x03 instead of 0xC7, 0x03). Also, the size of the argument is different. |
| - | The address override prefix (0x67) appears | + | The address-override prefix (0x67) appears |
| <code asm> | <code asm> | ||
| ; | ; | ||
| Line 159: | Line 159: | ||
| < | < | ||
| =====Instruction opcode===== | =====Instruction opcode===== | ||
| - | The instruction opcode is the mandatory field in every instruction. It encodes the main function | + | The instruction opcode is the mandatory field in every instruction. It encodes the operation' |
| <code asm> | <code asm> | ||
| opcode | opcode | ||
| Line 177: | Line 177: | ||
| vblendvpd xmm0, xmm1, xmm2, xmm3 ;0xC4, 0xE3, 0x71, 0x4B, 0xC2, 0x30 | vblendvpd xmm0, xmm1, xmm2, xmm3 ;0xC4, 0xE3, 0x71, 0x4B, 0xC2, 0x30 | ||
| </ | </ | ||
| - | The first blendvpd instruction has only two arguments; in this encoding scheme is not possible to encode more. It uses the mandatory | + | The first blendvpd instruction has only two arguments; in this encoding scheme, it is not possible to encode more. It uses the mandatory |
| =====MOD R/M byte===== | =====MOD R/M byte===== | ||
| - | The ModR/M byte encodes the addressing mode, a register which is used as an operand in the instruction, | + | The ModR/M byte encodes the addressing mode, a register which is used as an operand in the instruction, |
| <figure modrm_byte> | <figure modrm_byte> | ||
| Line 190: | Line 190: | ||
| * Mod - Mode. This 2-bit field gives the register/ | * Mod - Mode. This 2-bit field gives the register/ | ||
| * Reg - Register. This 3-bit field specifies one of the general-purpose registers used as the operand. It can also be the opcode extension. | * Reg - Register. This 3-bit field specifies one of the general-purpose registers used as the operand. It can also be the opcode extension. | ||
| - | * R/M - Register/ | + | * R/M - Register/ |
| In x86, the Mod field specifies one of four possible memory addressing modes, and the R/M field specifies which register, or pair of registers, is used for address calculation. If the Mod field is 11 (binary), the R/M field specifies the second register in the instruction. Details are shown in table {{ref> | In x86, the Mod field specifies one of four possible memory addressing modes, and the R/M field specifies which register, or pair of registers, is used for address calculation. If the Mod field is 11 (binary), the R/M field specifies the second register in the instruction. Details are shown in table {{ref> | ||
| Line 237: | Line 237: | ||
| In 32-bit mode, registers used for addressing can be specified with the SIB byte, but this is not always the case. If a single register is used (with some exceptions), | In 32-bit mode, registers used for addressing can be specified with the SIB byte, but this is not always the case. If a single register is used (with some exceptions), | ||
| - | In 64-bit long mode, the MOD R/M byte encoding works in a similar manner | + | In 64-bit long mode, the MOD R/M byte encoding works similarly |
| <table modrm_640> | <table modrm_640> | ||
| Line 315: | Line 315: | ||
| In the tables {{ref> | In the tables {{ref> | ||
| - | Let's look at some code examples, | + | Let's look at some code examples, |
| <code asm> | <code asm> | ||
| ;MOD R/M (second byte) is 0x04 for all instructions: | ;MOD R/M (second byte) is 0x04 for all instructions: | ||
| Line 329: | Line 329: | ||
| </ | </ | ||
| - | And other examples for x64 processors. The SIB byte is extended with bits from the REX prefix. We'll start with the similar examples as shown for 32-bit machines. | + | And other examples for x64 processors. The SIB byte is extended with bits from the REX prefix. We'll start with similar examples as shown for 32-bit machines. |
| <code asm> | <code asm> | ||
| Line 366: | Line 366: | ||
| Certainly, the presented examples do not exhaust all possible situations. For a more detailed explanation, | Certainly, the presented examples do not exhaust all possible situations. For a more detailed explanation, | ||
| =====Displacement===== | =====Displacement===== | ||
| - | Displacement gives the offset for memory operands. Depending on the addressing mode, it can be the direct memory address or an additional offset added to the contents of the base, index register or both. Displacement can be 1, 2, or 4 bytes long. Some instructions allow using an 8-byte displacement. In these instructions, | + | Displacement gives the offset for memory operands. Depending on the addressing mode, it can be a direct memory address or an additional offset added to the contents of the base register, index register, or both. Displacement can be 1, 2, or 4 bytes long. Some instructions allow the use of an 8-byte displacement. In these instructions, |
| =====Immediate===== | =====Immediate===== | ||
| Some instructions require an immediate value. The instruction determines the length of the immediate value. The immediate can be 1, 2, 4 or 8 bytes long. When an 8-byte immediate value is encoded, no displacement can be encoded. | Some instructions require an immediate value. The instruction determines the length of the immediate value. The immediate can be 1, 2, 4 or 8 bytes long. When an 8-byte immediate value is encoded, no displacement can be encoded. | ||
| - | < | + | < |
| MazeGen, x86 and amd64 instruction reference ((https:// | MazeGen, x86 and amd64 instruction reference ((https:// | ||