Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
en:multiasm:papc:chapter_6_6 [2026/02/19 20:26] – [Instruction opcode] ktokarzen:multiasm:papc:chapter_6_6 [2026/02/19 20:48] (current) – [Scale Index Base byte] ktokarz
Line 86: Line 86:
 <code asm> <code asm>
 mov BYTE PTR [ebx], 5     ;DS as the default segment mov BYTE PTR [ebx], 5     ;DS as the default segment
-mov BYTE PTR ES:[ebx], 5  ;ES segment override (results in appearance of the byte 0x26 as the prefix)+mov BYTE PTR ES:[ebx], 5  ;ES segment override  
 +                          ;(results in appearance of the byte 0x26 as the prefix)
 </code>  </code> 
   * 0x2E – CS segment override   * 0x2E – CS segment override
Line 171: Line 172:
   * 0x8F Three-byte XOP   * 0x8F Three-byte XOP
 VEX-encoded instructions are written with V at the beginning. Let's look at the example of the blending instruction. VEX-encoded instructions are written with V at the beginning. Let's look at the example of the blending instruction.
-<code>+<code asm>
                                   ;encoding                                   ;encoding
 blendvpd xmm0, xmm1               ;0x66, 0x0F, 0x38, 0x15, 0xC1  blendvpd xmm0, xmm1               ;0x66, 0x0F, 0x38, 0x15, 0xC1 
Line 206: Line 207:
 Let's look at some examples of instruction encoding. First, look at the data transfer between two registers. Let's look at some examples of instruction encoding. First, look at the data transfer between two registers.
 <code asm> <code asm>
-              ;                         MOD REG R/M   MOD               REG   R/M +              ;encoding      MOD REG R/M   MOD               REG   R/M 
-mov al, dl    ;encoded as 0x88, 0xD0    11  010 000   Register operand  DL    AL +mov al, dl    ;0x88, 0xD0    11  010 000   Register operand  DL    AL 
-mov ax, dx    ;encoded as 0x89, 0xD0    11  010 000   Register operand  DX    AX +mov ax, dx    ;0x89, 0xD0    11  010 000   Register operand  DX    AX 
-mov dx, si    ;encoded as 0x89, 0xF2    11  110 010   Register operand  SI    DX +mov dx, si    ;0x89, 0xF2    11  110 010   Register operand  SI    DX 
-mov si, dx    ;encoded as 0x89, 0xD6    11  010 110   Register operand  DX    SI+mov si, dx    ;0x89, 0xD6    11  010 110   Register operand  DX    SI
 </code> </code>
 Notice that in the first and second lines, different opcodes are used, but the MOD R/M bytes are identical. The type of instruction determines the order of data transfer. Notice that in the first and second lines, different opcodes are used, but the MOD R/M bytes are identical. The type of instruction determines the order of data transfer.
Line 216: Line 217:
 Now, a few examples of indirect addressing without displacement. Now, a few examples of indirect addressing without displacement.
 <code asm> <code asm>
-                                      MOD REG R/M   MOD               REG   R/    +               ;encoding      MOD REG R/M   MOD               REG   R/    
-mov dx,[si]   ;encoded as 0x8B, 0x14    00  010 100   Reg. only addr.   DX    [SI] +mov dx,[si]    ;0x8B, 0x14    00  010 100   Reg. only addr.   DX    [SI] 
-mov dx,[di]   ;encoded as 0x8B, 0x15    00  010 101   Reg. only addr.   DX    [DI] +mov dx,[di]    ;0x8B, 0x15    00  010 101   Reg. only addr.   DX    [DI] 
-mov dx,[bx+di];encoded as 0x8B, 0x11    00  010 001   Reg. only addr.   DX    [BX+DI] +mov dx,[bx+di] ;0x8B, 0x11    00  010 001   Reg. only addr.   DX    [BX+DI] 
-mov cx,[bx+di];encoded as 0x8B, 0x09    00  001 001   Reg. only addr.   CX    [BX+DI]+mov cx,[bx+di] ;0x8B, 0x09    00  001 001   Reg. only addr.   CX    [BX+DI]
 </code> </code>
  
 Now, a few examples of indirect addressing with displacement. Now, a few examples of indirect addressing with displacement.
 <code asm> <code asm>
