0% found this document useful (0 votes)
1K views20 pages

Real-Mode Memory Addressing

Real mode uses a segmented memory model with a 20-bit address bus, limiting the accessible memory to 1 MB. Addresses are calculated by combining a 16-bit segment register and 16-bit offset. This allows programs to be relocated by changing only the segment register. However, real mode has limitations like fixed 64 KB segment sizes, lack of protection from other programs, and complex address generation slowing memory access.

Uploaded by

Jas Lim
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)
1K views20 pages

Real-Mode Memory Addressing

Real mode uses a segmented memory model with a 20-bit address bus, limiting the accessible memory to 1 MB. Addresses are calculated by combining a 16-bit segment register and 16-bit offset. This allows programs to be relocated by changing only the segment register. However, real mode has limitations like fixed 64 KB segment sizes, lack of protection from other programs, and complex address generation slowing memory access.

Uploaded by

Jas Lim
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/ 20

MEMORY

MANAGEMENT
REAL MODE MEMORY ADDRESSING
■ Memory Access:
– Real Mode memory-addressing techniques.
– Protected Mode memory-addressing techniques.

■ Memory Access:
– 64-bit Flat Memory model.
■ Program-invisible registers in the 80286~Core2
microprocessors.
REAL MODE MEMORY
ADDRESSING
■ The only mode available on the 8086-8088.
20 bit address bus  1 MB, 16 bit data bus, 16 bit registers

■ 80286 and above operate in either the real or protected mode.


■ Real mode operation allows addressing of only the first 1M byte
of memory space—even in Pentium 4 or Core2 microprocessor.
– the first 1M byte of memory is called the real memory, conventional
memory, or DOS memory system
Segments and Offsets

■ All real mode memory addresses must consist of a segment


address plus an offset address.
– segment address defines the beginning address of any 64K-byte
memory segment
– offset address selects any location within the
64K byte memory segment

■ Figure in Next Slide: shows how the segment plus offset


addressing scheme selects a memory location.
– this shows a memory
segment beginning at
10000H, ending at location
IFFFFH
• 64K bytes in length

– also shows how an offset


address, called a
displacement, of F000H
selects location 1F000H in
the memory

Figure: The real mode memory-addressing scheme, using a segment


address plus an offset.
Physical Address Calculation
Physical Address (PA) is also
known as the Effective Address
Then the Effective memory
Address (EA) = 20-bit segment
start address + 16-bit offset
address
■ Here, assume were in the data segment.
■ DS=1000
■ BX=F000
■ EA = DS:BX= 1000:F000

NOTE: To get actual address in memory


– Shift Segment Address left by 1 nibble, fill
0 in a 0 to the right and add the offset address

Segment Start Address


in Segment Register
Segments and Offsets

■ Once the beginning/starting address is known, the ending


address is found by adding FFFFH.
– because a real mode segment of memory is 64K in length

■ The offset address is always added to the segment starting


address to locate the data.
■ Segment and offset address is sometimes written as 1000:2000.
– a segment address of 1000H; an offset of 2000H
Beginning Address, Ending Address, and Effective
Address Calculations

■ EA = segment register (SR) x


10H + offset
(a) SR: 1000H
EA = 10000 + 2000 = 12000
(b) SR: 2001H
EA = 20010 + 007C = 2008C
(c) SR: 1234H
EA = 12340 + FFEE = 2232E
Default Segment and Offset Registers

■ The microprocessor has rules that apply to


segments whenever memory is addressed.
– these define the segment and offset register
combination

■ The code segment register defines the start of


the code segment.
■ The instruction pointer locates the next
instruction within the code segment.
Default Segment and Offset Registers

■ Another of the default combinations is the stack.


– stack data are referenced through the stack segment at
the memory location addressed by either the stack
pointer (SP/ESP) or the base pointer (BP/EBP)

■ Figure in Next Slide: shows a system that contains


four memory segments.
– a memory segment can touch or overlap if 64K bytes of
memory are not required for a segment
Default Segment and Offset Registers
Memory
FFFFF

– think of segments as
59000 Windows that can be
58FFF
moved over any area of
Extra
49000
4900 ES
memory to access data or
48FFF
code
44000
43FFF

Stack – a program can have more


34000
33FFF
3400 SS than four or six segments,
30000
2FFFF • but only access four or six
Code segments at a time
20000 2000 CS
1FFFF
Figure: A memory system showing the placement
Data of four memory segments.
10000 1000 DS
0FFFF

00000
Default Segment and Offset Registers

Code should be limited to


only this portion of the
code segment, to avoid
effects of segment
overlap.

Figure: An application program containing a code, data,


and stack segment loaded into a DOS system memory.
Default Segment and Offset Registers
Convention Example: EA = CS:[IP]
■ Default segment numbers in:
– CS for program (code) Segment Start Offset: Literal
– SS for stack in Segment register or in a CPU register
– DS for data
– ES for string (destination) data
■ Default offset addresses that go with them:

Segment Offset (16-bit) Offset (32-bit) Purpose


8080, 8086, 80286 80386 and above

CS IP EIP Program

SS SP, BP ESP, EBP Stack

DS BX, DI, SI, 8-bit or 16-bit # EBX, EDI, ESI, EAX ECX,
EDX, 8-bit or 32-bit #
Data

ES DI, with string instructions EDI, with string instructions String


destination
TPA

■ The Transient Program Area (TPA) holds the DOS (disk operating
system) operating system; other programs that control the computer
system.

■ TPA is the first available area of memory above drivers and other TPA
programs

■ Area is indicated by a free-pointer maintained by DOS

■ program loading is handled automatically by the program loader within


DOS
Real Mode Addressing Scheme Allows
Relocation
■ Segment plus offset addressing allows DOS
programs to be relocated in memory.

■ A relocatable program is one that can be placed


into any area of memory and executed without
change.

■ Relocatable data are data that can be placed in


any area of memory and used without any change
to the program.
Real Mode Addressing Scheme Allows
Relocation
■ Because memory is addressed within a segment
by an offset address, the memory segment can be
moved to any place in the memory system without
changing any of the offset addresses.

■ Only the contents of the segment register must be


changed to address the program
in the new area of memory.

■ Windows programs are written assuming that the


first 2G of memory are available for code and
data.
Real Mode : Pros and Cons
Advantages:
■ Allows easy and efficient relocation of code and data
■ To relocate code or data, only the number in the relevant segment
register needs to be changed
Consequences:
A program can be located anywhere in memory without making any
changes to it (addresses are not absolute, but offsets relative to
start of segments)
Program writer needs not worry about actual memory structure
(map) of the computer used to execute it

Disadvantages:
■ Complex hardware and for address generation
■ Address computation delay for every memory access
■ Software limitation: Program size limited by segment size (64KB
with the 8086)
Limitations of the Real Mode Segmentation
Scheme
■ Segment size is fixed at and limited to 64 KB

■ Segment can not begin at an arbitrary memory address…

With 20-bit memory addressing, can only begin at addresses starting with
0H, i.e. at 16 byte intervals

 Principle is difficult to apply with 80286 and above, with segment


registers remaining at 16-bits!
Append: 00H 0000H

80286 and above use 24, 32 bit addresses but still 16-bit segment
registers

■ No protection mechanisms: Programs can overwrite operating system


code segments and corrupt them!

 Use memory segmentation in the protected mode

You might also like