• No results found

bit address of a byte is called its physical address .But it is specified as a logical address which is in the form of two 16 bit numbers in the format base address: offset

In document Lyla b das 0 & 1.pdf (Page 40-45)

THE ARCHITECTURE OF 8086

The 20 bit address of a byte is called its physical address .But it is specified as a logical address which is in the form of two 16 bit numbers in the format base address: offset

1.3.2.1 Segment Registers

Each of these segments is addressed by an address stored in corresponding segment registers .These registers are all 16 bit in size .Each register stores the base address of the corresponding segment .A base address is the starting address of a segment .But since the segment registers cannot store 20 bits (of the base address) ,they store only the upper 16 bits. The least significant nibble is implied to be zero.

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

The 20 bit address of a byte is called its physical address .But it is specified as a logical address which is in the form of two 16 bit numbers in the format base address: offset See the following figure ,as a typical example .

22236H

Base addres

Base address 2220H

Fig 1-3 Calculation of a physical address from the logical address Physical Address

x86 Chapter 1 Page 11 We consider that a data byte is stored in a data segment ,whose base address is 22220H .Then the data segment register (DS) will contain the number 2222H . The data at any location within this segment is referenced by an offset(displacement) with respect to the base address . Thus if a data at location a has a logical address specified as 2220H:0016H ,the number 0016H is the offset or displacement with respect to the base address .For physical address calculation ,the BIU appends the segment register content with four binary zeros(or one hex zero) on the right . The physical address is thus calculated as

22220H + 0016H

22236H

Fig 1-4 Segment Registers and Corresponding segments

Similar is the case for the other segments . All offsets are limited to 16 bits which means that the maximum size possible for a segment is only 216 which is 65,536 bytes or 64K bytes. We can conclude that every memory reference by the 8086 will use one of the segment registers (i.e., DS, ES, SS, or CS, ) which is combined with an offset (usually given in the instruction) to determine the physical address being accessed.

A data byte has the logical address of the form DS: offset 1.3.2.2 The Code Segment and the Instruction Pointer

The code segment is the area of memory where code alone is stored . The offsets within the code segment are referenced using the Instruction Pointer(IP) which is a 16 bit register .The IP sequences the instructions ,and always points to the next instruction to

SEGMENT REGISTERS BASE ADDRESS

50000H 70000H 90000H A0000H

SS ES DS CS A000H

9000H

5000 H 7000H

CS

DS

ES

SS

x86 Chapter 1 Page 12 be executed. Whenever an instruction byte has to be fetched from memory ,the bus interface unit(BIU ) performs the address calculation using the contents of CS register and the IP. This 20 bit address is then placed on the address bus and the instruction byte is fetched. Thus the logical address for an instruction bye is of the form CS:IP

1.3.2.3 The Stack Segment and the Stack Pointer

The stack is an area of memory which is used in a special way . Data is generally pushed in and popped out of the stack . The stack of the 8086 is a Last in First out ( LIFO )stack ,which means that the last data that was pushed in ,is the first one that can be popped out .This also means that data can only be taken out or put in only from the top of the stack, But the s‘ stack top’ changes as data is put in or taken out.

There is a 16 bit register called Stack Pointer which points to the top f the stack . The stack segment is like any other segment ,and the upper 16 bits of its base address is available is the SS register. A stack address of the form 4466H: 0122H means that the SS register contains 4466 H, the stack pointer (SP)contains the number 0122H , and the physical address of the top of the stack is 44660H+0122H =44782H

Fig : 1.5 Stack and physical address of the top of stack

The stack is used mostly to keep aside address and data temporarily , when a subprogram is called . This will be taken back when the subprogram ends .The 8086 has a stack which grows downwards(i.e. to lower memory addresses ) . This means that each push instruction causes the SP to be decremented (by two for 8086) , and data is pushed deeper downwards into the stack segment .We will discuss the operation of the stack in more detail in Chapter 4.

Even though ,a stack is usually accessed only from the top ,the 8086 has another register named BP (base pointer) which is used to reference data anywhere within the stack .

SS SP Address of the

top of stack 44782H

Base Address 44660H 4466H

0122 H Byte

Byte Byte - - - - - - -

