What are the physical addresses for the following logical addresses

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?

  1. 0, 430
  2. 1, 11
  3. 2, 100
  4. 3, 425
  5. 4, 95

 

Calculate the physical address if no trap is produced.

 

Solution-

 

In a segmentation scheme, the generated logical address consists of two parts-

  1. Segment Number
  2. 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

What are the physical addresses for the following logical addresses

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. 

What will be the physical addresses for the given logical addresses?

The Logical Address is generated by the CPU while the program is running and the Physical Address is the location inside the main memory. The Logical Address is Virtual and the Physical Address is the actual address of the memory.

How to find physical address from logical address in segmentation?

Segment 0, Logical Address is 430 - So physical address becomes - 219+430 = 649 b. Segment 1, Logical Addres is 10 - So physical address becomes - 2300+10 = 2310.

What is physical & logical address?

Logical and physical addresses are important terms. The logical address is rendered by CPU while a program is executed, whereas the physical address directs to a location in the memory unit. Let's figure out some major differences between logical and physical addresses.

How many logical address can a physical address have?

Just as the number 4 can be named as 0+4 , 1+3 , 2+2 , etc., the address 12345 can be expressed as 1234:0005 , 1233:0015 , 1230:0045 , and so on. In other words, each physical address has 64k different logical addresses.