0% found this document useful (0 votes)
12 views15 pages

SPOS Lab Manual (2019 Pattern)

Short notes

Uploaded by

aartigpatil2009
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views15 pages

SPOS Lab Manual (2019 Pattern)

Short notes

Uploaded by

aartigpatil2009
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

TE: 310248: Laboratory Practice I

Adsul Technical Campus


Department of Computer Engineering

Lab Manual
of
Laboratory Practice
I (310248)

Class: TE
Semester: V
Pattern: 2019

Department of Computer Engineering , ATC,Chas


TE: 310248: Laboratory Practice I

INDEX
ASSN
TITLE
NO.
Part I: Systems Programming and Operating System

Group A
Design suitable Data structures and implement Pass-I and Pass-II of a two-pass
1 assembler for pseudo-machine. Implementation should consist of a few instructions
from each category and few assembler directives. The output of Pass-I (intermediate
code file and symbol table) should be input for Pass-II.
Design suitable data structures and implement Pass-I and Pass-II of a two-pass macro-
2 processor. The output of Pass-I (MNT, MDT and intermediate code file without any
macro definitions) should be input for Pass-II.
Group B
Write a program to simulate Memory placement strategies – best fit, first fit, next
3
fit and worst fit.
4 Write a program to simulate Page replacement algorithm.

Department of Computer Engineering , ATC,Chas


TE: 310248: Laboratory Practice I

Assignment No- A1

Title: Pass I and II of a two pass assembler.

Objectives:
 To study assembler.
 To understand algorithm of Pass-I.
 To implement assembler pass-I using JAVA programming language.
 To study Pass-II of a two pass assembler.
 To implement Pass-II using JAVA Programming language.

Problem Statement: Design suitable Data structures and implement Pass-I and Pass-II of a
two-pass assembler for pseudo-machine. Implementation should consist of a few instructions
from each category and few assembler directives. The output of Pass-I (intermediate code file
and symbol table) should be input for Pass-II.

Outcomes:
 Understand Pass I of two pass assembler.
 Implement Pass-I using JAVA.
 Understand Pass II of two pass assembler.
 Implement Pass-II using JAVA.

Software Requirements:

 Operating System : Ubuntu or Fedora


 JDK/ JRE
 Eclipse

Hardware Requirements:

 64 bit machine
 4GB or 8 GB RAM
 500 GB or 1TB HDD

Theory:
An assembler is a program that takes basic computer instructions and converts them into a
pattern of bits that the computer's processor can use to perform its basic operations. Some
people call these instructions assembler language and others use the term assembly language.

Department of Computer Engineering , ATC,Chas


TE: 310248: Laboratory Practice I

Here's how it works:

 Most computers come with a specified set of very basic instructions that correspond to
the basic machine operations that the computer can perform. For example, a "Load"
instruction causes the processor to move a string of bits from a location in the
processor's memory to a special holding place called a register. Assuming the
processor has at least eight registers, each numbered, the following instruction would
move the value (string of bits of a certain length) at memory location 3000 into the
holding place called register 8:

L 8,3000

 The programmer can write a program using a sequence of these assembler


instructions.
 This sequence of assembler instructions, known as the source code or source program,
is then specified to the assembler program when that program is started.
 The assembler program takes each program statement in the source program and
generates a corresponding bit stream or pattern (a series of 0's and 1's of a given
length).
 The output of the assembler program is called the object code or object program
relative to the input source program. The sequence of 0's and 1's that constitute the
object program is sometimes called machine code.
 The object program can then be run (or executed) whenever desired.

In this assignment we make use of Hashing for our Mneumonic table.This is to reduce the
overhead required to search a mneumonic in the mneumonic table.

The output of this program is going to be the input to Pass II hence we write all the tables and
IC to a File.

Thus the requisites for this assignment are File handling and Table handling method of
Hashing.

The Mneumonic table has been designed using hash function = ([addition of ascii of
all alphabets of a mneumonic] mod 10 or 20)

Department of Computer Engineering , ATC,Chas


TE: 310248: Laboratory Practice I

Algorithm for Pass -I:-


