0% found this document useful (0 votes)
16 views

Tutorial 4

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views

Tutorial 4

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 19

MPI Tutorial-4

06.02.2024
07.02.2024
08.02.2024
12.02.2024
Contents

• Addressing Modes
• Machine Code Formation
• Machine Code Formation with for Segment
Override Prefix

ELECTRICAL ELECTRONICS COMMUNICATION INSTRUMENTATION


Addressing Modes
Problem 1
Find the addressing modes of the following instructions:

a. MOV CX,DX
b. MOV BX,1234
c. MOV AX,[SI]
d. MOV [offset address], 2345
e. MOV CX, [BX+SI]
f. MOV CX,[BX+SI+1234]

ELECTRICAL ELECTRONICS COMMUNICATION INSTRUMENTATION


Addressing Modes
Solution 1
The addressing modes of the given instruction can be obtained by careful observation of the
source and destination operands.

Sl. No. Instruction Addressing Modes

a MOV CX,DX Register

b MOV BX,1234 Immediate

c MOV AX,[SI] Indexed/Register Indirect

d MOV [offset address], 2345 Immediate

e MOV CX,[BX+SI] Based Indexed

f MOV CX,[BX+SI+1234] Relative Base Indexed

ELECTRICAL ELECTRONICS COMMUNICATION INSTRUMENTATION


Addressing Modes
Problem 2
The contents of different registers are AX = 1000H, BX = 2000H, SI = 3000H, DI = 4000H,
BP = 5000H, SP = 6000H, CS = 8000H, DS = 1000H, SS = 2000H, IP = 7000H:

Determine the 16-bit effective addresses (EA) and 20-bit physical address (PA) for the
following addressing modes:

a. Direct addressing MOV AX, CS:[0100H]


b. Register indirect addressing with CS as segment override prefix MOV AX, CS:[BX]
c. Based indexed addressing with DS as segment override prefix MOV AX, DS:[BX + SI]
d. Based Indexed with displacement addressing MOV AX, DS:[BX + SI + DISP]

Assume offset or displacement is 0500H and for direct addressing consider the location offset
to be 0100H.

ELECTRICAL ELECTRONICS COMMUNICATION INSTRUMENTATION


Addressing Modes
Solution 2
Direct addressing mode
MOV AX, [0100H] is an example of direct addressing mode instruction. The 16-bit EA = 0100
and 20-bit PA= CS × 10 + 0100 = 8000 × 10 + 0100 = 80100H
Register indirect addressing
MOV AX, CS:[BX] is an example of register indirect addressing mode instruction. The 16-bit EA
is the content of BX register = 2000H and 20-bit PA= CS × 10 + BX = 8000 × 10 + 2000 =
82000H
Based indexed addressing
MOV AX, DS:[BX + SI] is an example of base indexed addressing mode instruction. The 16-bit
EA is the content of BX plus SI register = BX + SI = 2000 + 3000 = 5000H and 20-bit PA = DS ×
10 + BX + SI = 1000 × 10 + 2000 + 3000 = 15000H

Based indexed with displacement addressing


MOV AX, DS:[BX + SI + DISP] is an example of base indexed addressing mode instruction. The
20-bit PA = DS × 10 + BX + SI + DISP
= 1000 × 10H + 2000H + 3000H + 500H = 15500H 6

ELECTRICAL ELECTRONICS COMMUNICATION INSTRUMENTATION


General Format of the first three bytes of an Instruction

This is an optional byte and need to be used only to


change the operation, e.g. segment override prefix.

This is considered to be the first byte of an


instruction. In this byte, there is the operation code
(opcode) which is 6 bits long. This is the code
which defines the operation to be carried out.
The other two bits are the D and W bits.
W (1-bit) – operand size. W = 1, means word
operand; W = 0, means byte operand.
D (1-bit) – Direction bit. D = 1, means register is
destination; D = 0, means register is source.

MOD (2-bit) – Addressing Mode bits


REG (3-bit) – the identifying code of the register used.
R/M (3 bits) – Specifying a register or memory operand.
The MOD and R/M bits together specify the addressing
mode of the instruction.

Note: All instructions need not have the W and D bits. In such cases, the size of the operand is implicit, and
the direction is irrelevant.

ELECTRICAL ELECTRONICS COMMUNICATION INSTRUMENTATION


Codes for Segment Registers

Note: The segment override prefix is a byte with


