Before you go through this article, make sure that you have gone through the previous article on Segmentation in OS.
We have discussed-
- Like Paging, Segmentation is another non-contiguous memory allocation technique.
- Segmentation divides the process into meaningful segments.
- Segment table stores the information about each segment of the process.
In this article, we will discuss a practice problem based on segmentation.
PRACTICE PROBLEM BASED ON SEGMENTATION-
Problem-
Consider the following segment table-
Segment No.BaseLength012197001230014290100313275804195296
Which of the following logical address will produce trap addressing error?
- 0, 430
- 1, 11
- 2, 100
- 3, 425
- 4, 95
Calculate the physical address if no trap is produced.
Solution-
In a segmentation scheme, the generated logical address consists of two parts-
- Segment Number
- Segment Offset
We know-
- Segment Offset must always lie in the range [0, limit-1].
- If segment offset becomes greater than or equal to the limit of segment, then trap addressing error is produced.
Option-A: 0, 430-
Here,
- Segment Number = 0
- Segment Offset = 430
We have,
- In the segment table, limit of segment-0 is 700.
- Thus, segment offset must always lie in the range = [0, 700-1] = [0, 699]
Now,
- Since generated segment offset lies in the above range, so request generated is valid.
- Therefore, no trap will be produced.
- Physical Address = 1219 + 430 = 1649
Option-B: 1, 11-
Here,
- Segment Number = 1
- Segment Offset = 11
We have,
- In the segment table, limit of segment-1 is 14.
- Thus, segment offset must always lie in the range = [0, 14-1] = [0, 13]
Now,
- Since generated segment offset lies in the above range, so request generated is valid.
- Therefore, no trap will be produced.
- Physical Address = 2300 + 11 = 2311
Option-C: 2, 100-
Here,
- Segment Number = 2
- Segment Offset = 100
We have,
- In the segment table, limit of segment-2 is 100.
- Thus, segment offset must always lie in the range = [0, 100-1] = [0, 99]
Now,
- Since generated segment offset does not lie in the above range, so request generated is invalid.
- Therefore, trap will be produced.
Option-D: 3, 425-
Here,
- Segment Number = 3
- Segment Offset = 425
We have,
- In the segment table, limit of segment-3 is 580.
- Thus, segment offset must always lie in the range = [0, 580-1] = [0, 579]
Now,
- Since generated segment offset lies in the above range, so request generated is valid.
- Therefore, no trap will be produced.
- Physical Address = 1327 + 425 = 1752
Option-E: 4, 95-
Here,
- Segment Number = 4
- Segment Offset = 95
We have,
- In the segment table, limit of segment-4 is 96.
- Thus, segment offset must always lie in the range = [0, 96-1] = [0, 95]
Now,
- Since generated segment offset lies in the above range, so request generated is valid.
- Therefore, no trap will be produced.
- Physical Address = 1952 + 95 = 2047
Thus, Option-[C] is correct.
To watch video solution and practice other problems,
Watch this Video Lecture
Next Article- Segmented Paging in OS
Get more notes and other study material of Operating System.
Watch video lectures by visiting our YouTube channel LearnVidFun.
Summary
Article Name
Segmentation in OS | Practice Problems
Description
Practice Problems based on Segmentation in OS. Segmentation in OS is a non-contiguous memory allocation technique. Unlike Paging, Segmentation divides the process into segments.
Physical Address identifies a physical location of required data in a memory. The user never directly deals with the physical address but can access by its corresponding logical address. The user program generates the logical address and thinks that the program is running in this logical address but the program needs physical memory for its execution, therefore, the logical address must be mapped to the physical address by MMU before they are used. The term Physical Address Space is used for all physical addresses corresponding to the logical addresses in a Logical address space.