1. Initialize LC=0 (default), Pooltab_ptr=1, pooltab[1]:=1,
littab_ptr=1 Read source file.
2. While next statement is not END.
a. If string=Label then enter it in symbol table.
b. If string=START then LC=operand value of START.
c. IF EQU then address=value of <address spec>, correct symbol table entry for the label
to the address spec.
d. If DS then
 Code=code of DS
 Size=size of memory area required by DC/DS.
 LC=LC+size
 General IC(DL,code)
e. If an IS then
 code=machine opcode from optab(mneumonic table).
 LC=LC+length of instruction from optab.
 If operand is a literal then
i)this_literal=literal in operand field.
ii)LITTAB[littab_ptr]=this_literal
iii)littab_ptr=littab_ptr+1
else
this_entry=Symbol table entry

f. If an LTORG statement then


 Process literals LITTAB[POOLTAB[pooltab_ptr]]…LITTAB[littab_ptr-1] to
allocate Memory and put the address in the address field. Update LC accordingly.
 Pooltab_ptr=pooltab_ptr+1
 POOLTAB[pooltab_ptr]=littab_ptr
3. (Processing of END statement)
a. Perform step 2f
b. Generate IC
c. Write all the tables and IC on to files.

Department of Computer Engineering , ATC,Chas


TE: 310248: Laboratory Practice I

Algorithm for Pass II:-


1. code_area_address=address of code area , pooltab_ptr=1 LC=0
2. While next statement is not END
statement. a.Clear machine buffer.
b. If an LTORG statement then
 Process literals LITTAB[POOLTAB[pooltab_ptr]]…LITTAB[littab_ptr+1] -1
similar to processing of constants in DC statement.assemble the literals in
machine_code_buffer.

 Size=size of memory area required for literals


 Pooltab_ptr=pooltab_ptr+1
c. If START statement then LC=value specified in operand field,size=0
d. If DS then assemble the constant in machine code buffer.
e. If IS then
 Get operand address from SYMTAB or LITTAB
 Assemble instruction in machine code buffer.
 Size=size of instruction.
 If Address of any symbol is missing generate ERROR for 'UNDEFINED SYMBOL'

f. If size!= 0 then
 Move contents of machine code buffer to the address code area+LC
 LC=LC+size
3. Processing of END statement
 Perform steps 2b and 2f
 Perform Error handling
 Write code to output file.
4. Stop.

Conclusion: Thus we have successfully studied and implemented the pass I and pass II of two pass
assembler.

Department of Computer Engineering , ATC,Chas


TE: 310248: Laboratory Practice I

Assignment No- A2

Title: Pass I and Pass II of a two pass Macro-Processor

Objectives:
 To study Pass-I of a two pass macro processor.

 To implement Pass-I using JAVA Programming.


 To implement Pass-II of a two pass macro processor.

 To study algorithm of Pass-II of a two pass macro processor.

Problem Statement: Design suitable data structures and implement Pass-I and Pass-II of a
two-pass macro- processor. The output of Pass-I (MNT, MDT and intermediate code file
without any macro definitions) should be input for Pass-II.

Outcomes:
 Understand algorithm of pass-I of a two pass macro processor.

 Study algorithm of pass-I of two pass macro processor.

Software Requirements:

 Operating System : Ubuntu or Fedora


 JDK/ JRE
 Eclipse
Hardware Requirements:

 64 bit machine
 4GB or 8 GB RAM
 500 GB or 1TB HDD

Theory:
Macro instruction is a notational convenience for the programmer.
It allows the programmer to write shorthand version of a program (module programming)
The macro processor replaces each macro invocation with the corresponding sequence of
statements

Department of Computer Engineering , ATC,Chas


TE: 310248: Laboratory Practice I

Macro
» the statement of expansion are generated each time the macro are invoked

Argument substitutions
Dummy arguments
» Positional argument

STRG DATA1, DATA2,


