6. Address Space in Real Mode

For compatibility reasons, Pentium CPU is capable of switching itself into real mode segmented model, is effectively becoming a good old 8086 chip!

7. Collective Terms for Memory

Size

Decimal

Hex

Byte

1

01H

Word

2

02H

Double word

4

04H

Quad word

8

08H

Ten byte

10

0AH

Paragraph (*)

16

10H

Page, or page frame, (almost never used)

256

100H

Segment

65,536

10000H

______________

(*) Paragraphs are almost never used, except in connection with the places where segments may begin.

8. Memory Paragraphs in Real Mode

Any memory address evenly divisible by 16 is called a paragraph boundary.

The first paragraph boundary is address 0.

The second is address 10H (10H is equal to decimal 16.)

The third address is 20H, and so on.

Any paragraph boundary may be considered the start of a segment.

There are 64K different paragraph boundaries where a segment may begin.

Each paragraph boundary has a number.

The numbers range from 0 to 64K minus one (decimal 65,535 or hex 0FFFFh.)

Any segment may begin at any paragraph boundary.

The number of the paragraph boundary is called the segment address.

Assembly language program can have up to four or five segments.

Segment address is 16 bytes in size.

9. Segment of Memory in Real Mode

Every byte of memory, accessible by program, is assumed to reside in a segment.

Segment size varies and can range from 1 byte to 64 Kbytes.

Nothing is protected within a segment in Real Mode.

Segments can overlap.

Initializing the data segment register in 16-bit real mode:

Numerical (immediate) values cannot be moved directly into the segment register. It is a 2-step process:

mov ax, 1000h
mov ds, ax

Initializing the data segment register:

10. Memory Access in Real Mode

Recall that 8086 and 8088 CPUs had 20 address pins, limiting a program to 1 megabyte of memory.

To express a 20-bit address, two 16-bit registers are used:

segment address in one 16-bit register,

and the offset address in another 16-bit register.

The memory location of a particular byte from one megabyte of memory is calculated as

segment start address

plusdistance between the byte and the segment start.

The byte's distance from the start of the segment is referred to as the byte's offset address.

SEGMENT:OFFSET addresses are always written in hexadecimal notation.

For example, an address of one byte of data MyByte is given as 0001:001D.

This means that MyByte is in segment 0001H and is located 001DH bytes from the start of that segment.

Since segments can overlap, same byte could also be located by SEGMENT:OFFSET combinations 0002:000D or 0001:001D.

11. Segment Registers in Real Mode

The 8088, 8086, and 80286 CPUs have four segment registers to hold segment addresses.

The 386 and later CPUs have two more, also available in real mode.

Note: the 386 and later Intel x86 CPUs still use 16-bit size segment registers.

Each segment register is 16-bit in size.

No matter how location in memory is accessed, the segment address of that location must be present in one of the six segment registers:

CS, DS, SS, ES, FS and GS.

12. Segment Register Names

All x86 segment registers are 16 bits in size, irrespective of the CPU:

CS, code segment. Machine instructions exist at some offset into a code segment. The segment address of the code segment of the currently executing instruction is contained in CS.

DS, data segment. Variables and other data exist at some offset into a data segment. There may be many data segments, but the CPU may only use one at a time, by placing the segment address of that segment in register DS.

SS, stack segment. The stack is a very important component of the CPU used for temporary storage of data and addresses. Therefore, the stack has a segment address, which is contained in register SS.

ES, extra segment. The extra segment is exactly that: a spare segment that may be used for specifying a location in memory.

13. Segment Register Names, Cont.

FS and GS are clones of ES, the extra segment.

FS and GS both are just additional segments, no specialty here.

Names FS and GS come from the fact that they were created after ES: E, F, G.

They exist only in the 386 and later x86 CPUs.

Extra segments ES, FS, and GS can be used for both data or code.

The six segments of the memory system:

14. Segment Positions in Real Mode

15. General-Purpose Registers in Real mode

General-purpose registers may hold

data values

offset addresses that must be paired with segment addresses to locate data in memory.

The customary notation is to separate the segment register and the offset register by a colon. For example:

DS : AX
SS : SP
SS : BP
ES : DI
DS : SI
CS : BX

16. Segmentation Models Summary

Pentium can turn off segmentation.

Flat model

Consists of one segment of 4GB

Used by linux

Multisegment model

Up to six active segments

Can have more than six segments (all segment descriptors are in the descriptor table.)

A segment becomes active by loading its descriptor into one of the segment registers.

17. Real Mode Flat Model Summary

CPU can see only 1 megabyte (1,048,576) of memory.

segment:offset pairs form a 20-bit addresses out of two 16-bit addresses.

In real mode flat model a program and all its data must exist within a single 64K block of memory.

The real mode flat model is similar to protected mode flat model, the code model used on Linux and Windows XP/Vista.

18. Real Mode Flat Model Diagram

The segment registers are all set to point to the beginning of the 64K block of memory.

The operating system sets segment registers when it loads the program.

All segment registers point to that same place.

Physical segment assignments never change as long as the program is running.

The segment registers are still functioning, but no work with segments is required.