x86 Chapter 1 Page 13 Thus the format SS:BP is also a logical address. This has certain interesting applications.

1.3.2.4 The Data Segment and Extra Segment

Both these segments store data ,but in certain special cases (string instructions) ,it may be necessary to list them separately . There is an Extra Segment ( ES )register to store the upper 16 bits of the base address of the extra segment

The offset within the data segment is also termed as an ‘effective address’. The effective address calculation depends on the mode of addressing .We will discuss this very soon.

SEGMENT OFFSET REGISTERS FUNCTION

CS IP Address of the next instruction

DS BX ,DI ,SI Address of data

SS SP , BP Addresses in the stack

ES BX,DI ,SI Address of destination data

(for string instructions ) Table 1-1: Segments and corresponding registers used for specifying offsets Table 1.1 shows the segment registers and the corresponding registers for offsets

--- Example 1-4

The content of DS is 345BH . The amount of data that is to be stored in the data segment is 12K bytes . Where in memory ,will this segment be located?

Solution:

DS contains the number 345BH.

This number corresponds to the upper 4 hex digits of the starting (base address)of the data segment .

The base address of the segment is 345B0H .

The last address will have an offset of 12K from the base address . 1K =1024 bytes

12 K=12 x1024 =12228=3000H

The last address of the segment =345B0H +3000H=375B0H

Hence the data segment occupies the memory addresses from 345B0H to 375B0H.

---

Example 1.5

The contents of the following segment registers are as given CS =1111H ,DS =3333H ,SS=2526H

IP =1232H ,SP =1100H ,offset in data segment =0020H

x86 Chapter 1 Page 14 Calculate the corresponding physical addresses for the addressed byte in a)CS b)SS and c)DS.

Solution:

a)The base address of CS is 1110H .

The address of the next instruction to be executed is referenced by CS and IP . which is given by 11110H + 1232H =12342H

b)The current top of the stack is referenced by SS and SP .The base address of the stack segment is 25260H .The corresponding physical address is 25260H +1100H =26350H c)The data that needs to be accessed is given by DS and the offset .The base address of the data segment is 33330H .The physical address of this data is calculated as 33330H+0020H =33350H

--- Segmentation-General Concerns

1. Segments begin at paragraph boundaries ,where a paragraph is 16 bytes.

i.e. Base addresses are divisible by 16 (because the lowest nibble of all base addresses are to be zero).

2 Segments can overlap with a new segment starting every 16 bytes. This also means that there can be more than one logical address for the same memory location. (physical address) For example, 0000:0100, 0001:00F0, and 0010:0000 all refer to physical address 00100H.

3 We can have segments with the same base address ,but the offsets within the segment will have to be taken care of to prevent overwriting of data .

For example ,in string operations ,we might use the same segment as the

data and extra segments. This is achieved by loading the same number in the ES and DS registers.

4. A segment can have a maximum size of 64 K .

5 . A program need not have all four segments ,but it will have at least the code segment ,

6.. The addresses used in instructions are called logical addresses which are translated by the BIU to physical addresses.

Advantages of Segmentation

1. It allows all address registers to have the same size as the data registers(16 bit) , while allowing the use of 20 bit physical addresses.

2. All addresses in memory are re-locatable . This means that any program or data can be loaded in any address in memory .A re-locatable program is one which can be placed in any area of memory and executed without change. Data is also re-locatable. Changing the base address of the corresponding segment is the only

x86 Chapter 1 Page 15 action we need to perform, in order to re-locate .. All addresses within the program are relative to the base address, as they are of the form Base address:

offset .All processors in the x86 family have this kind of segmentation . The higher order processors have protection also added to this structure.

Memory Organization

We have seen that data is stored in memory as bytes . Each byte location has an address . If a word (two bytes) is to be stored ,two locations of consecutive addresses are needed . Consider that the number 34E6H is to stored . Then 34H is stored in one location and E6H is in the next location .Intel’s processors use what is termed the little endian format which means the lower byte is stored in the lower address and the upper byte in the higher address .Thus if the above word has an address of 60088H , the storage is as shown in the fig

In document Lyla b das 0 & 1.pdf (Page 40-45)

Related documents