DATA3 GENER,,DIRECT,,,,,,3
» Keyword argument
STRG &a3=DATA1, &a2=DATA2, &a1=DATA3 GENER
TYPE=DIRECT, CHANNEL=3
Data Structures used :-
MNT(Macro name table):-Stores the names of all macros alongwith their MDT index.
MDT(Macro Definition Table):-Stores the definition of macro
ALA(Argument List Array):-To store formal v/s actual arguments
Eg:- Consider the following Macro definition and the tables constructed in pass I for this
macro

MACRO
&LAB INCR &ARG1,&ARG2,&ARG3
&LAB ADD 1,&ARG1

ADD 2,&ARG2
ADD 3,&ARG3

Department of Computer Engineering , ATC,Chas


TE: 310248: Laboratory Practice I

MEND
Output:-
MNT
Index Macro MDT Index
Name
1 INCR 1

MDT
Index Label Instruction operands
1 #0 ADD 1, #1
2 ADD 1, #2
3 ADD 1, #3
4 MEND
ALA
Argument Dummy name
&Lab #0
&Arg1 #1
&Arg2 #2
&Arg3 #3

Steps to follow:-
2. Read the ALP word by word using

fgetc. 2.If keyword MACRO is found then


 Store the arguments in ALA in sequence(0th argument for a label).
 Store all the instructions in MDT using dummy names of the arguments(prepared
in ALA).
 Store the MDT index in a variable temp.
 Store name of macro and its MDT index using temp in
MNT. 3.Write all the tables onto a file (as these will be required in
pass II) 4.Go to Pass I

Department of Computer Engineering , ATC,Chas


TE: 310248: Laboratory Practice I

The task of pass II is macro expansion i.e deal with macro calls. For this we use the tables created in pass I of
a macro-processor. Whenever a call to a macro is found for eg:-

LOOP INCR Data1,Data2,Data3


(with respect to the macro definition INCR in previous assignment)
Then this call should lead to a macro expansion as follows:-

LOOP : ADD 1 , Data1

ADD 2 ,

Data2 ADD

3,

Data3

Here the formal parameters are replaced by actual parameters.

For this ALA has to be updated with new parameter names.

ALA
Argument Actual
Parameters
#0 LOOP
#1 Data1
#2 Data2
#3 Data3

Using these values we expand the macro with the help of MNT and MDT.

Steps to follow:-
1. Read the source program.

2. If an macro name is encounterd it means there is a call to the macro so do the following.

 Search for the macro in the MNT.


 Extract its MDT index and go to that index position in MDT.
 Update ALA with actual parameters.
3. Read from MDT and replace dummy parameters with actual parameters.

4. Do step 3 till end of macro.

Department of Computer Engineering , ATC,Chas


Conclusion:- Thus we have successfully studied and implemented the pass I and pass II of two
pass macro-processor.

Department of Computer Engineering , ATC,Chas


TE: 310248: Laboratory Practice I

Assignment No- B1
Title: Write a program to simulate Memory placement strategies – best fit, first fit, next fit and worst fit.

Objectives:

 Understand Memory Allocation Techniques

 Compare Performance of Strategies

 Improve System Efficiency

 Handle Allocation Failures

 Support Educational Learning

 Test System Design Decisions

 Demonstrate Trade-offs

Problem Statement: Write a program to simulate Memory placement strategies – best fit, first fit, next fit and worst
fit.

Outcomes:
The simulation of memory placement strategies—First Fit, Next Fit, Best Fit, and Worst Fit—successfully
demonstrates how operating systems manage memory allocation for processes under various scenarios. After running
the simulation with different sets of memory blocks and process sizes, the following outcomes were observed.

Software Requirements:

 Operating System : Ubuntu or Fedora


 JDK/ JRE
 Eclipse
Hardware Requirements:

 64 bit machine
 4GB or 8 GB RAM
 500 GB or 1TB HDD

Department of Computer Engineering , ATC,Chas


TE: 310248: Laboratory Practice I

Theory:

When a program requests memory during execution, the operating system must allocate a suitable portion of
free memory to fulfill that request. This is known as dynamic memory allocation. The OS maintains a list of
free memory blocks (called holes), and it must decide where to place the new process or data.

The memory placement strategy is the algorithm used to select the appropriate free block from the list.

