College of Computer Technology
Department of Software
Class: 2stage / / Lec.6
Thur. 9-12-2010
Shaymaa A.M. Al-Garawi

Features of 8086 ( continued)

- 8086 has 16 bit registers

- 8086 has multiplexed address & data bus

- 8086 operates in 2 modes , minimum( single processor )

& maximum (multi processor) modes

Architecture (continued)

The 8086 has two parts, the Bus Interface Unit (BIU) and the Execution Unit (EU).

 The BIU fetches instructions, reads and writes data, and computes the 20-bit address

 The EU decodes and executes the instructions using the 16-bit ALU.

The EU contains many registers, the following 16-bit General Purpose Registers:

AX - the Accumulator

BX - the Base Register

CX - the Count Register

DX - the Data Register

SP - the Stack Pointer

BP - the Base Pointer

SI - the Source Index Register

DI - the Destination Register

General purpose Registers

AX

Accumulator Register

Preferred register to use in arithmetic, logic and data transfer instructions because it generates the shortest Machine Language Code

Must be used in multiplication and division operations

Must also be used in I/O operations

BX

Base Register

Also serves as an address register

Used in array operations

CX

Count register

Used as a loop counter

Used in shift and rotate operations

DX

Data register

Used in multiplication and division

Also used in I/O operations

Tafe.AL-Solteany

Segment Registers in 8086

There are four segment registers in the 8086 processor, CS , DS , ES , and SS , also known as Code Segment , Data Segment , Extra Segment , and Stack Segment.

Any time an address is generated by the processor, it is added to the

value of one of the segment registers. In order to generate the physical address that accesses memory.

This gives an effective address range of 20 bits, or 1MB, but note that only 64kb is addressable through any segment register at one time, unless you stop to change the contents of that segment register.

Code Segment(CS)

In computing, a code segment, also known as a text segment or simply as text, is a phrase used to refer to a portion of memory or of an object file that contains executable instructions. It has a fixed size and is usually read-only.

CS - points at the segment containing the current program. CS- is a 16-bit register containing address of 64 KB segment with processor instructions .CS register cannot be changed directly. The CS register is automatically updated. Used for access to program code.

Data segment

A data segment is one of the sections of a program in an object file or in memory,

which contains the global variables and static variables that are initialized by the programmer. DS- is a 16-bit register containing address of 64 KB segment with processor instructions .It has a fixed size, it is not read-only. (DS) register is used for access to data.

Stack register

The stack register contains the address of the last item pushed on the stack. The stack is a region of memory used for temporary storage of instruction addresses and register values in a Last-In-First-Out. SS- is a 16-bit register containing address of 64 KB segment with processor instructions.

The stack is where the 8086 stores important machine state information, subroutine return addresses

Extra segment

ES- is a 16-bit register containing address of 64 KB segment with processor instructions.

Use this segment register to access to segments when it is difficult or impossible to change the other segment registers.

Presented by: Ghaith Faisal Ali

Pointer And Index Registers

 used to keep offset addresses.

 Used in various forms of memory addressing.

 In the case of SP and BP the default reference to form a physical address is the Stack

 The index registers (SI & Di) and the BX generally default to the Data

segment register(DS).

• SP: Stack pointer

– Used with SS to access the stack segment

• BP: Base Pointer

– Primarily used to access data on the stack

–Can be used to access data in other segments

• SI: Source Index register

– is required for some string operations

– When string operations are performed, the SI register points to

memory locations in the data segment which is addressed by the DS

register. Thus, SI is associated with the DS in string operations.

• DI: Destination Index register

– is also required for some string operations.

– When string operations are performed, the DI register points to

memory locations in the data segment which is addressed by the ES

register. Thus, DI is associated with the ES in string operations.

• The SI and the DI registers may also be used to access data stored in

arrays

Memory Segmentation

The total memory size is divided into segments of various sizes. A segment is

just an area in memory.The process of dividing memory this way is called Segmentation.

In memory data is stored as bytes, each byte has specific address. Intel 8086 has 20 lines address bus. With 20 address lines, the memory that can be addressed is bytes.

= 1,048,576 bytes (1 MB).

8086 can access memory with address ranging from 00000 H to FFFFF H.

In 8086, memory has four different types of segments.

These are:

  • Code Segment
  • Data Segment
  • Stack Segment
  • Extra Segment

Each of these segments is addressed by an address stored in corresponding segment register. These registers are 16 bit in size, each register stores the base address (starting address) of the corresponding segment. Because the segment registers cannot store 20 bits, they only store the upper 16 bits. See figure (1).

Figure(1) illustrate segment registers and memory

Q.\

How is a 20-bit address obtained if there are only 16-bit registers?

Answer:

20-bit address of byte is called Physical Address, But it is specified as Logical address.

Logical Address is in the form of:

Base Address : Offset

Offset is the displacement of the memory location from the starting location of the segment.

Example

Let the value of data segment register (DS) is 2222 H.

To convert this 16-bit address into 20-bit, the BIU

1- Appends 0H to the LSB of the Address.

2- After appending the starting address of the data segment becomes 22220 H.

3- if the data at any location has a logical address specified as:

2222 H : 0016 H

4- then the number 0016 H is the offset.

2222 H is the value of DS.

5- to calculate the effective address of the memory, BIU uses the following

formula:

Effective address = Starting address of segment + Offset.

To find the starting address of the segment, BIU appends the contents of segment

register with 0H. Then, it adds offset to it. See figure(2)

Therefore : EA = 22220 H

+ 0016 H

------

22236 H

Figure(2) illustrate effective address

Remarks:

All offsets are limited to 16-bit.

It means that the maximum size possible for segment is = 65,535 bytes(64 KB)

The offset of the first location within the segment is 0000 H.

The offset of the last location in the segment is FFFF H.

See Tale (1-1).

Table(1-1) illustrate Offset Registers

Question\

The contents of the following registers are:

CS = 1111 H

DS = 3333 H

SS = 2526 H

IP = 1232 H

SP = 1100 H

DI = 0020 H

Calculate the corresponding physical address for the address bytes in CS, DS, SS.

Solution\

1. CS = 1111 H

  • The base address of the code segment is 11110 H.
  • Effective address of memory is given by 11110H + 1232H = 12342H.
  1. DS = 3333 H
  • The base address of the code segment is 33330 H.
  • Effective address of memory is given by 33330H + 0020H = 33350H.
  1. SS = 2526 H
  • The base address of the code segment is 25260 H.
  • Effective address of memory is given by 25260H + 1100H = 26350H.

1Shaymaa Al-Garawi