|
General Instruction Coding +--------+----------+---+-----+-----+---+-----+-----+----------+---------+ | OpCode | [OpCode] |mod|OpCod| r/m |ss |index|base | d32/16/8 | data | +--------+----------+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ or | 32/16/8 | | 7 .. 0 | 7 .... 0 |7|6|5|4|3|2|1|0|7|6|5|4|3|2|1|0| none | or none | +--------+----------+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+----------+---------+ \ / \ / \________/ \_______/ \ / \ / Address Immediate \ / \ / Displacement Data \_____/ \ _______________ / (4,2,1,0) (4,2,1,0) Opcode MODRM (1 or 2 bytes) Field (Register and Address mode Specifier) Encoding of Operand Length (w) Field +----------+-------------------+--------------------+ | | Operand Size | Operand Size | | w Field | during 16-bit | during 32-bit | | | Data Operations | Data Operations | +----------+-------------------+--------------------+ | 0 | 8 bits | 8 bits | | 1 | 16 bits | 32 bits | +----------+-------------------+--------------------+ Encoding of REG Field when 'w' Field is not Present in Instruction +-----------+--------------------+--------------------+ | | Registers Selected | Registers Selected | | reg Field | during 16-bit | during 32-bit | | | Data Operations | Data Operations | +-----------+--------------------+--------------------+ | 000 | AX | EAX | | 001 | CX | ECX | | 010 | DX | EDX | | 011 | BX | EBX | | 100 | SP | ESP | | 101 | BP | EBP | | 110 | SI | ESI | | 111 | DI | EDI | +-----------+--------------------+--------------------+ 16-bit Encoding of REG Field when 'w' Field is Present in Instruction +-----------+-----------------------------------------+ | | Registers Specified by REG field | | reg Field | during 16-bit Data Operations | | | w = 0 w = 1 | +-----------+--------------------+--------------------+ | 000 | AL | AX | | 001 | CL | CX | | 010 | DL | DX | | 011 | BL | BX | | 100 | AH | SP | | 101 | CH | BP | | 110 | DH | SI | | 111 | BH | DI | +-----------+--------------------+--------------------+ 32-bit Encoding of REG Field when 'w' Field is Present in Instruction +-----------+-----------------------------------------+ | | Registers Specified by REG field | | reg Field | during 32-bit Data Operations | | | w = 0 w = 1 | +-----------+--------------------+--------------------+ | 000 | AL | EAX | | 001 | CL | ECX | | 010 | DL | EDX | | 011 | BL | EBX | | 100 | AH | ESP | | 101 | CH | EBP | | 110 | DH | ESI | | 111 | BH | EDI | +-----------+--------------------+--------------------+ Encoding of the 2-bit Segment Register (sreg) Field +-------------+----------------+ | 2-bit | Segment | | sreg | Register | | Field | Selected | +-------------+----------------+ | 00 | ES | | 01 | CS | | 10 | SS | | 11 | DS | +-------------+----------------+ Encoding of the 3-bit Segment Register (sreg) Field +-------------+----------------+ | 3-bit | Segment | | sreg | Register | | Field | Selected | +-------------+----------------+ | 000 | ES | | 001 | CS | | 010 | SS | | 011 | DS | | 100 | FS | | 101 | GS | | 110 | do not use | | 111 | do not use | +-------------+----------------+ Encoding of 16-bit Address Mode +----------+------------------------+----------+------------------------+ | MODRM | Effective Address | MODRM | Effective Address | +----------+------------------------+----------+------------------------+ | 00 000 | DS:[BX+SI] | 10 00 0 | DS:[BX+SI+d16] | | 00 001 | DS:[BX+DI] | 10 00 1 | DS:[BX+DI+d16] | | 00 010 | SS:[BP+SI] | 10 01 0 | SS:[BP+SI+d16] | | 00 011 | SS:[BP+DI] | 10 01 1 | SS:[BP+DI+d16] | | 00 100 | DS:[SI] | 10 10 0 | DS:[SI+d16] | | 00 101 | DS:[DI] | 10 10 1 | DS:[DI+d16] | | 00 110 | DS:d16 | 10 11 0 | SS:[BP+d16] | | 00 111 | DS:[BX] | 10 11 1 | DS:[BX+d16] | +----------+------------------------+----------+------------------------+ Encoding of 16-bit Address Mode Continued +----------+------------------------+----------+------------------------+ | MODRM | Effective Address | MODRM | Effective Address | +----------+------------------------+----------+------------------------+ | 01 000 | DS:[BX+SI+d8] | 11 00 0 | register - see below | | 01 001 | DS:[BX+DI+d8] | 11 00 1 | register - see below | | 01 010 | SS:[BP+SI+d8] | 11 01 0 | register - see below | | 01 011 | SS:[BP+DI+d8] | 11 01 1 | register - see below | | 01 100 | DS:[SI+d8] | 11 10 0 | register - see below | | 01 101 | DS:[DI+d8] | 11 10 1 | register - see below | | 01 110 | SS:[BP+d8] | 11 11 0 | register - see below | | 01 111 | DS:[BX+d8] | 11 11 1 | register - see below | +----------+------------------------+----------+------------------------+ +------------+-----------------------------------------+ | | Registers Specified by R/M field | | | during 16-bit Data Operations | | MODRM | w = 0 w = 1 | +------------+--------------------+--------------------+ | 11 000 | AL | AX | | 11 001 | CL | CX | | 11 010 | DL | DX | | 11 011 | BL | BX | | 11 100 | AH | SP | | 11 101 | CH | BP | | 11 110 | DH | SI | | 11 111 | BH | DI | +------------+--------------------+--------------------+ +------------+-----------------------------------------+ | | Registers Specified by R/M field | | | during 32-bit Data Operations | | MODRM | w = 0 w = 1 | +------------+--------------------+--------------------+ | 11 000 | AL | EAX | | 11 001 | CL | ECX | | 11 010 | DL | EDX | | 11 011 | BL | EBX | | 11 100 | AH | ESP | | 11 101 | CH | EBP | | 11 110 | DH | ESI | | 11 111 | BH | EDI | +------------+--------------------+--------------------+ Encoding of 32-bit Address Mode with 1-byte MODRM Field +----------+------------------------+----------+------------------------+ | MODRM | Effective Address | MODRM | Effective Address | +----------+------------------------+----------+------------------------+ | 00 000 | DS:[EAX] | 10 00 0 | DS:[EAX+d32] | | 00 001 | DS:[ECX] | 10 00 1 | DS:[ECX+d32] | | 00 010 | SS:[EDX] | 10 01 0 | SS:[EDX+d32] | | 00 011 | SS:[EBX] | 10 01 1 | SS:[EBX+d32] | | 00 100 | escape to 2-byte | 10 10 0 | escape to 2-byte | | 00 101 | DS:d32 | 10 10 1 | SS:[EBP+d32] | | 00 110 | DS:[ESI] | 10 11 0 | DS:[ESI+d32] | | 00 111 | DS:[EDI] | 10 11 1 | DS:[EDI+d32] | +----------+------------------------+----------+------------------------+ Encoding of 32-bit Address Mode with 1-byte MODRM Field Continued +----------+------------------------+----------+------------------------+ | MODRM | Effective Address | MODRM | Effective Address | +----------+------------------------+----------+------------------------+ | 01 000 | DS:[EAX+d8] | 11 00 0 | register - see below | | 01 001 | DS:[ECX+d8] | 11 00 1 | register - see below | | 01 010 | SS:[EDX+d8] | 11 01 0 | register - see below | | 01 011 | SS:[EBX+d8] | 11 01 1 | register - see below | | 01 100 | escape to 2-byte | 11 10 0 | register - see below | | 01 101 | SS:[EBP+d8] | 11 10 1 | register - see below | | 01 110 | DS:[ESI+d8] | 11 11 0 | register - see below | | 01 111 | DS:[EDI+d8] | 11 11 1 | register - see below | +----------+------------------------+----------+------------------------+ +------------+-----------------------------------------------+ | | Registers Specified by REG or R/M field | | | during 16-bit Data Operations | | MODRM | w = 0 w = 1 | +------------+-----------------------+-----------------------+ | 11 000 | AL | AX | | 11 001 | CL | CX | | 11 010 | DL | DX | | 11 011 | BL | BX | | 11 100 | AH | SP | | 11 101 | CH | BP | | 11 110 | DH | SI | | 11 111 | BH | DI | +------------+-----------------------+-----------------------+ +------------+-----------------------------------------------+ | | Registers Specified by REG or R/M field | | | during 32-bit Data Operations | | MODRM | w = 0 w = 1 | +------------+-----------------------+-----------------------+ | 11 000 | AL | EAX | | 11 001 | CL | ECX | | 11 010 | DL | EDX | | 11 011 | BL | EBX | | 11 100 | AH | ESP | | 11 101 | CH | EBP | | 11 110 | DH | ESI | | 11 111 | BH | EDI | +------------+-----------------------+-----------------------+ Encoding of 32-bit Address Mode with 2-byte MODRM Field +----------+------------------------+----------+------------------------+ | MODRM | Effective Address | MODRM | Effective Address | +----------+------------------------+----------+------------------------+ | 00 000 | DS:[EAX+index] | 10 00 0 | DS:[EAX+index+d32] | | 00 001 | DS:[ECX+index] | 10 00 1 | DS:[ECX+index+d32] | | 00 010 | SS:[EDX+index] | 10 01 0 | SS:[EDX+index+d32] | | 00 011 | SS:[EBX+index] | 10 01 1 | SS:[EBX+index+d32] | | 00 100 | SS:[ESP+index] | 10 10 0 | SS:[ESP+index+d32] | | 00 101 | DS:[d32+index] | 10 10 1 | SS:[EBP+index+d32] | | 00 110 | DS:[ESI+index] | 10 11 0 | DS:[ESI+index+d32] | | 00 111 | DS:[EDI+index] | 10 11 1 | DS:[EDI+index+d32] | +----------+------------------------+----------+------------------------+ Encoding of 32-bit Address Mode with 2-byte MODRM Field Continued +----------+------------------------+-----------------------------------+ | MODRM | Effective Address | SS (Scale Factor) | +----------+------------------------+-----------------------------------+ | 01 000 | DS:[EAX+index+d8] | 00=X1 01=X2 10=X4 11=X8 | | 01 001 | DS:[ECX+index+d8] +-----------------------------------+ | 01 010 | SS:[EDX+index+d8] | INDEX (Index Register) | | 01 011 | SS:[EBX+index+d8] +-----------------------------------+ | 01 100 | SS:[ESP+index+d8] | 000=EAX 100=No Reg(SS=0)| | 01 101 | SS:[EBP+index+d8] | 001=ECX 101=EBP | | 01 110 | DS:[ESI+index+d8] | 010=EDX 110=ESI | | 01 111 | DS:[EDI+index+d8] | 011=EBX 111=EDI | +----------+------------------------+-----------------------------------+ Encoding of Operation Direction (d) Field +---+---------------------------------------------------------------+ | 0 | Register / Memory <-- Register | | | 'REG' field indicates source operand. | | | 'MODRM' or 'MOD SS INDEX BASE' indicates destination operand. | +---+---------------------------------------------------------------+ | 1 | Register <-- Register / Memory | | | 'REG' field indicates destination operand. | | | 'MODRM' or 'MOD SS INDEX BASE' indicates source operand. | +---+---------------------------------------------------------------+ Encoding of Sign-Extend (s) Field +-----+--------------------------------------+--------------------------+ | | Effect on | Effect on | | s | Immediate Data 8 | Immediate Data 16/32 | +-----+--------------------------------------+--------------------------+ | 0 | None | None | +-----+--------------------------------------+--------------------------+ | 1 | Sign-Extend Data8 to fill 16-bit | None | | | or 32-bit destination. | | +-----+--------------------------------------+--------------------------+ Encoding of Control or Debug Register (eee) Field +---------------------+---------------------+---------------------+ | Control Register | Debug Register | Test Register | +----------+----------+----------+----------+----------+----------+ | eee Code | Register | eee Code | Register | eee Code | Register | +----------+----------+----------+----------+----------+----------+ | 000 | CR0 | 000 | DR0 | 110 | TR6 | | 010 | CR2 | 001 | DR1 | 111 | TR7 | | 011 | CR3 | 010 | DR2 | | | | 011 | DR3 | 011 | DR3 | | | | | | 110 | DR6 | | | | | | 111 | DR7 | | | +----------+----------+----------+----------+----------+----------+ Encoding of Conditional Test Field +----------------+----------------------------------------+------------+ | Mnemonic | Condition | tttn | | O | Overflow | 0000 | | NO | No Overflow | 0001 | | B/NAE | Below / Not Above or Equal | 0010 | | NB/AE | Not Below / Above or Equal | 0011 | | E/Z | Equal / Zero | 0100 | | NE/NZ | Not Equal / Not Zero | 0101 | | BE/NA | Below or Equal / Not Above | 0110 | | NBE/A | Not Below or Equal / Above | 0111 | | S | Sign | 1000 | | NS | Not Sign | 1001 | | P/PE | Parity / Parity Even | 1010 | | NP/PO | No Parity / Parity Odd | 1011 | | L/NGE | Less Than / Not Greater or Equal | 1100 | | NL/GE | Not Less / Greater or Equal | 1101 | | LE/NG | Less or Equal / Not Greater Than | 1110 | | NLE/G | Not Less or Equal / Greater Than | 1111 | +----------------+----------------------------------------+------------+ |
|