Introduction to Program segments
Main memory, which is 1M bytes,
is divided into segments. Each segment size is 64K bytes. In 8086/8088
architecture, segmented memory model is used. The reason for using segmented
memory model is to make it compatible with earlier architectures 8085/8080
which had total 64K bytes main memory. Codes/Programs written for 8085/8080
architectures will run on architecture 8086/8088.
The main memory being 1M bytes
has physical address of 20-bits. To access data from physical memory location, processor
generates 20-bit address. This address is generated using segment and offset
registers. Steps are as follows;
1. Shift left segment value by 4-bits (binary).
2. Shift right offset by 4-bits
3. Adds these two numbers,
4. Result produced is 20-bit physical address.
Example
If you specify segment value as
CS=0A00 and offset value as IP=1234; Processor will read/write data from Physical
address calculated as below;
Physical address =0000 1011 0010 0011 0100
Code segment
When a code is assembled, the
executable part (instructions) are placed in code segment and are accessed one
by one. Instruction pointer (IP) is a register that always points to next
executable instruction in code segment. It holds the address of next instruction
which is to be executed. To read instructions manually from any part of code
segment, address can be specified using segment and offset. Segment has to be
specified via segment register CS and offset can be given using immediate value
or instruction pointer (IP).
For example, to access
instruction from memory address 0Xabcde; CS can be initialized as CS=A000 and
offset can be chosen as offset=BCDE;
Data segment
The variables or arrays declared
in a program are stored in data segment. Processor generates physical memory
address to read/write data from data segment in similar way as explained above
with the only difference that registers used to access data are different.
Whenever you want to access a
memory variable, you can specify its physical address by specifying its segment
address in DS offset address in either of (Si, Di or BX)
registers.
Stack segment
Variables created within functions/procedures, parameters
needed in a function call, return addresses of functions & interrupts are always
saved in stack memory. To access data from stack segment, Stack Segment
register (SS) is used as segment register and base pointer (BP) is used as
offset register.
Extra segment
Part of memory which is used to temporary store memory
variables. Extra segment register (ES) can be used to access data from other
segments too. Usually used in string operations.
No comments:
Post a Comment