This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| en:multiasm:papc:chapter_6_7 [2025/10/23 15:10] – [BMI1 and BMI2 Instructions] ktokarz | en:multiasm:papc:chapter_6_7 [2026/04/01 14:13] (current) – [Instruction Set of x64 - Essentials] ktokarz | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| - | ====== Instruction Set of x86 - Essentials ====== | + | ====== Instruction Set of x64 - Essentials ====== |
| + | The x64 processors can execute an extensive number of different instructions. As processors have evolved, the instruction set has expanded from the initial 117 in the 8086 processor to over 1000 in modern 64-bit designs. In this chapter, we present the instruction groups and a description of essential instructions called general-purpose instructions. | ||
| ===== Instruction groups ===== | ===== Instruction groups ===== | ||
| - | The x64 processors can execute an extensive number of different instructions. | + | In the documentation of processors, we can find several ways of dividing all instructions into groups. The most general division, according to AMD, defines five groups of instructions: |
| * General Purpose instructions | * General Purpose instructions | ||
| * System instructions | * System instructions | ||
| Line 105: | Line 107: | ||
| In the **mov** instruction, | In the **mov** instruction, | ||
| <code asm> | <code asm> | ||
| - | mov al, 100 ;0xB0, 0x64 | + | mov al, 100 ;0xB0, 0x64 |
| - | mov al, [bx] ; | + | ;copy constant (immediate) of the value 100 (0x64) to al |
| + | |||
| + | mov al, [bx] ; | ||
| + | ;copy byte from the memory at address stored in bx to al | ||
| + | ;(indirect addressing) | ||
| ;Notice the difference between two following instructions | ;Notice the difference between two following instructions | ||
| - | mov eax, 100 ; | + | mov eax, 100 ; |
| - | mov eax, [100] ; | + | ;copy constant 100 to eax |
| + | |||
| + | mov eax, [100] ; | ||
| + | ;copy value from memory at address 100 | ||
| ;It is possible to copy a constant to memory addressed directly or indirectly | ;It is possible to copy a constant to memory addressed directly or indirectly | ||
| - | ;operand size specifier dword ptr is required to inform the processor about the size of the argument | + | ;operand size specifier dword ptr is required |
| - | mov dword ptr ds:[200], 100 ; | + | ;to inform the processor about the size of the argument |
| - | ;copy value of 100, encoded as dword (four bytes), 0x64 = 100 | + | mov dword ptr ds:[200], 100 |
| - | ;to memory at address 200, encoded as four bytes, | + | ;0xC7, 0x05, 0xC8, 0x00, 0x00, 0x00, 0x64, 0x00, 0x00, 0x00 |
| + | | ||
| + | | ||
| | | ||
| - | mov dword ptr [ebx], 100 ;0xC7, 0x03, 0x64, 0x00, 0x00, 0x00 | + | mov dword ptr [ebx], 100 |
| - | ;copy value of 100, encoded as dword (four bytes), 0x64 = 100 | + | ;0xC7, 0x03, 0x64, 0x00, 0x00, 0x00 |
| - | ;to memory addressed by ebx | + | |
| + | | ||
| </ | </ | ||
| ==== Conditional move ==== | ==== Conditional move ==== | ||
| Line 159: | Line 171: | ||
| * **cwde** - converts word in ax to doubleword extended in eax | * **cwde** - converts word in ax to doubleword extended in eax | ||
| * **cdq** - converts doubleword in eax to quadword in edx:eax | * **cdq** - converts doubleword in eax to quadword in edx:eax | ||
| + | * **cdqe** - convert doubleword in eax to quadword in rax | ||
| + | * **cqo** - convert quadword in rax to double quadword in rdx:rax | ||
| - | Sign extension instructions work solely with the accumulator. Fortunately, | + | Sign extension instructions work solely with the accumulator. Fortunately, |
| * **movsx** - copies and sign-extends a byte to a word or doubleword or word to doubleword. | * **movsx** - copies and sign-extends a byte to a word or doubleword or word to doubleword. | ||
| * **movzx** - copies and zero-extends a byte to a word or doubleword or word to doubleword. | * **movzx** - copies and zero-extends a byte to a word or doubleword or word to doubleword. | ||
| Line 388: | Line 402: | ||
| ==== String compare ==== | ==== String compare ==== | ||
| Strings can be compared, which means that the element of the destination string is compared with the element of the source string. These instructions set the status flags in the flags register according to the result of the comparison. The elements of both strings remain unchanged. | Strings can be compared, which means that the element of the destination string is compared with the element of the source string. These instructions set the status flags in the flags register according to the result of the comparison. The elements of both strings remain unchanged. | ||
| - | The **cmps** instruction compares the element of a source string with the element of the destination string. It requires | + | The **cmps** instruction compares the element of a source string with the element of the destination string. It requires |
| The **cmpsb** instruction compares a byte from the source string with a byte from the destination string. | The **cmpsb** instruction compares a byte from the source string with a byte from the destination string. | ||
| The **cmpsw** instruction compares a word from the source string with a word from the destination string. | The **cmpsw** instruction compares a word from the source string with a word from the destination string. | ||
| Line 558: | Line 572: | ||
| </ | </ | ||
| - | The **blsr** instruction resets (clears | + | The **blsr** instruction resets (clears |
| <figure blsr_instr> | <figure blsr_instr> | ||
| Line 572: | Line 586: | ||
| </ | </ | ||
| - | PDEP Parallel | + | The **pdep** instruction performs a parallel |
| - | PEXT Parallel | + | |
| + | <figure pdep_instr> | ||
| + | {{ : | ||
| + | < | ||
| + | </ | ||
| + | |||
| + | The **pext** instruction performs a parallel | ||
| + | |||
| + | <figure pext_instr> | ||
| + | {{ : | ||
| + | < | ||
| + | </ | ||