Professional Documents
Culture Documents
Syllabus
Microprocessor architecture: Real mode and
protected mode memory addressing - Memory
paging - Addressing modes - Data addressing -
Program memory addressing - Stack memory
addressing - Data movement instructions -
Arithmetic and logic instructions - Program
control instructions - Programming the
microprocessor: modular programming - Using
keyboard and display - Data conversions - disk
files - interrupt hooks
JT/YHC/EIE311/2002/CSF_ch2.ppt page 1
Internal microprocessor
architecture
Before a program is written or any instruction
investigated, the internal configuration of the
microprocessor must be known.
The programming model of the 8086 through the
Pentium Pro is considered program visible because
its registers are used during programming and
specified by the instructions.
Registers which can not be addressable directly
during applications programming but may be used
indirectly during system programming are
considered program invisible.
JT/YHC/EIE311/2002/CSF_ch2.ppt page 2
Internal microprocessor
architecture
Figure 2.1 illustrates the programming
model of the 8086 through the Pentium II
microprocessor.
Some registers are general-purpose or
multipurpose registers, while some have
special purposes.
JT/YHC/EIE311/2002/CSF_ch2.ppt page 3
Registers
JT/YHC/EIE311/2002/CSF_ch2.ppt page 4
Registers:
Registers hold various data sizes (bytes,
words, or doublewords) and are used for
almost any purpose as dictated by a
program.
Multipurpose Registers
Special-purpose Registers
Segment Registers
JT/YHC/EIE311/2002/CSF_ch2.ppt page 5
Flags
•Three types
– status flag
– control flag
– system flag
JT/YHC/EIE311/2002/CSF_ch2.ppt page 6
Flag register
JT/YHC/EIE311/2002/CSF_ch2.ppt page 7
Real mode memory
addressing
Two operating modes – Real and Protected
Real mode operation allows the microprocessor to address
only the first 1M byte of memory space - even the Pentium
microprocessor.
The first 1M byte of memory is called either the real
memory or conventional memory system.
Dos- requires real mode
Real mode allows upward compatibility. Ie, it operation allows
application software written for the 8088/8086, which
contain only 1M byte of memory, to function in the 80286
and above without changing the software.
In all cases, each of these microprocessors begins operation
in the real mode by default whenever power is applied or the
microprocessor is reset.
JT/YHC/EIE311/2002/CSF_ch2.ppt page 8
Segments and offsets
A combination of a segment address and an offset address
access a memory location in the real mode.
The segment address, located within one of the segment
registers, defines the beginning address of any 64K-byte
memory segment.
The offset address selects any location within the 64K-byte
memory segment.
Segments in the real mode have 64K bytes .
Offset also called displacement.
Each segment register is internally appended with a 0H on
its right end , to form a 20 bit memory address.
Figure 2.3
Table 2.1
JT/YHC/EIE311/2002/CSF_ch2.ppt page 9
Figure 2.3
Real Mode
Memory
JT/YHC/EIE311/2002/CSF_ch2.ppt page 10
A 20-bit real mode address allows one to access the start of
a segment at any 16-byte boundary within the first 1M byte
of memory.
Any real mode segments can only begin at a 16-byte
boundary in the memory system and this boundary is often
called a paragraph.
The ending address of a segment is starting address +
FFFFH
The offset is always added to the starting address of the
segment
Offset can be calculated form more than one register and an
of set value
JT/YHC/EIE311/2002/CSF_ch2.ppt page 11
Table 2.1 Example
segment addresses
JT/YHC/EIE311/2002/CSF_ch2.ppt page 12
Default segment and offset
registers
The microprocessors has a set of rules
that apply to segments whenever memory is
addressed.
These rules, which apply in either the real
or protected mode, define the segment
register and offset register combination
used by certain addressing modes.
Table 2.2
JT/YHC/EIE311/2002/CSF_ch2.ppt page 13
Table 2.2 Default Segment
and Offset Registers
Table 2.3 80386, 80486, Pentium, Pentium Pro, and Pentium II default 32-bit segment
and offset address combinations.
JT/YHC/EIE311/2002/CSF_ch2.ppt page 15
Default segment and offset
registers
The code segment register defines the
start of the code segment and the
instruction pointer locates the next
instruction within the code segment.
Stack data are references through the
stack segment at the memory location
addressed by either the stack pointer
(SP/ESP) or the base pointer (BP/EBP).
Table 2.3
JT/YHC/EIE311/2002/CSF_ch2.ppt page 16
Default segment and offset
registers
One can think of segments as windows that can be
moved over any area of memory to access data and
code.
A program can have a lot of segments, but can only
access four (in 8086-80286) or six (in 80386 and
above) segments at a time.
Memory segments can touch or even overlap if 64k
memory is not required for a segment.
In Dos the program is loaded by the program
loader in the TPA (Transient program area) at
the first available area and it is indicated by a
free pointer maintained by Dos.
JT/YHC/EIE311/2002/CSF_ch2.ppt page 17
Figure 2.4
A Memory
System
JT/YHC/EIE311/2002/CSF_ch2.ppt page 18
Figure 2.5
DOS system
memory.
JT/YHC/EIE311/2002/CSF_ch2.ppt page 19
Relocation
Segment and offset addressing scheme allows
relocation.
Relocation allows the program function in real mode
to operate in protected mode systems
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.
The seg.+off. Addressing scheme allows relocation
with out changing a thing in the program or data.
JT/YHC/EIE311/2002/CSF_ch2.ppt page 20
Protected Mode Memory
Addressing
– access above 1MB of memory (80286 and above)
– offset address: still used to access information located within
the memory segment
• 80286: 16-bit
• 80386 and above: 32-bit (232 = 4G)
– segment register: contains a selector that selects a
descriptor from a descriptor table
• descriptor: describing the memory segment’s location, length,
and access rights
– protected mode instructions are identical to real mode
instructions;
- programs written to function in the real mode will
function without change in the protected mode
JT/YHC/EIE311/2002/CSF_ch2.ppt page 21
Selectors and Descriptors
• Two descriptor tables: 8192 descriptors each
–global descriptor table (GDT)
• system descriptors contain segment definitions that apply to
all programs
• GDT register (GDTR) contains the linear address of the
base of the GDT
–local descriptor table (LDT)
• application descriptors are usually unique to an application
• LDT register (LDTR) contains the linear address of the base
of the LDT
•Descriptor
–describing location, length, and access rights of the segment
–8 bytes in length, 8192 * 8 = 64KB per descriptor table
–descriptor 0 is called null descriptor and may not be used
•Selector: located in the segment register
–selects one of 8192 descriptors from one of two descriptor tables
–8192*2 memory segments described for each applications
JT/YHC/EIE311/2002/CSF_ch2.ppt page 22
Descriptor Format
JT/YHC/EIE311/2002/CSF_ch2.ppt page 24
The access rights byte for the
80286 through Pentium 4 descriptor
JT/YHC/EIE311/2002/CSF_ch2.ppt page 25
Format of Segment Register
JT/YHC/EIE311/2002/CSF_ch2.ppt page 27
Program-Invisible Registers
The are not directly addressed by software, these registers
control the microprocessor when operated in the protected.
Each segment registers contains aprogram invisible portion,
often called cache memory.
These cache is loaded with base address, limit, access rights
each time the number in the segment register is changed.
This allows repeatedly access a memory segment with out
referring the Descriptor table, each time.
GDTR and IDTR (interrupt descriptor table register)
contains the base address of the descriptor table and its
limit , and are initialized before using the protected mode.
LDTR is loaded with a selector with in GDT, ie one of the
global descriptor is set up to address LDT.
JT/YHC/EIE311/2002/CSF_ch2.ppt page 28
Program-Invisible Registers
•TR (task register) holds a selector, which
accesses a descriptor that defines a task
JT/YHC/EIE311/2002/CSF_ch2.ppt page 29
Memory Paging
• Memory paging mechanism
– 80386 and above
– Any physical memory location can be assigned to any
linearAddress
- Linear address means address generated by a program.
– 4KB-page boundary (or 4MB-page boundary in Pentium)
• Advantages
– A linear address is invisibly translated into a physical
address
– Allows memory to be placed into areas where no memory
exists
• Paging mechanism can be used in both real and protected modes
• EMM386.EXE: reassign extended memory, in 4K blocks, to the
system memory between video BIOS and the system BIOS
ROMS for upper memory blocks
JT/YHC/EIE311/2002/CSF_ch2.ppt page 30
Paging Registers
Paging unit is controlled by the mp’s control registers.
Paging Control Registers (CR0-CR4)
• CR0-CR3 – 80386 and above
• CR4: only for Pentium and above (support 4MB paging)
PCD : 1 PCD (page level cache disabled) pin of MP becomes one indicates
during bus cycle that are not pages(for controlling L2 cache).
PWT : 1 PWT(page level write transparent) pin of MP becomes high
indicates during bus cycle that are not pages(for controlling write
through cache).
JT/YHC/EIE311/2002/CSF_ch2.ppt page 31
Control register structure
JT/YHC/EIE311/2002/CSF_ch2.ppt page 32
Linear Address Format
Page directory entry: leftmost 10 bits (4 M bytes in size),
e.g., linear addresses 0000 0000H to 003F FFFFH
address 1st page (page 0)
Page table entry: contains the next 10 bits (4 K byte range)
after the page directory entry, e.g., 0000 0000H to 0000
0FFFH refer to both directory and table equal 0
Page offset address: selects a byte in the 4K byte memory
page
JT/YHC/EIE311/2002/CSF_ch2.ppt page 33
TLB – (translation look-aside buffer)
TLB is a dedicated cache (queue) structure to
hold the 32 most recent page directory and table
entries
Pentium+ processors have TLBs for each data and
instruction caches
A page table or page directory entry
JT/YHC/EIE311/2002/CSF_ch2.ppt page 34