Computer Science, asked by DevduttNair6484, 1 year ago

Question : Write algorithm for the following: Change the visibility attribute of a segment, Delete a

segment, Delete all segment​

Answers

Answered by puneetgoyal12
1

Answer:

Closing a Segment : After completing entry of all display file instructions, the segment needs to be closed for which it has to be renamed, which is done by changing the name of currently open segment as 0. Now the segment with name 0 is open i.e. unnamed segment is open and if two unnamed segments are present in display file one needs to be deleted.

Algorithm :

If any segment is not open, give error message : “No segment is open now” and go to step 6.

Change the name of currently opened segment to any unnamed segment, lets say 0.

Delete any other unnamed segment instruction which may have been saved and initialize above unnamed segment with no instructions.

Make the next free storage area available in display file as start of the unnamed segment.

Initialize size of unnamed segment to 0.

Stop.

Deleting a Segment : To delete a particular segment from display file, we must just delete that one segment without destroying or reforming the entire display and recover space occupied by this segment. Use this space for some other segment. The method to achieve this depends upon the data structure used to represent display file. In case of arrays, the gap left by deleted segment is filled by shifting up all the segments following it.

Algorithm :

Read the name of the segment to be deleted.

If segment name is not valid, give error message : “Segment name is not a valid name” and go to step 8.

If the segment is open, give error message : “Can’t delete an open segment” and go to step 8.

If size of segment is less than 0, no processing is required and go to step 8.

The segments which follow the deleted segment are shifted by its size.

Recover deleted space by resetting index of next free instruction.

The starting position of shifted segments is adjusted by subtracting the size of deleted segment from it.

Stop.

Similar questions