UNIT 2. Instruction Format
UNIT 2. Instruction Format
The OP code field occupies 6-bits.It defines the operation to be carried out by the instruction.
Register Direct bit (D) occupies one bit. It defines whether the register operand in byte 2 is the
source or destination operand.
D=1 Specifies that the register operand is the destination operand.
D=0 indicates that the register is a source operand.
Data size bit (W) defines whether the operation to be performed is an 8 bit or 16 bit data
Byte 1 Byte 2 OR
DIRECT DIRECT
ADDRESS LOW ADDRESS HIGH
BYTE BYTE
Register field occupies 3 bits. It defines the register for the first operand which is specified as
source or destination by the D bit.
Register Codes:
8086 INSTRUCTION FORMATS 2
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
8086 INSTRUCTION FORMATS 3
normally contain the displacement value of a memory operand and / or the actual value
of an immediate constant operand.
Obtain the opcodes for the following instructions.
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
8086 INSTRUCTION FORMATS 4
segment override prefix byte (SOP byte) to start with. The SOP byte is 001 xx 110, where
SR value is provided as per table shown below.
xx Segment register
00 ES
01 CS
10 SS
11 DS
To specify DS register, the SOP byte would be 001 11 110 = 3E H. Thus the 5 byte code for this
instruction would be 3E 89 96 45 23 H.
SOP Opcode D W MOD REG R/M LB disp. HD disp.
3EH 1000 10 0 1 10 010 110 45 23
Suppose we want to code MOV SS : 2345 (BP), DX. This generates only a 4 byte code, without
SOP byte, as SS is already the default segment register in this case.
Example 5:
Give the instruction template and generate code for the instruction ADD 0FABE [BX], [DI],
DX (code for ADD instruction is 000000)
Example 6 :
Give the instruction template and generate the code for the instruction MOV AX, [BX]
(Code for MOV instruction is 100010)
AX destination register with D=1 and code for AX is 000 [BX] is specified using 00 Mode
and R/M value 111. It is a word operation
INPUT/OUTPUT INSTRUCTIONS:
IN acc, port : In transfers a byte or a word from input port to the AL register or the AX
register respectively. The port number my be specified either with an immediate byte
constant, allowing access to ports numbered 0 through 255 or with a number previously
placed in the DX register allowing variable access (by changing the value in DX) to ports
numbered from 0 through 65,535.
In Operands Example
acc, immB IN AL, 0E2H (OR) IN AX, PORT
acc, DX IN AX, DX (OR) IN AL, DX
8086 INSTRUCTION FORMATS 5
OUT port, acc : Out transfers a byte or a word from the AL register or the AX register
respectively to an output port. The port numbers may be specified either with an
immediate byte or with a number previously placed in the register DX allowing variable
access.