1 - MICROPROCESSOR UNIT III QP & Solution - 1
1 - MICROPROCESSOR UNIT III QP & Solution - 1
SE-SEM IV
UNIT III
MEMORY MANAGEMENT
Q1. Differentiate and explain GDTR, LDTR, and IDTR. in 80386 microprocessors.
In summary:
OR
Q3. Explain the Segment Translation Process with a neat diagram of 80386.
ANS-
Segment Translation:
● The processor uses the following data structures for segment translation:
o Descriptors: These provide the necessary information to map a logical
address to a linear address.
o Descriptor tables: Segment descriptors are stored in either the Global
Descriptor Table (GDT) or the Local Descriptor Table (LDT).
● Linear Address to Physical Address Conversion:
o Once we have the linear address, it undergoes further translation
using paging hardware to obtain the physical address.
ANS- A descriptor is a series of 8 bytes that describe and locate a memory segment.
• It contains 32-bit base address that specifies the beginning of the segment of
memory controlled by the descriptor.
• The size of segment is indicated by a 20-bit limit field and the state of the
Granularity Bit (G bit)
• A segment descriptor provides the 80386 with the data it needs to map a logical
• These descriptors are not created by programs, but created by Compilers, Linkers,
• This allows the size of segment to be of any length from 4KB to 4GB.
• When this bit is cleared (G = 0) the 20-bit limit field is assumed to be measured in
units of 1 byte. If it is set (G = 1), the limit field is in units of 4 KB.
• Two Descriptor Privilege Level (DPL) bits specifies the privilege level required to
access the segment.
S (Segment Descriptor): When set, indicate that the segment is a system segment.
When clear, the segment is a code or data segment.
D (Default Operation Size): For code segment, D controls the default operand and
address size (16 bit when D is clear versus 32 bit when set).
For data segment, D controls how stack is manipulated (via SP /ESP with 16/32 bit
pushes/pops)
The AVL (available) field specifies whether the descriptor is available for user or it is
for use by operating system.
E (Executable):
Executable selects a stack segment (E=0) or a code segment (E=1) .E also defines
the function of the next two bits.
X (Expansion):
If E=0, then X indicates the direction of expansion for the data segment. If X=0, the
segment expands upward, as in a data segment.
RW(Read/Write):
If E=0, then the read/write bit indicate that the data segment may be written or not.
If E=1, then RW indicate that the code segment maybe read (RW=0) or not read
(RW=1).
A (Accessed Bit):
Accessed is set each time that the microprocessor accesses the segment. It is
sometimes used by operating system to keep track of which segments have been
accessed.
Q5. With the necessary diagram, explain the page translation process in 80386.
ANS-
• Page translation
Once the logical address converted into linear address in segment translation, the
80386 transforms a linear address into a physical address.
• Each page directory entry addresses a page table that contains 1024 entries.
Each Page Directory Entry contains the
• The upper 10 bits of the linear address (A22±A31) are used as an index to select
the correct Page Directory Entry.
• D: The D (Dirty) bit 6 is set to 1 before a write to an address covered by that page
table entry occurs.
• A: The A (Accessed) bit 5, is set by the Intel386 DX for both types of entries before
a read or write access occurs to an address covered by the entry.
• U/S and R/W: These bits are used to provide User/ Supervisor and Read/Write
protection for individual pages.
• P: The P (Present) bit 0 indicates if a Page Directory or Page Table entry can be
used in address translation. – If P=1theentry can be used for address translation.
• Each Page Table is 4K bytes and holds up to 1024 Page Table Entries.
• Page Table Entries have the starting address of the page frame and statistical
information about the page.
• The 20 upper bit page frame address is concatenated with the lower 12 bits of the
linear address to form the physical address.
▪ Similar to LGDT, LLDT can use either a 16-bit operand (16-bit limit,
24-bit base) or a 32-bit operand (16-bit limit, 32-bit base).
▪ LLDT m16&32: Load the LDTR with the base address and limit
from the specified memory location.
▪ LLDT is used less frequently than LGDT and SIDT.
▪ It is essential for managing per-task segment descriptors.
Q7. What is call gate? Explain how it is used in calling functions with higher
privilege levels.
ANS-
• A Word Count which specifies how many parameters are to be copied from the
caller's stack to the stack of the called routine.
• The Word Count field is only used by call gates when there is a change in the
privilege level, other types of gates ignore the word count field.
Q8. Differentiate and explain the Interrupt gate and Trap gate descriptor.
ANS-
• Interrupt and Trap Gates use the destination selector and destination offset fields of
the gate descriptor as a pointer to the start of the interrupt or trap handler routines.
• The difference between interrupt gates and trap gates is that the interrupt gate
disables interrupts (resets the IF bit) while the trap gate does not.
Q 9. Explain the use of following instructions in detail: i) SGDT ii) LIDT iii) SLDT.
ANS-
1. SGDT (Store Global Descriptor Table Register):
o Opcode: 0F 01 /0
o Description: Copies the contents of the Global Descriptor Table
Register (GDTR) into the six bytes of memory indicated by the operand.
o Operand Size: If the operand-size attribute is 32 bits, the next three
bytes are assigned the base address of the GDTR.
o Usage: Primarily used in operating system software, not in application
programs.
o Flags Affected: None.
o Exceptions:
▪ #GP (0) if the result is in a non-writable segment.
▪ #GP (0) for an illegal memory operand effective address in the
CS, DS, ES, FS, or GS segments.
▪ #SS (0) for an illegal address in the SS segment.
▪ #PF (fault-code) for a page fault.
o Real Address Mode Exceptions: Interrupt 6; SGDT is not recognized in
Real Address Mode.
o Virtual 8086 Mode Exceptions: Same exceptions as in Real Address
Mode; #PF (fault-code) for a page fault.
2. LIDT (Load Interrupt Descriptor Table Register):
o Opcode: 0F 01 /3
o Description: Loads the contents of the Interrupt Descriptor Table
Register (IDTR) from the six bytes of memory indicated by the operand.
o Operand Size: If the operand-size attribute is 32 bits, the next three
bytes are loaded into the IDTR.
o Usage: Used to set up interrupt handling in protected mode.
o Flags Affected: None.
o Exceptions:
▪ #GP (0) if the result is in a non-writable segment.
▪ #GP (0) for an illegal memory operand effective address in the
CS, DS, ES, FS, or GS segments.
▪ #SS (0) for an illegal address in the SS segment.
▪ #PF (fault-code) for a page fault.
o Real Address Mode Exceptions: Interrupt 6; LIDT is not recognized in
Real Address Mode.
o Virtual 8086 Mode Exceptions: Same exceptions as in Real Address
Mode; #PF (fault-code) for a page fault.
3. SLDT (Store Local Descriptor Table Register):
o Opcode: 0F 00 /0
o Description: Stores the contents of the Local Descriptor Table Register
(LDTR) in the two-byte register or memory location indicated by the
effective address operand.
o Usage: Exclusively used in operating system software, not in
application programs.
o Flags Affected: None.
o Exceptions:
▪ #GP (0) if the result is in a non-writable segment.
▪ #GP (0) for an illegal memory operand effective address in the
CS, DS, ES, FS, or GS segments.
▪ #SS (0) for an illegal address in the SS segment.
▪ #PF (fault-code) for a page fault.
Q 10. Enlist various types of system and non-system descriptors in the 80386.
Explain their use in brief.
ANS-
1. System Descriptors:
o Global Descriptor Table (GDT): The GDT contains segment descriptors for
both system and user programs. It’s a crucial data structure used by the
processor to map logical addresses to linear addresses. Descriptors in the
GDT provide information about segment location, size, and access
permissions.
o Interrupt Descriptor Table (IDT): The IDT holds descriptors for interrupt
service routines (ISRs). These descriptors define how the processor handles
various hardware and software interrupts.
o Local Descriptor Table (LDT): The LDT is an optional table that can be used to
store additional segment descriptors. It’s similar to the GDT but is specific to a
particular task or process.
o Task State Segment (TSS): The TSS descriptor provides information about the
task state, including stack pointers, privilege levels, and other task-related
data. It’s used during task switching and context switching.
2. Non-System Descriptors:
o Code Segment Descriptor: Used for executable code, such as program
instructions. It specifies the base address, limit, and access rights for code
segments.
o Data Segment Descriptor: Used for data storage. Similar to the code segment
descriptor, it defines the base address, limit, and access rights for data
segments.
o Stack Segment Descriptor: Used for stack operations. It provides information
about the stack’s location and size.
o Gate Descriptors: These are special descriptors used for interrupt gates, trap
gates, and call gates. They facilitate transitions between different privilege
levels and handle interrupts and exceptions.
Ans-
• The Intel386 DX keeps a cache of the most recently accessed pages, this cache is
called the Translation Look-aside Buffer (TLB).
• The 32-entry TLB coupled with a 4K page size,results in coverage of 128K bytes of
memory addresses.
• The paging unit hardware receives a 32-bit linear address from the segmentation
unit.
• The upper 20 linear address bits are compared with all 32 entries in the TLB to
determine if there is a match.
• If there is a match (i.e. a TLB hit), then the 32 bit physical address is calculated and
will be placed on the address bus.
ANS-
• Demand Paging follows that pages should only be brought into memory if the
executing process demands them.
• This is often referred to as Lazy Evaluation as only those pages demanded by the
process are swapped from secondary storage to main memory.
2. Allocating Memory
• Majority of memory is used by OS, Memory resident Programs and other user’s
programs, or memory maynotbeavailable.
• So as per requirement of new task, memory will be made free by swapping out data
to secondary memory.
2. Allocating Memory
• System will check A bit (Bit 5) from PTE of every page, and accordingly pages will
be allocated.
• If accessed bit has not be set by the system, meaning is that 4 KB page frame is
never references by the processor.
• After completing copy from the page, P bit from PTE will be set again, as new valid