the format 001XX110. In place of XX, the code
of the segment register which overrides the
default segment has to be inserted.

ELECTRICAL ELECTRONICS COMMUNICATION INSTRUMENTATION


Codes for REG Field

ELECTRICAL ELECTRONICS COMMUNICATION INSTRUMENTATION


Codes for MOD and R/M fields

ELECTRICAL ELECTRONICS COMMUNICATION INSTRUMENTATION


Instruction Encoding
Problem 3
Find the machine code for the following instructions:

a. MOV AX,BX
b. MOV BX,1234H
c. MOV AX,[SI]
d. MOV ES,AX

11

ELECTRICAL ELECTRONICS COMMUNICATION INSTRUMENTATION


Instruction Encoding
Solution 3 (a)

MOV AX, BX

So, the data movement is between two registers. As per the instruction encoding format,

d = 1, r/m → reg
w = 1 for 16-bit data
MOD = 11 for register movements
Destination: AX, reg = 000
Source: BX, r/m = 011

Hence, the complete machine code should be: 1000 1011 1100 0011 (8B C3 H)

Go to Tables 12

ELECTRICAL ELECTRONICS COMMUNICATION INSTRUMENTATION


Instruction Encoding
Solution 3 (b)

MOV BX,1234H

The instruction has an immediate field. As per the instruction encoding format,

w = 1 for 16-bit data


Destination: BX, reg = 011
Data (low) = 34 H
Data (high) = 12 H

Hence, the complete machine code should be: 1011 1011 00110100 00010010 (BB 34 12 H)

Go to Tables 13

ELECTRICAL ELECTRONICS COMMUNICATION INSTRUMENTATION


Instruction Encoding
Solution 3 (c)

MOV AX,[SI]

The instruction has an immediate field. As per the instruction encoding format,

d = 1, r/m → reg
w = 1 for 16-bit data
MOD = 00 for no displacement
Destination: AX, reg = 000
Source: [SI], r/m = 100

Hence, the complete machine code should be: 1000 1011 0000 0100 (8B 04 H)

Go to Tables 14

ELECTRICAL ELECTRONICS COMMUNICATION INSTRUMENTATION


Instruction Encoding
Solution 3 (d)

MOV ES,AX

The instruction has an data transfer between accumulator to segment register. As per the
instruction encoding format,

MOD = 11 for register data movement (predefined)


Destination: ES, reg = 000
Source: AX, r/m = 000

Hence, the complete machine code should be: 1000 1110 1100 0000 (8E C0 H)

Go to Tables 15

ELECTRICAL ELECTRONICS COMMUNICATION INSTRUMENTATION


Instruction Encoding
Problem 4
Find the machine code for the following instructions:

a. MOV DS:43D[BP],CX
b. MOV CS:[BX],DH

16

ELECTRICAL ELECTRONICS COMMUNICATION INSTRUMENTATION


Instruction Encoding
Solution 4(a)

MOV DS:43D[BP],CX

d = 0, reg → r/m
w = 1 for 16-bit data operation.
Source: CX, reg = 001
Destination: DS: 43[BP]
Except the segment override, the destination is DS:[BP], which is the memory location with 8-bit
displacement, hence mod = 01 with r/m = 110
8-bit Displacement = 43D = 2B H

The bit pattern for the segment override prefix is 001SR110


As segment override prefix is selected for DS hence, SR becomes 11.

Thus, the complete machine code becomes: 0011 1110 1000 1001 0100 1110 0010 1011(3E 89 4E 2B H)

Go to Tables 17

ELECTRICAL ELECTRONICS COMMUNICATION INSTRUMENTATION


Instruction Encoding
Solution 4(b)

MOV CS:[BX],DH

d = 0, reg → r/m
w = 0 for 8-bit data operation.
Source: DH, reg = 110
Destination: CS: [BX]
Except the segment override, the destination is CS:[BX], which is the memory location with 0-
bit displacement, hence mod = 00 with r/m = 111

The bit pattern for the segment override prefix is 001SR110


As segment override prefix is selected for CS hence, SR becomes 01.

Thus the complete machine code becomes: 0010 1110 1000 1000 0011 0111 (2E 88 37 H)

Go to Tables 18

ELECTRICAL ELECTRONICS COMMUNICATION INSTRUMENTATION


Instruction Encoding
Important Tables

19

ELECTRICAL ELECTRONICS COMMUNICATION INSTRUMENTATION

You might also like