-                                          MOD REG R/M   MOD              REG  R/M       Disp   +               ;encoding          MOD REG R/M   MOD             REG R/M       Disp   
-mov dx,[bp+62];encoded as 0x8B, 0x56, 0x3E  01  010 110   Reg.+disp addr.  DX   [BP+disp] 0x3E +mov dx,[bp+62] ;0x8B, 0x56, 0x3E  01  010 110   Reg.+disp addr. DX  [BP+disp] 0x3E 
-mov [bp+62],dx;encoded as 0x89, 0x56, 0x3E  01  010 110   Reg.+disp addr.  DX   [BP+disp] 0x3E +mov [bp+62],dx ;0x89, 0x56, 0x3E  01  010 110   Reg.+disp addr. DX  [BP+disp] 0x3E 
-mov dx,[si+13];encoded as 0x8B, 0x54, 0x0D  01  010 100   Reg.+disp addr.  DX   [SI+disp] 0x0D +mov dx,[si+13] ;0x8B, 0x54, 0x0D  01  010 100   Reg.+disp addr. DX  [SI+disp] 0x0D 
-mov si,[bp]   ;encoded as 0x8B, 0x76, 0x00  01  110 110   Reg.+disp addr.  SI   [BP+disp] 0x00+mov si,[bp]    ;0x8B, 0x76, 0x00  01  110 110   Reg.+disp addr. SI  [BP+disp] 0x00
 </code> </code>
-If we look in first two lines, we can observe that the MOD R/M bytes are identical. The only difference is the opcode, which determines the direction of the data transfer.+If we look at the first two lines, we can observe that the MOD R/M bytes are identical. The only difference is the opcode, which determines the direction of the data transfer.
  
 Notice also that the last instruction is encoded as BP + displacement, even if there is no displacement in the mnemonic. If you look into the table {{ref>modrm_16}}, you can observe that there is no addressing mode with [BP] only. It must appear with the displacement. Notice also that the last instruction is encoded as BP + displacement, even if there is no displacement in the mnemonic. If you look into the table {{ref>modrm_16}}, you can observe that there is no addressing mode with [BP] only. It must appear with the displacement.
Line 317: Line 318:
 <code asm> <code asm>
 ;MOD R/M (second byte) is 0x04 for all instructions: ;MOD R/M (second byte) is 0x04 for all instructions:
-                       ;                    MOD REG R/M   REG  MOD & R/M +                     ;                    MOD REG R/M   REG  MOD & R/M 
-                       ;                     00 000 100   eax  SIB is present+                     ;                     00 000 100   eax  SIB is present
  
 ;SIB (third byte) is 0x0B, 0x4B, 0x8B or 0xCB: ;SIB (third byte) is 0x0B, 0x4B, 0x8B or 0xCB:
-                                        Scale Index Base  Scale Index Base +                                     Scale Index Base Scale Index Base 
-mov eax, [ebx+ecx]     ;0x8B, 0x04, 0x0B     00   001  011     x1   ecx  ebx +mov eax, [ebx+ecx]   ;0x8B, 0x04, 0x0B    00   001  011    x1   ecx  ebx 
-mov eax, [ebx+ecx*2]   ;0x8B, 0x04, 0x4B     01   001  011     x2   ecx  ebx +mov eax, [ebx+ecx*2] ;0x8B, 0x04, 0x4B    01   001  011    x2   ecx  ebx 
-mov eax, [ebx+ecx*4]   ;0x8B, 0x04, 0x8B     10   001  011     x4   ecx  ebx +mov eax, [ebx+ecx*4] ;0x8B, 0x04, 0x8B    10   001  011    x4   ecx  ebx 
-mov eax, [ebx+ecx*8]   ;0x8B, 0x04, 0xCB     11   001  011     x8   ecx  ebx+mov eax, [ebx+ecx*8] ;0x8B, 0x04, 0xCB    11   001  011    x8   ecx  ebx
 </code> </code>
  
