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

Tutorial 3

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)
8 views

Tutorial 3

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/ 16

MPI Tutorial-3

30.01.2024
31.01.2024
01.02.2024
05.02.2024
Contents

• Physical Address Calculation


• Interpretation of Flags

ELECTRICAL ELECTRONICS COMMUNICATION INSTRUMENTATION


Physical Address Calculation
Problem 1

Contents of the segment registers are as follows:


CS = 1111H, DS = 3333H, SS = 2526H.

Additionally, we have
IP = 1232H, SP = 1100H, offset in DS = 0020H.

Calculate the corresponding physical addresses for the byte being


addressed in: (a) CS, (b) SS, and, (c) DS.

ELECTRICAL ELECTRONICS COMMUNICATION INSTRUMENTATION


Physical Address Calculations
(a)
CS = 1111H; Base address of CS = 11110H
The address of the next instruction to be executed is referenced by CS:IP,
which is given by (11110H +1232H) = 12342H.

(b)
The current top of the stack is referenced by SS:SP. The base address of the
stack segment is 25260H. Therefore, the corresponding physical address is
(25260H + 1100H) = 26360H.

(c)
The data that needs to be accessed from DS is given by DS and the
specified offset. The base address of the DS is 33330H. The physical
address of this data byte is calculated as (33330H + 0020H) = 33350H. 4

ELECTRICAL ELECTRONICS COMMUNICATION INSTRUMENTATION


Physical Address Calculation
Problem 2
Consider the contents of various registers to be
DS = 1112H, AX = EE78H and BX = 3400H.

Also, suppose the following instructions are executed separately.


a) MOV [0422H], AL
b) MOV [0424H], AX
c) MOV [BX], AX

What will be the contents of the appropriate memory locations?

ELECTRICAL ELECTRONICS COMMUNICATION INSTRUMENTATION


Physical Address Calculations
a) The destination is a memory location, which is specified directly in
the instruction.
AL contains 78H and DS = 1112H
Data segment base address is 11120H
The offset in the instruction is 0422H
Physical address is 11120H + 00422H = 11542H
Contents of the memory addressed 11542H will be 78H

b) The physical address is calculated as 11120H + 0424H = 15344H

However, since AX contains two bytes of data, the lower byte (78H) is
stored in the address 15344H and the higher byte (EEH) in the next
address (recollect the ‘little endian’ concept)
6

ELECTRICAL ELECTRONICS COMMUNICATION INSTRUMENTATION


Physical Address Calculations
c)

BX is a pointer to the address 3400H, which is an offset. The


corresponding physical address is (11120H + 03400H) = 14520H

The lower byte (78H) is stored in the address 14520H and the higher
byte (EEH) in the next address.

ELECTRICAL ELECTRONICS COMMUNICATION INSTRUMENTATION


Physical Address Calculations
c)

BX is a pointer to the address 3400H, which is an offset. The


corresponding physical address is (11120H + 03400H) = 14520H

The lower byte (78H) is stored in the address 14520H and the higher
byte (EEH) in the next address.

ELECTRICAL ELECTRONICS COMMUNICATION INSTRUMENTATION


Physical Address Calculation
Problem 3
If SS = 2000, SP = 4578, find:

a) The physical address


b) The logical address
c) The lower range of the SS
d) The upper range of the SS

ELECTRICAL ELECTRONICS COMMUNICATION INSTRUMENTATION


Physical Address Calculations
a) The physical address will be (20000H + 4578H) = 24578H.
b) The logical address will be 2000H:4578H
c) The lower range will be 20000H
d) The upper range will be (20000H+FFFFH) = 2FFFFH

Key Concept: How is 64 kB represented as FFFFH in the address?


64 kB = (64  1024) bytes = 65,536 bytes = 67108864 bits

Let the starting location address be 0 H and each memory location can
hold 8 bits of data.
Thus, to hold 67108864 bits of data, we would require 65,536 locations
indexing from 0 to 65,535. Converting 65,535d = FFFFH.

Hence the final address offset will be FFFFH. 10

ELECTRICAL ELECTRONICS COMMUNICATION INSTRUMENTATION


Flags
Problem 4
Find the status of CF, PF, AF, ZF, and SF for the following
operations:

(a)MOV BL,9FH
ADD BL,61H

(b)MOV DX,10FFH
ADD DX,1

11

ELECTRICAL ELECTRONICS COMMUNICATION INSTRUMENTATION


Flags
(a) Solution

MOV BL,9FH (BL  9FH)


ADD BL,61H (BL  9FH+61H)

9FH+61H = 100H

Flags condition after each instruction:


MOV BL, 9FH; CF = 0, PF = 0, AF = 0, ZF = 0, SF = 0
ADD BL, 61H; CF = 1, PF = 1, AF = 1, ZF = 1, SF = 0

Interpretation:

CF = 1 indicating a carry occurred; PF = 1 indicating even parity; AF = 1 indicating a carry


from bit 3; ZF = 1 indicating the result is zero; SF = 0 indicating a positive result.
12

ELECTRICAL ELECTRONICS COMMUNICATION INSTRUMENTATION


Flags
(b) Solution

MOV DX,10FFH (DX  10FFH; DH = 10H; DL = FFH)


ADD DX,1 (DX  10FFH+1)

10FFH+1 = 1100H

Flags condition after each instruction:


MOV DX,10FFH; CF = 0, PF = 0, AF = 0, ZF = 0, SF = 0
ADD DX,1; CF = 0, PF = 1, AF = 1, ZF = 0, SF = 0

Interpretation:

CF = 0 indicating no carry; PF = 1 indicating even parity; AF = 1 indicating a carry from


bit 3; ZF = 0 indicating the result is not zero; SF = 0 indicating positive result.
13

ELECTRICAL ELECTRONICS COMMUNICATION INSTRUMENTATION


Flags
Problem 5
Show how the flag register is affected by for the following
program:

MOV AX,94C2H
MOV BX,323EH
ADD AX,BX
MOV DX,AX
MOV CX,DX

14

ELECTRICAL ELECTRONICS COMMUNICATION INSTRUMENTATION


Flags
Solution
A key concept for PF in 8086 flags
After certain operations, the parity of the lower-order byte is checked.
If the byte has an even number of 1s, then PF is set to 1; otherwise, it
is cleared.

15

ELECTRICAL ELECTRONICS COMMUNICATION INSTRUMENTATION


Flags
Solution
MOV AX,94C2H; AX  94C2H
MOV BX,323EH; BX  323EH
ADD AX,BX; AX  (94C2+323E) = C700H
MOV DX,AX; DX  C700H
94C2 1001 0100 1100 0010
MOV CX,DX; CX  C700H
323E 0011 0010 0011 1110

C700 1100 0111 0000 0000

Flags condition after add instruction:


CF = 0, PF = 1, AF = 1, ZF = 0, SF = 1
Interpretation:

CF = 0, indicating no carry beyond bit 15; PF = 1, indicating even numbers of 1s in the


lower byte; AF = 1, indicating a carry from bit 3 to bit 4; ZF = 0, indicating the result is not
zero; SF = 1, since bit 15 of the result is 1. 16

ELECTRICAL ELECTRONICS COMMUNICATION INSTRUMENTATION

You might also like