| 1. |
MOD (2 bits) Interpretation |
|
Answer» MOD (2 bits) Interpretation : 00 Memory mode with no displacement follows except for 16 bit displacement when R/M=110 01 Memory mode with 8 bit displacement 10 Memory mode with 16 bit displacement 11 Register mode (no displacement) Register field occupies 3 bits. It defines the register for the first operand which is specified as source or destination by the D bit. Byte 1 Byte 2 OR Register Operand/Register to use EA Calculation Register Operand/Extension of opcode Register mode/Memory mode with displacement length Word/byte operation Direction is to register/from register Operation code DIRECT ADDRESS LOW BYTE DIRECT ADDRESS HIGH BYTE 24 REG 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 The R/M field occupies 3 bits. The R/M field along with the MOD field defines the second operand as shown below. MOD 11 R/M 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 Effective Address Calculation R/M MOD=00 MOD 01 MOD 10 000 (BX) + (SI) (BX)+(SI)+D8 (BX)+(SI)+D16 001 (BX)+(DI) (BX)+(DI)+D8 (BX)+(DI)+D16 010 (BP)+(SI) (BP)+(SI)+D8 (BP)+(SI)+D16 011 (BP)+(DI) (BP)+(DI)+D8 (BP)+(DI)+D10 100 (SI) (SI) + D8 (SI) + D16 101 (DI) (DI) + D8 (DI) + D16 110 Direct address (BP) + D8 (BP) + D16 111 (BX) (BX) + D8 (BX) + D16 In the above, encoding of the R/M field depends on how the mode field is set. If MOD=11 (register to register mode), this R/M identifies the second register operand. MOD selects memory mode, then R/M indicates how the effective address of the memory operand is to be calculated. Bytes 3 through 6 of an instruction are optional fields that normally contain the displacement value of a memory operand and / or the actual value of an immediate constant operand. Example 1 : MOV CH, BL This instruction transfers 8 bit content of BL 25 Into CH The 6 bit Opcode for this instruction is 1000102 D bit indicates whether the register specified by the REG field of byte 2 is a source or destination operand. D=0 indicates BL is a source operand. W=0 byte operation In byte 2, since the second operand is a register MOD field is 11 The R/M field = 101 (CH) Register (REG) field = 011 (BL) Hence the machine code for MOV CH, BL is 10001000 11 011 101 Byte 1 Byte2 = 88DD16 Example 2 : SUB Bx, (DI) This instruction subtracts the 16 bit content of memory location addressed by DI and DS from Bx. The 6 bit Opcode for SUB is 001010 D=1 so that REG field of byte 2 is the destination operand. W=1 indicates 16 bit operation. MOD = 00 REG = 011 R/M = 101 The machine code is 0010 1011 0001 1101 2 B 1 D 2B1D16 Summary of all Addressing Modes Example 3 : Code for MOV 1234 (BP), DX Here we have specify DX using REG field, the D bit must be 0, indicating the DX is the source register. The REG field must be 010 to indicate DX register. The W bit must be 1 to indicate it is a word operation. 1234 [BP] is specified using MOD value of 10 and R/M value of 110 and a displacement of 1234H. The 4 byte code for this instruction would be 89 96 34 12H. MOD / R/M Memory Mode (EA Calculation) Register Mode 00 01 10 W=0 W=1 000 (BX)+(SI) (BX)+(SI)+d8 (BX)+(SI)+d16 AL AX 001 (BX) + (DI) (BX)+(DI)+d8 (BX)+(DI)+d16 CL CX 010 (BP)+(SI) (BP)+(SI)+d8 (BP)+(SI)+d16 DL DX 011 (BP)+(DI) (BP)+(DI)+d8 (BP)+(DI)+d16 BL BX 100 (SI) (SI) + d8 (SI) + d16 AH SP 101 (DI) (DI) + d8 (DI) + d16 CH BP 110 d16 (BP) + d8 (BP) + d16 DH SI 111 (BX) (BX) + d8 (BX) + d16 BH DI 26 Opcode D W MOD REG R/M LB displacement HB displacement 100010 0 1 10 010 110 34H 12H Example 4 :Code for MOV DS : 2345 [BP], DX Here we have to specify DX using REG field. The D bit must be o, indicating that Dx is the source register. The REG field must be 010 to indicate DX register. The w bit must be 1 to indicate it is a word operation. 2345 [BP] is specified with MOD=10 and R/M = 110 and displacement = 2345 H. Whenever BP is used to generate the Effective Address (EA), the default segment would be SS. In this example, we want the segment register to be DS, we have to provide the segment override prefix byte (SOP byte) to start with. The SOP byte is 001 SR 110, where SR value is provided as per table shown below. |
|