8086 arch-SNK
8086 arch-SNK
B us Interface
ES U n it
CS
SS In stru ctio n
DS q u eu e
IP
SP E xe cutio n
BP
ALU U n it
DI
SI
F lag s
O D I T S Z AF PF CF
CF
Fig, 1.6 Flag Register
Six of the nine flags are used to indicate some condition produced by an instruction. These condition
flags are also called status flags of 8086/8088 microprocessor. These are the Carry flag, Parity flag, Auxiliary
carry flag, Zero flag, and Sign flag. The other three Control flags are Trap Flag, Direction Flag and Interrupt
flag.
Condition Flags
Carry Flag (CF)
This flag will be set to one if the addition of two 16-bit binary numbers produces a carry out of
the most significant bit position or if there is a borrow to the MSB after subtraction. This flag is also
affected when other arithmetic and logical instruction are executed.
Contiguous memory
Segment C
Segment D
Disjoint
Fig 1.7
FFFFFH
B
C
CS
D
DS
E
SS
F
ES
G
H I
00000H
Fig-1.8
Fig 1.8 shows the segment registers pointing to the various memory segments. Since logical addresses
are 16-bits wide, up to 64K (65536) bytes in a given segment can be addressed.
Each time the CPU need to generate a memory address, one of the segment registers is automatically
chosen and its contents added to a logical address.
For an instruction fetch, the code segment register is automatically added to the logical address (in this
case, the contents of the instruction pointer) to compute the value of the instruction address.
For stack referencing the stack segment register is automatically added to the logical address (the SP or
BP register contents) to compute the value of the stack address.
For data reference operations, where either the data or extra segment register is chosen as the base, the
logical address can be made up of many different types of values: it can be simply the immediate data value
contained in the instruction, or it can be the sum of an immediate data value and a base register, plus an index
register. Generally, the selection of the DS or ES register is made automatically, though provisions do exist to
override this selection. Thus any memory location may be addressed without changing the value of the segment
base register. In systems that use 64K or fewer bytes of memory for each memory area (code, stack, data and
extra), the segment registers can be initialized to zero at the beginning of the program and then ignored, since
zero plus a 16-bit offset yields a 16-bit address. In a system where the total amount of memory is 64K bytes or
less, it is possible to set all segments equal and have fully overlapping segments.
Segment registers are also very useful for large programming tasks, which require isolation of program
code from the data area, or isolation of module data from the stack information etc.
Segmentation makes it easy to build re-locatable and reentrant programs. In many cases, the task of
relocating a program (relocation means having the ability to run the same program in several different areas of
memory without changing addresses in the program itself) simply requires moving the program code and then
adjusting the code segment register to point to the base of the new code area. Since programs can be written for
the 8086 / 8088 in which all branches and jumps are relative to the instruction pointer, it does not matter what
value is kept in the code segment register. Every application will define and use segments differently. The
currently addressable segment override provide, a generous workspace: 64K bytes for code, 64K bytes stack
and 128K bytes of data
storage.
Solved Problems
1. If a physical branch address is 5A230 H when (CS) = 5200 H, what will it be if
the (CS) are changed to 7800 H.
CS: 52 0 0
Offset: XXXX
Physical add. 5A2 3 0 H