1. First Fit

 The allocator scans the list of free blocks from the beginning.
 The first block found that is large enough to accommodate the requested memory size is chosen.
 The block is then split if larger than needed, and the remainder remains free.

2. Next Fit

 Similar to first fit but does not restart searching from the beginning every time.
 It continues searching from the point where it last allocated memory.
 If it reaches the end of the list, it wraps around to the beginning.

3. Best Fit

 The allocator searches the entire list of free blocks.


 It selects the smallest free block that is large enough to fulfill the request.
 The goal is to minimize leftover free space in the allocated block.

4. Worst Fit

 The allocator searches the entire list of free blocks.


 It selects the largest free block available.
 The idea is to leave a large leftover free block after allocation.

Conclusion

Memory placement strategies play a crucial role in managing dynamic memory allocation efficiently in
operating systems. Each strategy—First Fit, Next Fit, Best Fit, and Worst Fit—offers a different trade-off
between allocation speed and memory utilization.

 First Fit and Next Fit prioritize speed by quickly finding a suitable block, but may lead to
fragmentation over time.
 Best Fit aims to minimize wasted space by selecting the smallest adequate block but may increase
fragmentation and allocation time.
 Worst Fit tries to preserve large free blocks by allocating from the largest space available, but it may
cause inefficient memory use.
Department of Computer Engineering , ATC,Chas
TE: 310248: Laboratory Practice I

Assignment No- B2

Title: Implement Paging Algorithms 1.LRU 2. Optimal Page Replacement.

Objectives:
 To study page replacement strategies.

 To implement paging algorithm using JAVA Programming language

Problem Statement: Write a program to simulate Page replacement algorithm.

Outcomes:
 Understand page replacement policies.
 Handle LRU and optimal algorithm using JAVA Programming language.

Software Requirements:
 Operating System : Ubuntu or Fedora
 Eclipse
 JDK/JRE

Hardware Requirements:
 64 bit machine
 4GB or 8 GB RAM
 500 GB or 1TB HDD
Theory:

Page Fault:-An interrupt that occurs when a program requests data that is not currently in real
memory. The interrupt triggers the operating system to fetch the data from a virtual memory
and load it into RAM.

Page Replacement Algorithms

1. Least recently used

The least recently used page (LRU) replacement algorithm, though similar in name to NRU,
differs in the fact that LRU keeps track of page usage over a short period of time, while NRU
just looks at the usage in the last clock interval. LRU works on the idea that pages that have
been most heavily used in the past few instructions are most likely to be used heavily in the
next few instructions too. While LRU can provide near-optimal performance in theory (almost
as good as Adaptive Replacement Cache), it is rather expensive to implement in practical.

Department of Computer Engineering , ATC,Chas


TE: 310248: Laboratory Practice I

2. Optimal Page Replacement Algorithm

When a page needs to be swapped in, the operating system swaps out the page whose next use
will occur farthest in the future. For example, a page that is not going to be used for the next 6
seconds will be swapped out over a page that is going to be used within the next 0.4 seconds.
This algorithm cannot be implemented in the general purpose operating system because it is
impossible to compute reliably how long it will be before a page is going to be used, except
when all software that will run on a system is either known beforehand and is amenable to the
static analysis of its memory reference patterns, or only a class of applications allowing run-
time analysis is allowed.

Conclusion: Thus we have studied and implemented the page replacement algorithm.

FAQs ( This is for reference only )


1. What is Demand Paging? And what is a page fault?
2. What is BELADY‟s ANAMOLY? Explain with example.
3. What is segmentation? Is it better than paging?
4. What is LFU page replacement algorithm? How is it different from LRU?
5. Is it possible to implement optimal page replacement algorithm in reality?
6. Total no. of page faults increase with an increase in no. of frames?
7. What is logical address? How is it converted to physical address?
8. What is TLB? Why is it used?
9. What are other page replacement algorithms you know?
10. How many page faults will occur using LRU and optimal page replacement
scheme. Compare the results.1, 2, 3, 4, 5, 3, 4, 1, 6, 7, 8, 7, 8, 9, 7, 8, 9, 5, 4,
5, 4, 2 (Note:- Reference string may be different)

You might also like