AREGS Website Design & Development Guide
AREGS Website Design & Development Guide
PAGE \* MERGEFORMAT 1
LAB MANUAL
Academic year 2023-24
PAGE \* MERGEFORMAT 1
PAGE \* MERGEFORMAT 1
VISION
We are commi琀琀ed to produce not only good engineers but good human beings, also.
MISSION
Holistic development of students and teachers is that we believe in and work for, We
strive to achieve this by imbibing a unique value system, transparent work culture,
excellent academic and physical environment conducive to learning, creativity and
technology transfer. Our mandate is to generate, preserve and share knowledge for
developing a vibrant society.
VISION
MISSION
M1: To provide broad-based education and contemporary knowledge by
adopting modern teaching-learning methods.
M2: To inculcate a spirit of innovation in students through industrial
interactions.
M3: To develop individual’s potential to its fullest extent so that they can
emerge as gifted leaders in their fields
PAGE \* MERGEFORMAT 1
PAGE \* MERGEFORMAT 1
Build strong alliances that bring the know-how of the business community to complete
the training of students through projects.
PAGE \* MERGEFORMAT 1
PAGE \* MERGEFORMAT 1
PAGE \* MERGEFORMAT 1
PAGE \* MERGEFORMAT 1
PO8- Ethics:- Apply ethical principles and commit to professional ethics and responsibilities
and norms of engineering practice.
PO9- Individual and Team work :-Function effectively as an individual and as a member or
leader in diverse teams, and in multidisciplinary settings.
PO10- Communication Skill:- Communicate effectively on complex engineering activities with
the engineering community and with society at large, such as being able to comprehend and
write effective reports and design documentation, make effective presentations, and give and
receive dear instructions.
PO11- Project management Finance: - Demonstrate knowledge and understanding of
engineering and management principles and apply these to one’s own work as a member and
leader in a team to manage projects and in multidisciplinary environment.
PO12- Life-long Learning: - Recognize the need for, and have the preparations and ability to
engage in independent and lifelong learning in the broadest context of technological change.
PAGE \* MERGEFORMAT 1
PAGE \* MERGEFORMAT 1
Course Objectives:
1) To learn system programming tools
2) To learn modern operating system
3) To learn various techniques, tools, application in IOT and embedded
system. HCI/ DS/ SPM.
Course Outcomes:
On completion of the course, learners will be able to
Systems Programming and Operating System
CO1: Implement language translators
CO2: Use tools like LEX and YACC
CO3: Implement internals and functionalities of Operating System
Internet of Things and Embedded Systems
CO4: Design IoT and Embedded Systems based application
CO5: Develop smart applications using IoT
CO6: Develop IoT applications based on cloud environment
OR
Human Computer Interface
CO4: Implement the interactive designs for feasible data search and retrieval
CO5: Analyze the scope of HCI in various paradigms like ubiquitous computing,
Virtual Reality and, multi-media, worldwide web related environments
CO6: Analyze and identify user models, user support, socio-organizational issues
and stakeholder requirements of HCI systems
OR
Distributed Systems
CO4: Demonstrate knowledge of the core concepts and techniques in Distributed
Systems
PAGE \* MERGEFORMAT 1
PAGE \* MERGEFORMAT 1
PAGE \* MERGEFORMAT 1
PAGE \* MERGEFORMAT 1
CERTIFICATE
has completed all the practical work in the subject Laboratory Practices-I,
PAGE \* MERGEFORMAT 1
PAGE \* MERGEFORMAT 1
Programming Tools:
Internet of things and embedded system: - Raspberry Pi / Arduino Programming;
Arduino IDE / Python.
. During oral assessment, the expert evaluator should give the maximum weightage to
the satisfactory implementation of the problem statement. The supplementary and relevant
questions may be asked at the time of evaluation to test the student’s for advanced learning,
understanding of the fundamentals, effective and efficient implementation. So encouraging
efforts, transparent evaluation and fair approach of the evaluator will not create any uncertainty
or doubt in the minds of the students. So adhering to these principles will consummate our team
efforts to the promising start of the student's academics.
PAGE \* MERGEFORMAT 1
PAGE \* MERGEFORMAT 1
INDEX
Sr. Assignment Date of Date of Marks Sign of
no. performance Submission Obtained Faculty
1 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.
Total
Marks
Marks: /10
Date of Performance: Sign with Date
T.E. (Computer) Sinhgad Institute of Technology, Lonavala Lab Practices-I
/ / 2023
Pass I: -
Separate the symbol, mnemonic opcode and operand fields.
Determine the storage-required for every assembly language statement and update the
location counter.
Build the symbol table and the literal table.
Construct the intermediate code for every assembly language statement.
Pass II: -
Synthesize the target code by processing the intermediate code generated during pass1
INTERMEDIATE CODE REPRESENTATION
The intermediate code consists of a set of IC units, each IC unit consisting of the
following three fields
1. Address
2. Representation of the mnemonic opcode
3. Representation of operands
Where statement class can be one of IS,DL and AD standing for imperative statement,
declaration statement and assembler directive respectively.
Algorithms(procedure) :
PASS 1
• Initialize location counter, entries of all tables as zero.
• Read statements from input file one by one.
• While next statement is not END statement
I. Tokenize or separate out input statement as label,numonic,operand1,operand2
II. If label is present insert label into symbol table.
III. If the statement is LTORG statement processes it by making it’s entry into literal
table, pool table and allocate memory.
IV. If statement is START or ORIGEN Process location counter accordingly.
V. If an EQU statement, assign value to symbol by correcting entry in symbol table.
VI. For declarative statement update code, size and location counter.
VII. Generate intermediate code.
VIII. Pass this intermediate code to pass -2.
Conclusions:
Program:
#include<conio.h>
#include<stdio.h>
#define MAX 20
#include<string.h>
struct symbol
{
char sym[10];
int addr;
}S[MAX];
struct litab
{
char lit[10];
int addr;
}L[MAX];
char optab[]
[6]={"STOP","ADD","SUB","MULT","MOVER","MOVEM","COMP","BC","DIV","READ","
PRINT"};
char regtab[][5]={"AREG","BREG","CREG","DREG"};
char adtab[][7]={"START","END","ORIGIN","EQU","LTORG"};
char condtab[][4]={"LT","LE","EQ","GT","GE","ANY"};
FILE *fs,*ft;
char buffer[80],source[80],tok1[10],tok2[10],tok3[10],tok4[10],tok5[10];
int lc=0,sc=0,poolcnt=0,litcnt=0;
int pooltab[10];
}
}
return -1;
}
void pass1()
{
int p;
int n,i=0,j=0,k=0;
fs=fopen(source,"r");
if(fs==NULL)
{
printf("\n file does not exist!!!!");
getch();
exit(0);
}
ft=fopen("[Link]","w");
while(fgets(buffer,80,fs))
{
n=sscanf(buffer,"%s%s%s%s",tok1,tok2,tok3,tok4);
switch(n)
{
case 1: //ltorg,end
i=search_adtab(tok1);
if(i==2 || i==5)
{
for(j=pooltab[poolcnt];j<litcnt;j++)
{
L[j].addr=lc++;
}
lc--;
pooltab[++poolcnt]=litcnt;
fprintf(ft,"(AD, %02d)\n",i);
break;
}
case 2: //start
i=search_adtab(tok1);
if(i==1)
{
lc=atoi(tok2)-1;
fprintf(ft,"(AD, %02d) (C, %s)\n",i,tok2);
break;
}
case 3:i=search_optab(tok1);
if(i>=1 && i<=8)
{
tok2[strlen(tok2)-1]='\0';
k=search_regtab(tok2);
//mover areg,='5'
if(tok3[0]=='=')
{
j=search_littab(tok3);
if(j==-1)
{
strcpy(L[litcnt].lit,tok3);
fprintf(ft,"(IS, %02d)%d(L, %02d)\n",i,k,litcnt);
litcnt++;
}
else
{
fprintf(ft,"(IS, %02d) %d (L, %02d)\n",i,k,j);
}
break;
else//mover areg,A
{
p=search_symtab(tok3);
if(p==-1)
{
strcpy(S[sc].sym,tok3);
fprintf(ft,"(IS, %02d) %d (S, %02d)\n",i,k,sc);
sc++;
}
else
{
fprintf(ft,"(IS, %02d) %d (S, %02d)\n",i,k,p);
}
break;
}
}
//A DS 2
if(strcmp(tok2,"DS")==0)
{
p=search_symtab(tok1);
if(p==-1)
{
strcpy(S[sc].sym,tok1);
S[sc].addr=lc;
fprintf(ft,"(DL, 2) (C, %s)\n",tok3);
sc++;
}
else
{
S[p].addr=lc;
fprintf(ft,"(DL, 2) (C, %s)\n",tok3);
}
lc=lc+atoi(tok3)-1;
break;
}
}
lc++;
}
fcloseall();
void print_littab()
{
int i;
printf("\n LITERAL\tADDRESS\n");
for(i=0;i<litcnt;i++)
{
printf("%s\t%d\n",L[i].lit,L[i].addr);
}
}
void print_symtab()
{
int p=0;
printf("\n SYMBOL\tADDRESS\n");
while(p<sc)
{
printf("%s\t%d\n",S[p].sym,S[p].addr);
p=p+1;
}
}
void main()
{
clrscr();
printf("\n enter source file name: \n");
scanf("%s",source);
pass1();
getch();
}
//File 2- [Link]
//SOURCE FILE
START 200
MOVER AREG, ='5'
MOVEM BREG, ='1'
ADD BREG, A
LTORG
SUB CREG, B
A DS 2
B DS 2
END
//INTERMEDIATE CODE
(AD, 01) (C, 200)
(IS, 04) 1 (L, 00)
(IS, 05) 2 (L, 01)
(IS, 01) 2 (S, 00)
(AD, 05)
(IS, 02) 3 (S, 01)
(DL, 2) (C, 2)
(DL, 2) (C, 2)
(AD, 02)
OUTPUT
gcc pass1.c
./[Link]
START 200
MOVER AREG, ='5'
MOVEM BREG, ='1'
ADD BREG, A
LTORG
SUB CREG, B
A DS 2
B DS 2
END
Literal Table:
LITERAL ADDRESS
='5' 203
='1' 204
Symbol Table:
SYMBOL ADDRESS
A 206
B 208
//Assembler Pass 2
#include<stdio.h>
#include<conio.h>
#define MAX 20
struct symbol
{
char sym[10];
int addr;
}S[MAX]={
{"A",103},
{"B",106},
{"C",107}
};
char optab[]
[6]={"STOP","ADD","SUB","MULT","MOVER","MOVEM","COMP","BC","DIV","READ","PRINT"};
char regtab[][5]={"AREG","BREG","CREG","DREG"};
char condtab[][4]={"LT","LE","EQ","GT","GE","ANY"};
char adtab[][7]={"START","END","ORIGIN","EQU","LTORG"};
FILE *fs,*ft;
char source[20],buffer[80],tok1[10],tok2[10],tok3[10],tok4[10],tok5[10];
int lc,ec=0,sc=3;
}
return(-1);
}
int search_adtab(char *s)
{
int i;
for(i=0;i<5;i++)
{
if(strcmp(adtab[i],s)==0)
return (i+1);
}
return(-1);
}
void print_file(char *target)
{
FILE *fp;
fp=fopen(target,"r");
if(fp==NULL)
{
printf("\nError In Opening File");
getch();
exit(0);
}
printf("\n\n");
while(fgets(buffer,80,fp))
{
printf("%s",buffer);
}
//printf("%d",lc);
fclose(fp);
}
void passtwo()
{
int i,j,k,n,p;
char temp[20];
if((fs=fopen("[Link]","r"))==NULL)
{
printf("\n\nError In Opening [Link]");
getch();
exit(0);
}
if((ft=fopen("[Link]","w"))==NULL)
{
printf("\n\nError In Opening [Link]");
getch();
exit(0);
}
lc=0;
while(fgets(buffer,80,fs))
{
n=sscanf(buffer,"%s%s%s%s%s",tok1,tok2,tok3,tok4,tok5);
switch(n)
{
case 4:
if(strcmp(tok1,"(AD,")==0)
{
tok4[strlen(tok4)-1]='\0';
lc=atoi(tok4)-1;
break;
}
if(strcmp(tok1,"(DL,")==0)
{
tok2[strlen(tok2)-1]='\0';
tok4[strlen(tok4)-1]='\0';
i=atoi(tok2);
j=atoi(tok4);
if(i==2) //A DS 2
{
for(k=0;k<j;k++)
{
fprintf(ft,"%d)\n",lc++);
}
lc--;
}
else //ONE DC 1
{
fprintf(ft,"%d) %d\n",lc,j);
}
}
break;
case 5:
tok2[strlen(tok2)-1]='\0';
tok5[strlen(tok5)-1]='\0';
i=atoi(tok2);
j=atoi(tok3);
k=atoi(tok5);
if(strcmp(tok4,"(S,")==0)
{
fprintf(ft,"%d) %02d %d %03d\n",lc,i,j,S[k].addr);
}
break;
} //switch
lc++;
} //while
fcloseall();
}
void print_symb()
{
int p=0;
printf("\n\tsymbol\taddress");
while(p<sc)
{
printf("\n\t%s\t%d",S[p].sym,S[p].addr);
p=p+1;
}
}
void main()
{
clrscr();
printf("\n\n\tSYMBOL TABL[Link]\n");
print_symb();
printf("\n\n\n\tINTERMEDIATE CO[Link]\n");
print_file("[Link]");
getch();
passtwo();
printf("\n\n\tTARGET CO[Link]\n");
print_file("[Link]");
getch();
}
SYMBOL TABL[Link]
symbol address
A 103
B 106
C 107
INTERMEDIATE CO[Link]
TARGET CO[Link]
100) 01 1 103
101) 02 2 106
102) 05 2 107
103)
104)
105)
106) 2
107)
108)
109)
110) 03 2 107
111) 08 3 106
import os
LC=0 #location counter initialization
"""
mnemonic dictionary elements are:
Key is mnemonic e.g. "STOP"
Value of that key is a tuple consiting of opcode value, instruction class or type and number of
operands required for that mnemonic
e.g. "STOP":('00','IS',0)
This states that 'STOP' is a mnemonic whereas value tuple consisting of '00' is opcode, 'IS' is
instruction type, 0 is number of operands that mnemonics required.
"""
mnemonics={'STOP':('00','IS',0),'ADD':('01','IS',2),'SUB':('02','IS',2),'MUL':
('03','IS',2),'MOVER':('04','IS',2),'MOVEM':('05','IS',2),'COMP':('06','IS',2),'BC':
('07','IS',2),'DIV':('08','IS',2),'READ':('09','IS',1),'PRINT':('10','IS',1),'LTORG':
('05','AD',0),'ORIGIN':('03','AD',1),'START':('01','AD',1),'EQU':('04','AD',2),'DS':
('01','DL',1),'DC':('02','DL',1),'END':('AD',0)}
file=open("[Link]") #Enter input file with complete path if not in same directory
for x in lit:
print(x)
[Link](z)
while(x[i][j]!="'"):
j+=1
j+=1
while(x[i][j]!="'"):
[Link](x[i][j])
j+=1
if(i!=len(x)-1):
[Link]("\t(AD,05)\t(DL,02)(C,"+str(f[0])+")\n")
y=x[i].split()
[Link](y[0]+"\t"+str(LC)+"\n")
LC+=1
[Link](str(LC))
else:
[Link]("\t(AD,05)\t(DL,02)(C,"+str(f[0])+")\n")
y=x[i].split()
[Link](y[0]+"\t"+str(LC)+"\n")
LC+=1
else:
[Link](x[i])
z+=1
i+=1
[Link](0)
[Link](0,0)
for x in tmp:
[Link](x)
[Link](0)
#handles DS mnemonic
def DS(size):
global LC
[Link]("\t(DL,01)\t(C,"+size+")\n")
LC=LC+int(size)
#handles DC mnemonic
def DC(value):
global LC
[Link]("\t(DL,02)\t(C,"+value+")\n")
LC+=1
'''
def EQU(words):
global symindex
if words[2] in [Link]():
z=symtab[words[2]]
if words[0] not in [Link]():
symtab[words[0]]=(z[0],symindex)
symindex+=1
else:
w=symtab[words[0]]
symtab[words[0]]=(z[0],w[-1])
DS(words[k+1])
elif(words[k]=="DC"):
DC(words[k+1])
#elif(words[k]=="EQU"):
#EQU(words)
else:
OTHERS(words[k],k)
littab()
pooltab2()
symbol()
if words[0] in [Link]():
print("Mnemonic:",words[0])
val=mnemonics[words[0]]
k=0
detect_mn(k)
else:
print("Label:",words[0],"Mnemonic:",words[1])
if words[k] not in [Link]():
symtab[words[k]]=(LC,symindex)
#[Link]("\t(S,"+str(symindex)+")\t")
symindex+=1
symbol()
else:
#print(words)
x=symtab[words[k]]
if x[0]=="**":
print("yes")
symtab[words[k]]=(LC,x[1])
#[Link]("\t(S,"+str(symindex)+")\t")
symbol()
k=1
detect_mn(k)
#print(symtab)
#print(pooltab)
[Link]()
[Link]()
[Link]()
sym=open("[Link]","a+")
[Link](0)
for x in symtab:
[Link](x+"\t"+str(symtab[x][0])+"\n")
[Link]()
pool=open("[Link]","a+")
[Link](0)
for x in pooltab:
[Link](str(x)+"\n")
[Link]()
if [Link]("[Link]")==True:
[Link]("[Link]")
Input file
START 100
A DC 10
MOVER AREG, B
MOVEM BREG, ='1'
ADD AREG, ='2'
SUB BREG, ='1'
B DC 20
ORIGIN 300
LTORG
MOVER AREG, NUM
MOVER CREG, LOOP
ADD BREG, ='1'
NUM DS 5
LOOP DC 10
END
Sample output:
LC= 0
START 100
['START', '100']
Mnemonic: START
literal table:
Pool Table:
[]
Symbol Table:
{}
LC= 100
A DC 10
Pool Table:
[]
Symbol Table:
{'A': (100, 0), 'B': ('**', 1)}
LC= 103
ADD AREG, ='2'
='2' **
Pool Table:
[]
Symbol Table:
{'A': (100, 0), 'B': ('**', 1)}
LC= 104
SUB BREG, ='1'
='2' **
='1' **
Pool Table:
[]
Symbol Table:
{'A': (100, 0), 'B': ('**', 1)}
LC= 105
B DC 20
='2' **
='1' **
Pool Table:
[]
Symbol Table:
{'A': (100, 0), 'B': (105, 1)}
LC= 106
ORIGIN 300
['ORIGIN', '300']
Mnemonic: ORIGIN
literal table:
='1' **
='2' **
='1' **
Pool Table:
[]
Symbol Table:
{'A': (100, 0), 'B': (105, 1)}
LC= 300
LTORG
['LTORG']
Mnemonic: LTORG
literal table:
='1' 300
='2' 301
='1' 302
Pool Table:
[0]
Symbol Table:
{'A': (100, 0), 'B': (105, 1)}
LC= 303
MOVER AREG, NUM
Mnemonic: MOVER
literal table:
='1' 300
='2' 301
='1' 302
Pool Table:
[0]
Symbol Table:
{'A': (100, 0), 'B': (105, 1), 'NUM': ('**', 2)}
LC= 304
MOVER CREG, LOOP
='2' 301
='1' 302
Pool Table:
[0]
Symbol Table:
{'A': (100, 0), 'B': (105, 1), 'NUM': ('**', 2), 'LOOP': ('**', 3)}
LC= 305
ADD BREG, ='1'
='2' 301
='1' 302
='1' **
Pool Table:
[0]
Symbol Table:
{'A': (100, 0), 'B': (105, 1), 'NUM': ('**', 2), 'LOOP': ('**', 3)}
LC= 306
NUM DS 5
literal table:
='1' 300
='2' 301
='1' 302
='1' **
Pool Table:
[0]
Symbol Table:
{'A': (100, 0), 'B': (105, 1), 'NUM': (306, 2), 'LOOP': ('**', 3)}
LC= 311
LOOP DC 10
='2' 301
='1' 302
='1' **
Pool Table:
[0]
Symbol Table:
{'A': (100, 0), 'B': (105, 1), 'NUM': (306, 2), 'LOOP': (311, 3)}
LC= 312
END
['END']
Mnemonic: END
literal table:
='1' 300
='2' 301
='1' 302
='1' 312
Pool Table:
[0, 3]
Symbol Table:
{'A': (100, 0), 'B': (105, 1), 'NUM': (306, 2), 'LOOP': (311, 3)}
Marks: /10
Date of Performance: Sign with Date
/ / 2023
Aim: Design suitable data structures and implement Pass-I and Pass-II of a two-pass macro- processor.
Objective:
1) To Identify and create the data structures required in the design of macro processor
2) Implement Pass-I and Pass-II of a two-pass macro- processor using C++
Theory :
In Pass-I the macro definitions are searched and stored in the macro definition table and the entry is
made in macro name table
In Pass-II the macro calls are identified and the arguments are placed in the appropriate place and the
macro calls are replaced by macro definitions.
Pass 1:-
• The input macro source program.
• The output macro source program to be used by Pass2.
• Macro-Definition Table (MDT), to store the body of macro definition .
• Macro-Definition Table Counter (MDTC), to mark next available entry MDT.
• Macro- Name Table (MNT) - store names of macros.
• Macro Name Table counter (MNTC) - indicate the next available entry in MNT.
• Argument List Array (ALA) - substitute index markers for dummy arguments before storing a macro-
definition.
Pass 2:-
• The input is from Pass1.
• The output is expanded source to be given to assembler.
• MDT and MNT are created by Pass1.
• Macro-Definition Table Pointer (MDTP), used to indicate the next line of text to be used
during macro expansion.
• Argument List Array (ALA), used to substitute macro call arguments for the index markers in
the stored macro-definitions.
Design of two pass Macro processor
PASS I - ALGORITHM
• Pass1 of macro processor makes a line-by-line scan over its input.
• Set MDTC = 1 as well as MNTC = 1.
• Read next line from input program.
• If it is a MACRO pseudo-op, the entire macro definition except this (MACRO) line is stored in
MDT.
• The name is entered into Macro Name Table along with a pointer to the first location of MDT
entry of the definition.
• When the END pseudo-op is encountered all the macro-definitions have been processed, so
control is transferred to pass2
PASS II - ALGORITHM
• This algorithm reads one line of input program at a time.
• for each Line it checks if op-code of that line matches any of the MNT entry.
• When match is found (i.e. when call is pointer called MDTF to corresponding macro
definitions stored in MDT.
• The initial value of MDTP is obtained from MDT index field of MNT entry.
•The macro expander prepares the ALA consisting of a table of dummy argument indices &
corresponding arguments to the call.
•Reading proceeds from the MDT, as each successive line is read, The values form the argument
list one substituted for dummy arguments indices in the macro definition.
• Reading MEND line in MDT terminates expansion of macro & scanning continues from the
input file.
• When END pseudo-op encountered , the expanded source program is given to the assembler.
Conclusions:
/*--------MACRO PROGRAM--------*/
#include<stdio.h>
#include<conio.h>
#include<string.h>
#include<ctype.h>
#include<process.h>
#include<stdlib.h>
void main()
{
int mdt_pntr=0,mnt_pntr=0,v_pntr=0,i,j,loc_cnt=0,flag=0;
char temp[100],tkn[10][10],v[15][15],temp1[100],tkn1[10][10];
FILE *fp,*fp1;
clrscr();
fp=fopen("[Link]","r");
fp1=fopen("[Link]","w+");
if (fp==NULL)
{
printf("Cannot open output file.\n");
exit(0);
}
while(fgets(temp,40,fp))
{
for(i=0;i<4;i++)
strcpy(tkn[i],"");
sscanf(temp,"%s %s %s %s",tkn[0],tkn[1],tkn[2],tkn[3]);
if(strcmpi(tkn[0],"macro")!=0)
printf("%s %s %s %s\t\t\n",tkn[0],tkn[1],tkn[2],tkn[3]); //
as it is print bcoz assebler statement
else
{
for(i=0;i<4;i++)
strcpy(tkn[i],"");
fgets(temp,40,fp);
sscanf(temp,"%s %s %s %s",tkn[0],tkn[1],tkn[2],tkn[3]);
strcpy(mdt[mdt_pntr++],temp);
strcpy(mn[mnt_pntr].mname,tkn[0]);
mn[mnt_pntr].mdt_index=mdt_pntr-1;
mnt_pntr++;
//**************************************************
//*************************
while(fgets(temp,40,fp))
{
for(i=0;i<4;i++)
strcpy(tkn[i],"");
sscanf(temp,"%s %s %s %s",tkn[0],tkn[1],tkn[2],tkn[3]);
for(i=0;i<v_pntr;i++)
{
if(strcmp(tkn[2],v[i])==0)
{ sprintf(temp,"%s %s %d %s \n",tkn[0],tkn[1],i,tkn[3]);
strcpy(mdt[mdt_pntr++],temp);
sprintf(temp,"%s %s %d %s\n",tkn[0],tkn[1],i,tkn[3]);
break;
}
}
}
v_pntr=0;
}
}
printf("\n\n\t\t\tMNT TABLE\n\n");
printf("\tmnt index\tmnt name\tmdt index\n");
printf("___________________________________________________
___\n\n");
for(i=0;i<mnt_pntr;i++)
printf("\t%d\t\t%s\t\t\t%d\n",i,mn[i].mname,mn[i].mdt_index
);
getch();
printf("\n\n\n");
printf("\t\t\tMDT TABLE\n\n");
printf("\tmdtindex \t macro def\n");
printf("___________________________________________\n\n");
for(i=0;i<mdt_pntr;i++)
{
fprintf(fp1,"\t%d\t\t%s",i,mdt[i]);
printf("\t%d\t\t%s",i,mdt[i]);
}
getch();
fcloseall();
sscanf(temp1,"%s %s %s %s",tkn1[0],tkn1[1],tkn1[2],
tkn1[3],tkn1[4]);
if(atoi(tkn1[0])==mn[i].mdt_index) //pointing to
def.
{
while(fgets(temp1,40,fp1))
{
sscanf(temp1,"%s %s %s %s",tkn1[0],tkn1[1],tkn1[2],
tkn1[3],tkn1[4]);
if (strcmp(tkn1[1],"mend")==0)
break;
if(strcmp(tkn1[3],"0")==0)
{
sprintf(temp1,"%s %s %s %s",tkn1[1],tkn1[2]
,tkn[1]);
}
if(strcmp(tkn1[3],"1")==0)
{
sprintf(temp1,"%s %s %s %s",tkn1[1],tkn1[2]
,tkn[2]);
}
if(strcmp(tkn1[3],"2")==0)
{
sprintf(temp1,"%s %s %s %s",tkn1[1],tkn1[2]
,tkn[3]);
}
printf("%s\n",temp1);
}
flag=1;
}
}
break;
}
}
if(flag==0)
printf("%s",temp);
}
getch();
}
PROGRAM:[Link]
start 100
mover bregs asd
sub aregs =6
add aregs =5
sub aregs =6
sub1 1 2 32
ltorg
movem cregs =3
mover bregs asd
origin 103
sub aregs =6
mover bregs sd
sd dc 3
add1 44 55
asd ds 2
sub1 98 99 78
end
INTERMEDIATE FILE
OUTPUT
start 100
mover bregs asd
sub aregs =6
add aregs =5
sub aregs =6
sub1 1 2 32
ltorg
movem cregs =3
mover bregs asd
origin 103
sub aregs =6
mover bregs sd
sd dc 3
add1 44 55
asd ds 2
sub1 98 99 78
end
MNT TABLE
0 sub1 0
1 add1 5
MDT TABLE
----Expansion of macro----
start 100
mover bregs asd
sub aregs =6
add aregs =5
sub aregs =6
mover aregs 1
mover aregs 2
add bregs 32
ltorg
movem cregs =3
mover bregs asd
origin 103
sub aregs =6
mover bregs sd
sd dc 3
mover aregs 55
add bregs 44
asd ds 2
mover aregs 98
mover aregs 99
add bregs 78
end
/ / 2023
Aim: Write a program to simulate CPU Scheduling Algorithms: FCFS, SJF (Preemptive), Priority (Non-
Preemptive) and Round Robin (Preemptive).
Objectives: Implement CPU scheduling algorithms FCFS, SJF (Preemptive), Priority (Non-Preemptive) and
Round Robin (Preemptive) using Python.
Theory:
A Process Scheduler schedules different processes to be assigned to the CPU based on particular scheduling
35 | Department Computer Engineering, SIT, Lonavala
algorithms.
First-Come, First-Served (FCFS) Scheduling
Downloaded by Adinath Sonawane (adinaths109@[Link])
Shortest-Job-Next (SJN) Scheduling or Shortest-Job-First (SJF) Scheduling
lOMoARcPSD|58943265
Algorithm
Step 1: Start the process
Step 2: Accept the number of processes in the ready Queue
Step 3: For each process in the ready Q, assign the process id and accept the CPU burst time
Step 4: Set the waiting of the first process as ‘0’ and its burst time as its turnaround time
Step 5: for each process in the Ready Q calculate
(a) Waiting time for process(n)= waiting time of process (n-1) + Burst time of process(n-1)
(b) Turnaround time for Process(n)= waiting time of Process(n)+ Burst time for process(n)
Step 6: Calculate
(a) Average waiting time = Total waiting Time / Number of process
(b) Average Turnaround time = Total Turnaround Time / Number of process Step 7: Stop the process
3) Priority Scheduling
Priority scheduling is a non-preemptive algorithm and one of the most common
scheduling algorithms in batch systems.
Each process is assigned a priority. Process with highest priority is to be executed first
and so on.
Processes with same priority are executed on first come first served basis.
Priority can be decided based on memory requirements, time requirements or any other
resource requirement.
Algorithm
Step 1: Start the process
Step 2: Accept the number of processes in the ready Queue
Step 3: For each process in the ready Q, assign the process id and accept the CPU burst time,
priority
Step 4: Start the Ready Q according the priority by sorting according to lowest to
highest burst time and process.
Step 5: Set the waiting time of the first process as ‘0’ and its turnaround time as its burst time.
Step 6: For each process in the ready queue, calculate
(e) Waiting time for process(n)= waiting time of process (n-1) + Burst time of process(n-1)
(f) Turn around time for Process(n)= waiting time of Process(n)+ Burst time for process(n)
Step 6: Calculate
(g) Average waiting time = Total waiting Time / Number of process
(h) Average Turnaround time = Total Turnaround Time / Number of process
Step 7: Stop the process
Algorithm
Step 1: Start the process
Step 2: Accept the number of processes in the ready Queue and time quantum (or) time slice
Step 3: For each process in the ready Q, assign the process id and accept the CPU burst time
Step 4: Calculate the no. of time slices for each process where
No. of time slice for process(n) = burst time process(n)/time slice
Step 5: If the burst time is less than the time slice then the no. of time slices =1.
Step 6: Consider the ready queue is a circular Q, calculate
(a) Waiting time for process(n) = waiting time of process(n-1)+ burst time of process(n-1 ) +
the time difference in getting the CPU from process(n-1)
(b) Turnaround time for process(n) = waiting time of process(n) + burst time of process(n)+
the time difference in getting CPU from process(n).
Step 7: Calculate
(e) Average waiting time = Total waiting Time / Number of process
(f) Average Turnaround time = Total Turnaround Time / Number of process
Step 8: Stop the process.
Conclusions:
1. FCFS PROGRAM
#include<iostream>
using namespace std;
int main()
{ int n,bt[20],wt[20],tat[20],avwt=0,avtat=0,i,j;
cout<<"Enter total number of processes(maximum 20):";
cin>>n;
return 0;
}
OR
//C++ program for implementation of FCFS
// scheduling
#include<iostream>
// Driver code
int main()
{
//process id's
int processes[] = { 1, 2, 3};
int n = sizeof processes / sizeof processes[0];
findavgTime(processes, n, burst_time);
return 0;
}
OUTPUT:
Enter total number of processes(maximum 20):5
int main() {
index = i;
for (j = i + 1; j < n; j++)
if (A[j][1] < A[index][1])
index = j;
temp = A[i][1];
A[i][1] = A[index][1];
A[index][1] = temp;
temp = A[i][0];
A[i][0] = A[index][0];
A[index][0] = temp;
}
A[0][2] = 0;
// Calculation of Waiting Times
for (i = 1; i < n; i++) {
A[i][2] = 0;
for (j = 0; j < i; j++)
A[i][2] += A[j][1];
total += A[i][2];
}
avg_wt = (float)total / n;
total = 0;
cout << "P BT WT TAT" << endl;
cout << "P" << A[i][0] << " " << A[i][1] << " " << A[i][2] << " " << A[i][3] <<
endl;
}
avg_tat = (float)total / n;
cout << "Average Waiting Time= " << avg_wt << endl;
cout << "Average Turnaround Time= " << avg_tat << endl;
}
Output:
{
// If burst time of a process is greater than 0
// then only need to process further
if (rem_bt[i] > 0)
{
done = false; // There is a pending process
// Driver code
int main()
{
// process id's
int processes[] = { 1, 2, 3};
int n = sizeof processes / sizeof processes[0];
// Time quantum
int quantum = 2;
findavgTime(processes, n, burst_time, quantum);
return 0;
}
OUTPUT:
PN BT WT TAT
1 10 13 23
2 5 10 15
3 8 13 21
Average waiting time = 12
Average turn around time = 19.6667
struct Process {
int pid; // Process ID
int bt; // CPU Burst time required
int priority; // Priority of this process
};
findavgTime(proc, n);
}
// Driver code
int main()
{
Process proc[]
= { { 1, 10, 2 }, { 2, 5, 0 }, { 3, 8, 1 } };
int n = sizeof proc / sizeof proc[0];
priorityScheduling(proc, n);
return 0;
}
OUTPUT:
PYTHON IMPLEMENTATION
for i in range(n):
key = "P"+str(i+1)
a = int(input("Enter arrival time of process"+str(i+1)+": "))
b = int(input("Enter burst time of process"+str(i+1)+": "))
l = []
[Link](a)
[Link](b)
d[key] = l
ET = []
for i in range(len(d)):
# first process
if(i==0):
[Link](d[i][1][1])
TAT = []
for i in range(len(d)):
[Link](ET[i] - d[i][1][0])
WT = []
for i in range(len(d)):
[Link](TAT[i] - d[i][1][1])
avg_WT = 0
for i in WT:
avg_WT +=i
avg_WT = (avg_WT/n)
2) SJF- Nonpreemptive
class SJF:
normal_queue = []
for j in range(len(process_data)):
if (process_data[j][1] <= s_time) and (process_data[j][3] == 0):
[Link]([process_data[j][0], process_data[j][1], process_data[j][2]])
ready_queue.append(temp)
temp = []
elif process_data[j][3] == 0:
[Link]([process_data[j][0], process_data[j][1], process_data[j][2]])
normal_queue.append(temp)
temp = []
if len(ready_queue) != 0:
ready_queue.sort(key=lambda x: x[2])
'''
Sort the processes according to the Burst Time
'''
start_time.append(s_time)
s_time = s_time + ready_queue[0][2]
e_time = s_time
exit_time.append(e_time)
for k in range(len(process_data)):
if process_data[k][0] == ready_queue[0][0]:
break
process_data[k][3] = 1
process_data[k].append(e_time)
elif len(ready_queue) == 0:
if s_time < normal_queue[0][1]:
s_time = normal_queue[0][1]
start_time.append(s_time)
total_waiting_time = 0
for i in range(len(process_data)):
waiting_time = process_data[i][5] - process_data[i][2]
'''
waiting_time = turnaround_time - burst_time
'''
total_waiting_time = total_waiting_time + waiting_time
process_data[i].append(waiting_time)
average_waiting_time = total_waiting_time / len(process_data)
'''
average_waiting_time = total_waiting_time / no_of_processes
'''
return average_waiting_time
for i in range(len(process_data)):
for j in range(len(process_data[i])):
if __name__ == "__main__":
no_of_processes = int(input("Enter number of processes: "))
sjf = SJF()
[Link](no_of_processes)
OUTPUT:
Enter number of processes: 5
Enter Process ID: 1
Enter Arrival Time for Process 1: 3
Enter Burst Time for Process 1: 1
Enter Process ID: 2
Enter Arrival Time for Process 2: 1
Enter Burst Time for Process 2: 4
Enter Process ID: 3
Enter Arrival Time for Process 3: 4
Enter Burst Time for Process 3: 2
Enter Process ID: 4
Enter Arrival Time for Process 4: 0
Enter Burst Time for Process 4: 6
Enter Process ID: 5
Enter Arrival Time for Process 5: 2
Enter Burst Time for Process 5: 3
Process ID Arrival Time Burst Time Completed Completion Time Turnaround Time Waiting Time
1 3 1 1 7 4 3
2 1 4 1 16 15 11
3 4 2 1 9 5 3
4 0 6 1 6 6 0
5 2 3 1 12 10 7
class SJF:
process_data = []
for i in range(no_of_processes):
temporary = []
'''
'0' is the state of the process. 0 means not executed and 1 means execution
complete
'''
process_data.append(temporary)
start_time = []
exit_time = []
s_time = 0
sequence_of_process = []
'''
'''
while 1:
ready_queue = []
normal_queue = []
temp = []
for i in range(len(process_data)):
ready_queue.append(temp)
temp = []
elif process_data[i][ 3] == 0:
normal_queue.append(temp)
temp = []
break
if len(ready_queue) != 0:
'''
'''
start_time.append(s_time)
s_time = s_time + 1
e_time = s_time
exit_time.append(e_time)
sequence_of_process.append(ready_queue[ 0][0])
for k in range(len(process_data)):
break
process_data[k][ 2] = process_data[k][ 2] - 1
process_data[k][ 3] = 1
process_data[k].append(e_time)
if len(ready_queue) == 0:
start_time.append(s_time)
s_time = s_time + 1
e_time = s_time
exit_time.append(e_time)
sequence_of_process.append(normal_queue[ 0][0])
for k in range(len(process_data)):
break
process_data[k][ 2] = process_data[k][ 2] - 1
process_data[k][ 3] = 1
process_data[k].append(e_time)
total_turnaround_time = 0
for i in range(len(process_data)):
'''
'''
process_data[i].append(turnaround_time)
'''
'''
return average_turnaround_time
total_waiting_time = 0
for i in range(len(process_data)):
'''
'''
process_data[i].append(waiting_time)
'''
'''
return average_waiting_time
'''
'''
for i in range(len(process_data)):
for j in range(len(process_data[i])):
print()
if __name__ == "__main__":
sjf = SJF()
[Link](no_of_processes)
'''
process_data.append(temporary)
'''
The above if loop checks that the next process is not a part of ready_queue
'''
if present == 0:
[Link]([process_data[i][0], process_data[i][1], process_data[i][2],
process_data[i][4]])
ready_queue.append(temp)
temp = []
'''
The above if loop adds a process to the ready_queue only if it is not already
present in it
'''
if len(ready_queue) != 0 and len(executed_process) != 0:
for k in range(len(ready_queue)):
if ready_queue[k][0] == executed_process[len(executed_process) - 1]:
ready_queue.insert((len(ready_queue) - 1), ready_queue.pop(k))
'''
The above if loop makes sure that the recently executed process is appended at
the end of ready_queue
'''
elif process_data[i][3] == 0:
[Link]([process_data[i][0], process_data[i][1], process_data[i][2],
process_data[i][4]])
normal_queue.append(temp)
temp = []
if len(ready_queue) == 0 and len(normal_queue) == 0:
break
if len(ready_queue) != 0:
if ready_queue[0][2] > time_slice:
'''
If process has remaining burst time greater than the time slice, it will execute
for a time period equal to time slice and then switch
'''
start_time.append(s_time)
s_time = s_time + time_slice
e_time = s_time
exit_time.append(e_time)
executed_process.append(ready_queue[0][0])
for j in range(len(process_data)):
if process_data[j][0] == ready_queue[0][0]:
break
process_data[j][2] = process_data[j][2] - time_slice
ready_queue.pop(0)
elif ready_queue[0][2] <= time_slice:
'''
If a process has a remaining burst time less than or equal to time slice, it will
complete its execution
'''
start_time.append(s_time)
s_time = s_time + ready_queue[0][2]
e_time = s_time
exit_time.append(e_time)
executed_process.append(ready_queue[0][0])
for j in range(len(process_data)):
if process_data[j][0] == ready_queue[0][0]:
break
process_data[j][2] = 0
process_data[j][3] = 1
process_data[j].append(e_time)
ready_queue.pop(0)
elif len(ready_queue) == 0:
process_data[j].append(e_time)
t_time = [Link](self, process_data)
w_time = [Link](self, process_data)
[Link](self, process_data, t_time, w_time, executed_process)
if __name__ == "__main__":
no_of_processes = int(input("Enter number of processes: "))
rr = RoundRobin()
[Link](no_of_processes)
OUTPUT OF RR:
Enter number of processes: 5
Enter Process ID: 0
1 1 0 1 3 12 11 8
2 2 0 1 1 5 3 2
3 3 0 1 2 9 6 4
4 4 0 1 3 14 10 7
temporary = []
process_id = int(input("Enter Process ID: "))
for k in range(len(process_data)):
if process_data[k][0] == normal_queue[0][0]:
break
process_data[k][4] = 1
process_data[k].append(e_time)
t_time = [Link](self, process_data)
w_time = [Link](self, process_data)
[Link](self, process_data, t_time, w_time)
if __name__ == "__main__":
no_of_processes = int(input("Enter number of processes: "))
priority = Priority()
[Link](no_of_processes)
Marks: /10
Date of Performance: Sign with Date
/ / 2023
Aim: Write a program to simulate Memory placement strategies – best fit, first fit,
next fit and worst fit..
Objective .
1. To study page replacement policies to understand memory management.
2. To understand efficient frame management using replacement policies.
Theory :
CONCEPT OF PAGE REPLACEMENT:
1. Page Fault: Absence of page when referenced in main memory during paging leads to a page
fault.
2. Page Replacement: Replacement of already existing page from main memory by the required
new page is called as page replacement. And the techniques used for it are called as page replacement
algorithms.
Algorithm/Flowchart:
1. FIFO :
1. Start the process
2. Read number of pages n
3. Read number of pages no
4. Read page numbers into an array a[i]
5. Initialize avail[i]=0 .to check page hit
6. Replace the page with circular queue, while re-placing check page availability
in the frame Place avail[i]=1 if page is placed in the frame Count page faults
7. Print the results.
8. Stop the process.
3. OPTIMAL ALGORTHIM:
1. Start Program
2. Read Number Of Pages And Frames
[Link] Each Page Value
4. Search For Page In The Frames
5. If Not Available Allocate Free Frame
6. If No Frames Is Free Replace The Page With The Page That Is Least Used
7. Print Page Number Of Page Faults
8. Stop process.
Conclusion:
Successfully implemented all page replacement policies.
output:
Enter the number of frames: 3
Enter the reference string: 1 2 3 4 1 6 7 8 2
String|Frame → 0 1 2 Fault
↓
1 1 Yes
2 1 2 Yes
3 1 2 3 Yes
4 4 2 3 Yes
1 4 1 3 Yes
6 4 1 6 Yes
7 7 1 6 Yes
8 7 8 6 Yes
2 7 8 2 Yes
Total requests: 9
Total Page Faults: 9
Fault Rate: 100.00%
2) LRU
[Link](len(f)-1)
else:
ind = [Link](0)
f[ind] = i
[Link](ind)
pf = 'Yes'
fault += 1
else:
[Link]([Link]([Link]([Link](i))))
pf = 'No'
print(" %d\t\t"%i,end='')
for x in f:
print(x,end=' ')
for x in range(capacity-len(f)):
print(' ',end=' ')
print(" %s"%pf)
print("\nTotal Requests: %d\nTotal Page Faults: %d\nFault Rate:
%0.2f%%"%(len(s),fault,(fault/len(s))*100))
OUTPUT:
Enter the number of frames: 3
Enter the reference string: 1 2 3 4 1 6 7 8 2
String|Frame → 0 1 2 Fault
↓
1 1 Yes
2 1 2 Yes
3 1 2 3 Yes
4 4 2 3 Yes
1 4 1 3 Yes
6 4 1 6 Yes
7 7 1 6 Yes
8 7 8 6 Yes
2 7 8 2 Yes
Total Requests: 9
Total Page Faults: 9
Fault Rate: 100.00%
3) OPTIMAL
output:
String|Frame → 0 1 2 Fault
↓
1 1 Yes
2 1 2 Yes
3 1 2 3 Yes
4 1 2 4 Yes
1 1 2 4 No
6 6 2 4 Yes
7 7 2 4 Yes
8 8 2 4 Yes
2 8 2 4 No
Total requests: 9
Total Page Faults: 7
Fault Rate: 77.78%
Marks: /10
Date of Performance: Sign with Date
/ / 2023
Aim: Write a program to simulate Memory placement strategies – best fit, first fit,
next fit and worst fit..
Objective .
1. To study Memory Placement strategies to understand memory management.
2.
Theory :
CONCEPT OF MEMORY PLACEMENT STRATEGIES:
In the operating system, the following are four common memory management
techniques.
[Link] contiguous allocation: Simplest allocation method used by MS-DOS. All memory
(except some reserved for OS) is available to a process.
Most of the operating systems (for example Windows and Linux) use Segmentation with
Paging. A process is divided into segments and individual segments have pages.
In Partition Allocation, when there is more than one partition freely available to
accommodate a process’s request, a partition must be selected. To choose a particular
partition, a partition allocation method is needed. A partition allocation method is
considered better if it avoids internal fragmentation.
When it is time to load a process into the main memory and if there is more than one free
block of memory of sufficient size then the OS decides which free block to allocate.
A. First Fit
B. Best Fit
C. Worst Fit
D. Next Fit
Advantage:
It is the fastest searching Algorithm as we not to search only first block, we do not need to search
a lot.
Disadvantage:
The main disadvantage of First Fit is that the extra space cannot be used by any other
[Link] the memory is allocated it creates large amount of chunks of memory space.
If the size is less than the size of the first block then only it is allocated. Otherwise, we move to
the second block and this process is continuously going on until all processes are allocated.
This method keeps the free/busy list in order by size – smallest to largest.
In this method, the operating system first searches the whole of the memory according to the size
of the given job and allocates it to the closest-fitting free partition in the memory, making it able
to use memory efficiently. Here the jobs are in the order from smallest job to largest job.
When a process requests memory, the operating system searches the list for the smallest free
block of memory that is large enough to accommodate the process.
If a suitable block is found, the process is allocated memory from that block.
If no suitable block is found, the operating system can either wait until a suitable block becomes
available or request additional memory from the system.
The best-fit allocation algorithm has the advantage of minimizing external fragmentation, as it
searches for the smallest free block of memory that can accommodate a process. However, it can
also lead to more internal fragmentation, as processes may not use the entire memory block
allocated to them.
Overall, the best-fit allocation algorithm can be an effective way to allocate memory in an
operating system, but it is important to balance the advantages and disadvantages of this
approach with other allocation algorithms such as first-fit, next-fit, and worst-fit.
Advantages of Best-Fit Allocation :
Memory Efficient.
The operating system allocates the job minimum possible space in the memory,
making memory management very efficient.
To save memory from getting wasted, it is the best method.
Improved memory utilization
Reduced memory fragmentation
Minimizes external fragmentation
In this allocation technique, the process traverses the whole memory and always search for the
largest hole/partition, and then the process is placed in that hole/partition. It is a slow process
because it has to traverse the entire memory to search the largest hole.
Here Process P1=30K is allocated with the Worst Fit-Allocation technique, so it traverses the
entire memory and selects memory size 400K which is the largest, and hence there is an internal
fragmentation of 370K which is very large and so many other processes can also utilize this
leftover space.
The next fit is a modified version of ‘first fit’. It begins as the first fit to find a free partition but
when called next time it starts searching from where it left off, not from the beginning. This
policy makes use of a roving pointer. The pointer moves along the memory chain to search for
the next fit. This helps in, to avoid the usage of memory always from the head (beginning) of the
free blockchain.
even if the sum of all small pieces is greater than it required which is so-called external
fragmentation problem.
Another problem of the first fit is that it tends to allocate memory parts at the beginning of the
memory, which may lead to more internal fragments at the beginning. Next fit tries to address
this problem by starting the search for the free portion of parts not from the start of the memory,
but from where it ends last time.
Next fit is a very fast searching algorithm and is also comparatively faster than First Fit and Best
Fit Memory Management Algorithms.
Example:
Input : blockSize[] = {5, 10, 20};
processSize[] = {10, 20, 30};
Output:
Process No. Process Size Block no.
1 10 2
2 20 3
3 30 Not Allocated
Algorithm:
Input the number of memory blocks and their sizes and initializes all the blocks as free.
Input the number of processes and their sizes.
Start by picking each process and check if it can be assigned to the current block, if yes,
allocate the required memory and check for next process but from the block where we
left not from starting.
If the current block size is smaller then keep checking the further blocks.
// Process Class
class process {
public:
// Size & number of process
size_t size;
pid_t no;
};
// Memory Class
class memory {
public:
size_t size;
done1 = 0;
if (memory_blocks.at(i).size
>= [Link]().size) {
memory_blocks.at(i).push([Link]());
done = 1;
done1 = 1;
break;
}
}
// If process is done
if (done == 0 && done1 == 0) {
[Link] += [Link]().size;
[Link]([Link]());
}
temp = to_string([Link]).length();
cout << string(7 - temp / 2 - temp % 2, ' ')
<< [Link]
<< string(7 - temp / 2, ' ') << "|";
temp = to_string(memory_blocks.at(i).no).length();
cout << string(7 - temp / 2 - temp % 2, ' ');
// Driver Code
int main()
{
// Declare memory blocks
vector<memory> memory_blocks(5);
memory_blocks[1].no = 2;
memory_blocks[1].size = 500;
memory_blocks[2].no = 3;
memory_blocks[2].size = 300;
memory_blocks[3].no = 4;
memory_blocks[3].size = 200;
memory_blocks[4].no = 5;
memory_blocks[4].size = 100;
[Link] = 1;
[Link] = 88;
[Link] = 2;
[Link] = 192;
[Link] = 3;
[Link] = 277;
[Link] = 4;
[Link] = 365;
[Link] = 5;
[Link] = 489;
-------------+--------------+--------------+
| Process no. | Process size | Memory block |
+-------------+--------------+--------------+
| 1 | 88 | 1 |
| 2 | 192 | 1 |
| 3 | 277 | 2 |
| 4 | 365 | N/A |
| 5 | 489 | N/A |
+-------------+--------------+--------------+
// Driver Method
int main()
{
int blockSize[] = {100, 500, 200, 300, 600};
int processSize[] = {212, 417, 112, 426};
int m = sizeof(blockSize) / sizeof(blockSize[0]);
int n = sizeof(processSize) / sizeof(processSize[0]);
return 0 ;
}
OUTPUT:
<< "\t\t\t\t";
if (allocation[i] != -1)
cout << allocation[i] + 1;
else
cout << "Not Allocated";
cout << endl;
}
}
// Driver program
int main()
{
int blockSize[] = { 5, 10, 20 };
int processSize[] = { 10, 20, 5 };
int m = sizeof(blockSize) / sizeof(blockSize[0]);
int n = sizeof(processSize) / sizeof(processSize[0]);
return 0;
}
OUTPUT:
Process No. Process Size Block no.
1 10 2
2 20 3
3 5 1
#include<bits/stdc++.h>
using namespace std;
// Driver code
int main()
{
int blockSize[] = {100, 500, 200, 300, 600};
int processSize[] = {212, 417, 112, 426};
int m = sizeof(blockSize)/sizeof(blockSize[0]);
int n = sizeof(processSize)/sizeof(processSize[0]);
return 0 ;
}
OUTPUT:
Process No. Process Size Block no.
1 212 5
2 417 2
3 112 5
4 426 Not Allocated
Python implementation
1) First fit
break
# Driver code
if __name__ == '__main__':
blockSize = [100, 500, 200, 300, 600]
processSize = [212, 417, 112, 426]
m = len(blockSize)
n = len(processSize)
firstFit(blockSize, m, processSize, n)
Output :
2) Next Fit
for i in range(n):
print("\t", i + 1, "\t\t\t", processSize[i],end = "\t\t\
t")
if allocation[i] != -1:
print(allocation[i] + 1)
else:
print("Not Allocated")
# Driver Code
if __name__ == '__main__':
blockSize = [5, 10, 20]
processSize = [10, 20, 5]
m = len(blockSize)
n = len(processSize)
NextFit(blockSize, m, processSize, n)
3) Best Fit
# Driver code
if __name__ == '__main__':
blockSize = [100, 500, 200, 300, 600]
processSize = [212, 417, 112, 426]
m = len(blockSize)
n = len(processSize)
bestFit(blockSize, m, processSize, n)
4) Worst fit
# Driver code
if __name__ == '__main__':
blockSize = [100, 500, 200, 300, 600]
processSize = [212, 417, 112, 426]
m = len(blockSize)
n = len(processSize)
worstFit(blockSize, m, processSize, n)
/23
Objective:-
To design a user interface in Python
Learning Outcomes:
Requirements:
Implementa琀椀on Steps:
import the Python GUI Tkinter module:
>>> import tkinter as tk
A window is an instance of Tkinter’s Tk class. Go ahead and create a new window
and assign into the variable window:
When you execute the above code, a new window pops up on your screen. How it
looks depends on your opera琀椀ng system:
text to a window.
Create a Label widget with the text "Hello,Tkinter" and assign it to a variable called gree琀椀ng:
>>>
>>> greeting = [Link] el(text="Hello, Tkinter")
Working With Widgets
Each widget in Tkinter is de昀椀ned by a class. Here are some of the widgets available:
Label widgets are used to display text or images. The text displayed by a Label widget can’t
be edited by the user. It’s for display purposes only. As you saw in the example at the
beginning of this tutorial, you can create a Label widget by instan琀椀a琀椀ng the Label class and
passing a string to the text parameter:
label = [Link](
text="Hello,
Tkinter",
foreground="white", # Set the text color to white
background="black" # Set the background color to
black
)
ou can also control the width and height of a label with the width and height parameters:
label = [Link](
text="Hello,
Tkinter",
fg="white",
bg="black",
width=10,
height=10
Here’s what this label looks like in a window:
he following code creates a widget with a blue background, some yellow text, and a width of 50
text units:
>>> [Link]()
>>> [Link]()
Here’s what that looks like:
Ai Marks: /10
Date of Performance: Sign with Date
/23
Objec琀椀ve:
Learning Outcomes:
Requirements:
Any GUI screen from a selected applica琀椀on.
General structure of the elements on the screen to measure complexity factors.
In the above screen the elements are not placed in a proper symmetry, which
creates user confusion and loss of interest in the interface.
The 昀椀rst requirement is to iden琀椀fy the text boxes and their places on the screen and
then place them in a proper order , also group them as per requirement.
The re-designed screen for the above example is shown in the 昀椀gure below.
To validate the improved screen, complexity of the screen is calculated which shows
the op琀椀miza琀椀on of screen space as well as the user friendly interface.
Calcula琀椀on of complexity:
Original Design
1. 22 elements
2. 6 horizontal (column) alignment points
3. 20 ver琀椀cal (row) alignment points
4. 48 = complexity (addi琀椀on of all counts))
Redesigned Screen
1. 18 elements
2. 7 horizontal (column) alignment points
3. 8 ver琀椀cal (row) alignment points
4. 33 = complexity
Students have to choose an applica琀椀on like the above GUI and calculate the screen complexity
and re-design it by re-arranging the elements on the screen
Conclusion:
Brief descrip琀椀on of the studied method for improving screen design complexity and the
improvement in design by applying this method.