Line 332: Line 333:
 <code asm> <code asm>
 ;REX prefix (first byte) is 0x48 for all instructions: ;REX prefix (first byte) is 0x48 for all instructions:
-                       ;                                             0 +                     ;                                             0 
-                       ;                 +---+---+---+---+---+---+---+---+ +                     ;                 +---+---+---+---+---+---+---+---+ 
-                       ;                 | 0       0 | W | R | X | B | +                     ;                 | 0       0 | W | R | X | B | 
-                       ;                 +---+---+---+---+---+---+---+---+ +                     ;                 +---+---+---+---+---+---+---+---+ 
-                       ;                                         0+                     ;                                         0
  
 ;MOD R/M (second byte) is 0x04 for all instructions: ;MOD R/M (second byte) is 0x04 for all instructions:
-                       ;                    MOD R.REG R/M   REG  MOD & R/M +                     ;                    MOD R.REG R/M   REG  MOD & R/M 
-                       ;                     00 0.000 100   eax  SIB is present+                     ;                     00 0.000 100   eax  SIB is present
  
-                                              Scale X.Index B.Base  Scale Index Base +                                           Scale X.Index B.Base Scale Index Base 
-mov rax, [rbx+rcx]     ;0x48, 0x8B, 0x04, 0x0B     00   0.001  0.011     x1   rcx  rbx +mov rax, [rbx+rcx]   ;0x48, 0x8B, 0x04, 0x0B    00   0.001  0.011    x1   rcx  rbx 
-mov rax, [rbx+rcx*2]   ;0x48, 0x8B, 0x04, 0x4B     01   0.001  0.011     x2   rcx  rbx +mov rax, [rbx+rcx*2] ;0x48, 0x8B, 0x04, 0x4B    01   0.001  0.011    x2   rcx  rbx 
-mov rax, [rbx+rcx*4]   ;0x48, 0x8B, 0x04, 0x8B     10   0.001  0.011     x4   rcx  rbx +mov rax, [rbx+rcx*4] ;0x48, 0x8B, 0x04, 0x8B    10   0.001  0.011    x4   rcx  rbx 
-mov rax, [rbx+rcx*8]   ;0x48, 0x8B, 0x04, 0xCB     11   0.001  0.011     x8   rcx  rbx+mov rax, [rbx+rcx*8] ;0x48, 0x8B, 0x04, 0xCB    11   0.001  0.011    x8   rcx  rbx
 </code> </code>
  
Line 352: Line 353:
  
 <code asm> <code asm>
-                                              Scale X.Index B.Base  Scale Index Base +                                           Scale X.Index B.Base Scale Index Base 
-mov rax, [r10+rcx]     ;0x49, 0x8B, 0x04, 0x0A     00   0.001  1.010     x1   rcx  r10 +mov rax, [r10+rcx]   ;0x49, 0x8B, 0x04, 0x0A    00   0.001  1.010    x1   rcx  r10 
-mov rax, [rbx+r11]     ;0x4A, 0x8B, 0x04, 0x1B     00   1.001  0.011     x1   r11  rbx +mov rax, [rbx+r11]   ;0x4A, 0x8B, 0x04, 0x1B    00   1.001  0.011    x1   r11  rbx 
-mov r12, [rbx+rcx]     ;0x4C, 0x8B, 0x24, 0x0B     10   0.001  0.011     x1   rcx  rbx+mov r12, [rbx+rcx]   ;0x4C, 0x8B, 0x24, 0x0B    10   0.001  0.011    x1   rcx  rbx
  
-                       ;Last instruction has the MOD R/M REG field extended  +                     ;Last instruction has the MOD R/M REG field extended  
-                       ;by the R bit from the REX prefix. +                     ;by the R bit from the REX prefix. 
-                       ;                    MOD R.REG R/M   REG  MOD & R/M +                     ;                    MOD R.REG R/M   REG  MOD & R/M 
-                       ;                     00 1.100 100   r12  SIB is present+                     ;                     00 1.100 100   r12  SIB is present
 </code> </code>
  
en/multiasm/papc/chapter_6_6.1771525592.txt.gz · Last modified: by ktokarz
CC Attribution-Share Alike 4.0 International
www.chimeric.de Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0