Micro Lect Notes 5 6
Micro Lect Notes 5 6
BS Computer Engineering
Microprocessors
3rd
Year
Contents
How its memory space is addressed?
Real mode of operation
Protected mode of operation
Flat mode of operation
Overlapped Segments
An application program containing a code,
data, and stack segment loaded into a DOS
system memory
The side view of the segments clearly
shows the overlap.
It also shows how segments can be moved
over any area of memory by changing the
segment starting address.
Fortunately, the DOS program loader
calculates and assigns segment starting
addresses
Examples 2
The segment address is 4000H
The offset address is specified as the sum of F000H plus 3000H
What is the memory location that will be accessed?
Solution
Start Address: 40000H
Offset Address: F000H + 3000H = 12000H
This will access memory location 42000H instead of location 52000H (Why?)
When the F000H and 3000H are added, they form a l6-bit (modulo 16) sum
of 2000H used as the offset address; not 12000H, the true sum.
Note that the carry of 1 (F000H + 3000H = 12000H) is dropped for this
addition to form the offset address of 2000H. The address is generated as
4000:2000 or 42000H.
Windows Mode
Allows access to data and programs located
anywhere in the memory
Variable Segment size
Using the segment register to select a
description from the global descriptor table.
In this example, the DS register accesses
memory locations 00100000H–
001000FFH as a data segment.
The entry in the global descriptor table
selects a segment in the memory system.
The contents of a segment register during protected mode operation of the 80286 through Core2
microprocessors.
13-bit selector field: selects one of 8192 (8k) descriptors from one of two tables
(global or local) of descriptors
Each descriptor table contains 8192 descriptors, so a total of 16,384 total
descriptors 16,384 total descriptors
The TI bit (table selector bit) selects either the global or the local descriptor table.
Requested Privilege Level (RPL) requests the access privilege level of a memory
segment.
If privilege levels are violated, system normally indicates an application or privilege
level violation
The base address of the descriptor indicates the starting location of the memory
segment.
the paragraph boundary limitation is removed in protected mode
segments may begin at any address
The base address of the descriptor indicates the starting location of the memory
segment
For the 80286 microprocessor, the base address is a 24-bit address, so segments
begin at any location in its 16M bytes of memory
The 80386 and above use a 32-bit base address that allows segments to begin at
any location in its 4G bytes of memory
The segment start and end if the base address is 10000000H, the limit is 001FFH, and the G-
bit G=0
Example-2 (G=0)
The segment start and end if the base address is 10000000H, the limit is 001FFH, and the G-
bit G=1
Note: limit is appended with FFFH to determine the ending segment address
Program-Invisible Registers
Global and local descriptor tables are found in the memory system.
To access & specify the table addresses, 80286–Core2 contain program- invisible
registers.
not directly addressed by software
although some of these registers are accessed by the system software
Each segment register contains a program-invisible portion used in the protected mode.
often called cache memory because cache is any memory that stores information
Notes
1. The 80286 does not contain FS and GS nor the program-invisible portions of these
registers.
2. The 80286 contains a base address that is 24-bits and a limit that is 16-bits.
3. The 80386/80486/Pentium/Pentium Pro contain a base address that is 32-bits and a
limit that is 20-bits.
4. The access rights are 8-bits in the 80386 and 12-bits in the 80386/80486/Pentium-
Core2.
When a new segment number is placed in a segment register, the microprocessor
accesses a descriptor table and loads the descriptor into the program-invisible portion of
the segment register.
held there and used to access the memory segment until the segment number is
changed
This allows the microprocessor to repeatedly access a memory segment without
referring to the descriptor table.
hence the term cache
The GDTR (global descriptor table register) and IDTR (interrupt descriptor table
register) contain the base address of the descriptor table and its limit.
when protected mode operation desired, address of the global descriptor table and
its limit are loaded into the GDTR
The location of the local descriptor table is selected from the global descriptor table.
one of the global descriptors is set up to address the local descriptor table
Memory Paging
The memory paging mechanism allows any physical memory location to be assigned to
any linear address.
Linear address is defined as the address generated by a program.
Physical address is the actual memory location accessed by a program.
With memory paging, the linear address is invisibly translated to any physical address.
In Windows, each application is allowed a 2G linear address space from location
00000000H–7FFFFFFFH even though there may not be enough memory or memory
available at these addresses.
Through paging to the hard disk drive and paging to the memory through the memory
paging unit, any Windows application can be executed
Paging Registers
The paging unit is controlled by the contents of the microprocessor’s control registers.
Beginning with Pentium, an additional control register labeled CR4 controls extensions to
the basic architecture.
Paging Registers
The leftmost bit (PG) position of CR0 selects paging when placed at a logic 1 level.
If the PG bit is cleared (0), the linear address generated by the program becomes the
physical address used to access memory.
If the PG bit is set (1), the linear address is converted to a physical address through the
paging mechanism.
The paging mechanism functions in both the real and protected modes.
CR3 contains the page directory base or root address
The page directory base address locates the directory for the page
translation unit
Note that this address locates the page directory at any 4K boundary in the memory
system because it is appended internally with 000H.
The page directory contains 1024 directory entries of 4 bytes each.
Each page directory entry addresses a page table that contains 1024 entries
Memory Paging
The linear address, as generated by software, is broken into three sections that are used to
access the page directory entry, page table entry, and memory page offset address.
Memory Paging
Intel has incorporated a special type of cache called TLB (translation look-aside buffer).
because repaging a 4K-byte section of memory requires access to the page directory
and a page table, both located in memory
The 80486 cache holds the 32 most recent page translation addresses.
if the same area of memory is accessed, the address is already present in the TLB This
speeds program execution
Pentium contains separate TLBs for each of their instruction and data caches.
Summary
8-bit registers are AH, AL, BH, BL, CH, CL, DH, and DL.
16-bit registers are AX, BX, CX, DX, SP, BP, DI, and SI.
The segment registers are CS, DS, ES, SS, FS, and GS.
32-bit extended registers are EAX, EBX, ECX, EDX, ESP, EBP, EDI, and ESI.
The 64-bit registers in a Pentium 4 with 64-bit extensions are RAX, RBX, RCX, RDX, RSP,
RBP, RDI, RSI, and R8 through R15.
In addition, the microprocessor contains an instruction pointer (IP/EIP/RIP) and flag
register (FLAGS, EFLAGS, or RFLAGS).
All real mode memory addresses are a combination of a segment address plus an offset
address.
The starting location of a segment is defined by the 16-bit number in the segment register
that is appended with a hexadecimal zero at its rightmost end.
The offset address is a 16-bit number added to the 20-bit seg-ment address to form the
real mode memory address.
All instructions (code) are accessed by the combination of CS (segment ad-dress) plus IP or
EIP (offset address).
Data are normally referenced through a combination of the DS (data segment) and either
an offset address or the contents of a register that contains the offset address.
The 8086-Core2 use BX, DI, and SI as default offset registers for data if 16-bit registers are
selected.
The 80386 and above can use the 32-bit registers EAX, EBX, ECX, EDX, EDI, and ESI as
default offset registers for data.
Protected mode operation allows memory above the first 1M byte to be accessed by the
80286 through the Core2 microprocessors.
This extended memory system (XMS) is accessed via a segment address plus an offset
address, just as in the real mode.
In the protected mode, the segment starting address is stored in a descriptor that is
selected by the segment register.
The 80286 microprocessor allows a memory segment to start at any of its 16M bytes of
memory using a 24-bit base address.
The 80386 and above allow a memory segment to begin at any of its 4G bytes of memory
using a 32-bit base address.
This allows an 80286 memory segment limit of 64K bytes, and an 80386 and above mem-
ory segment limit of either 1M bytes
The segment register contains three fields of information in the protected mode.
The leftmost 13 bits of the segment register address one of 8192 descriptors from a
descriptor table.
The program-invisible registers are used by the 80286 and above to access the descriptor
tables.
Each segment register contains a cache portion that is used in protected mode to hold the
base address, limit, and access rights acquired from a descriptor.
The cache allows the microprocessor to access the memory segment without again
referring to the descriptor table until the segment register's contents are changed.
A memory page is 4K bytes in length. The linear address, as generated by a program, can be
mapped to any physical address through the paging mechanism found within the 80386
through the Pentium 4.
Memory paging is accomplished through control registers CR0 and CR3.
The PG bit of CR0 enables paging, and the contents of CR3 addresses the page directory.
The page directory contains up to 1024 page table addresses that are used to access
paging tables.
The page table contains 1024 entries that locate the physical address of a 4K-byte memory
page.
The TLB (translation look-aside buffer) caches the 32 most recent page table translations.
The flat mode memory contains 1T byte of memory using a 40-bit address.
In the future, Intel plans to increase the address width to 52 bits to access 4P bytes of
memory.
The flat mode is only available in the Pentium 4 and Core2 that have their 64-bit extensions
enabled.