Professional Documents
Culture Documents
2.0 Outcomes
2. List and describe the function of the 80386 registers and flags
users. The most common family members are the 80386DX and the 80386SX. Table 2.1 lists
the specification for the data and address buses of the SX and DX versions of the 80386
microprocessor. Both the SX and the DX versions of the 80386 can operate in either real mode
or protected mode. In the real mode the 80386 microprocessor operates like a powerful 80286
(16-bit microprocessor) and thus can address only 1 MB of memory. In the protected mode the
80386 can access the entire memory space. In this book only the real mode will be discussed.
80386 DX 80386 SX
• 32-bit data bus. Thus 32 bit • 16-bit data bus. Thus, only up to
data transfer is possible 16 bit data transfer is possible
• 32-bit address bus. Thus, can • 24-bit address bus. Thus, can
address up to 4 Gigabyte of address up to 16 megabyte of
memory memory
2.2 Real Mode Model
To enable a programmer to write assembly programs for the 80386 family of microprocessors, a
software model of the internal architecture of the microprocessor is needed. The model
basically describes the registers and flags available for the programmer use.
2.2.1 Registers
A register is a place where data can be stored and manipulated. The registers of 80386
microprocessors can broadly classified into two groups: General-purpose registers, and special
purpose registers
There are 4 data registers that can be used to store data temporarily during the execution of
program instructions. These can be used as the destination or the source for any data
movement instruction. These registers can be used as 8-bit (for example AL or AH) so that
programs written on Intel 8-bit microprocessors can be executed on the 80386 in real mode.
They can also be used as 16-bit (for example AX) to allow 80286 codes to run by the 80386.
Although, these registers are called general purpose, there are certain operations that only
possible on a given register. Table 2.1 lists the 4 general-purpose data registers and the
The 4 registers in this group can be used either as 16-bit or 32-bit registers. These registers are
used to hold the offset of the address of the data held in memory. The other part of the
address, the segment address, is normally held by a segment registers. Table 2.2 describes the
Stack Pointer SP ESP Used to hold the offset address of the stack
registers, the flags register, the instruction pointer, and control registers.
2.2.1.2.1 The Segment Registers
The six segment registers are 16 bits wide. Each segment register holds the base memory
address for a 64K-memory segment. Table 2.4 briefly describes the usage of the segment
registers.
The instruction pointer (EIP) is a 32-bit register. This register is used with the code segment
register (CS) to hold the address of the next instruction to be fetched from the code segment of
the memory.
Although, the 80386 microprocessor has several control registers, only one of them control
register zero is active in real-mode. The five least-significant digits are called the machine status
word (MSW). In real-mode, only bit 0 of the control register zero is active. This bit is called the
the first nine bits are used. These are the same as those for the 80286 microprocessor. The first
six are called status flags because their states (set or reset) change as a result of executing
certain instructions. The last three flags are control flags used to control the operations of the
80386 microprocessor. The name and usage of these flags are summarised in Table 2.5
virtual (logical) memory and how the virtual memory is mapped into the physical memory
physical memory. Each memory location has an address. These addresses are linearly ordered
from 0 to M. The value of M indicates the maximum storage capacity of the computer memory.
Address M Content
Address 0 Content
Figure 2.1
executed by the processor. This address needs to be translated into a physical address to
access the data stored in the memory. This translation can be done by the processor itself or by
The memory architecture in which any memory location (physical address) can be selected from
a single contiguous block by a single integer offset (logical address) is called flat addressing.
Thus, in this addressing mode there is a one to one correspondence between logical addresses
and physical addresses. A flat address space greatly simplifies programming because of the
Memory segmentation is the division of computer's primary memory into segments or sections.
includes a value that identifies a segment and an offset within that segment. Thus, the logical
address is made of two components: A segment and an offset. Different segments may be
created for different program modules, or for different classes of memory usage such as code
and data segments. Certain segments may even be shared between programs.
bits wide respectively. Thus, the maximum addressable memory space is 224 bytes and 232 bytes
for the SX and DX respectively. However, in real mode, only 20 bits are used for memory
addressing thus, the maximum addressable memory is 220 = 1048576 bytes which is equivalent
to 1 Mbytes. The logical address generated by the process being executed by the 80386 is
always made up of two components: A segment address stored in one the segment registers
and an offset address stored in one of the index and pointer registers. Thus, the logical address
is 32 bits but the physical address is only 20 bits. The memory management unit in the
microprocessor translates the 32 bits logical address into a 20 bits physical address as shown in
Figure 2.2.
Logical Address
Adder
Figure 2.2
Table 2.6 shows few examples of this mapping. As can be seen from Table 2.6 it is possible
that more than one logical address produce the same physical address. In fact any given
As mentioned earlier, the logical address is formed from a segment address held in a segment
register and an offset address. The offset address is obtained from one of the general purpose
or special purpose registers or from a combination of both depending on the type of access to
be performed by the microprocessor. Each segment register has a default offset register as
shown in Table 2.7. This default segment-offset relationship can be overridden for certain
operations by specifying the name of the segment to be used in front of the offset register.
selected. In TASM, the .model directive specifies one of several models. The number and type
of segments that each model type specifies are given in Table 2.8
Table 2. 8
Medium Multiple 1 1
Compact 1 Multiple 1
Large Multiple Multiple 1 All data and code are far by default.