lab report system software
TRANSCRIPT
8/13/2019 Lab Report System Software
http://slidepdf.com/reader/full/lab-report-system-software 1/26
DEPARTMENT
OF
COMPUTER SCIENCE AND ENGINEERING
SYSTEM SOFTWARE
(CS651)
Prijo Cherry Mathews
1017422
A Laboratory Record submitted in partial fulfillmentof the
requirement of System Software Lab
of VIthB.Tech (CSE)
December, 2012
8/13/2019 Lab Report System Software
http://slidepdf.com/reader/full/lab-report-system-software 2/26
Certificate
This is to certify that the record titled System Software Lab (CS651) is a
bonafide record of work done by Pri jo Cherry Mathews in partial fulfillment of
requirement of VI th B.Tech CSE during the year 2012.
HEAD OF THE DEPARTMENT FACULTY-IN-
CHARGE
EXAMINER 1:
ASSOCIATE DEAN EXAMINER 2:
Name : Prijo Cherry Mathews
Register Number : 1017422
Examination Center : CUFE
Date of Examination : ___________________
8/13/2019 Lab Report System Software
http://slidepdf.com/reader/full/lab-report-system-software 3/26
8/13/2019 Lab Report System Software
http://slidepdf.com/reader/full/lab-report-system-software 4/26
System Software Lab (CS652)
Department of Computer Science and Engineering, Christ University 2
struct symbtab
{
char label[10];int addr;
struct symtab *next;
};
struct symbtab *first,*last;
void main()
{
int op;
int y;
char la[10];
clrscr();
do
{
printf("\n 1. Insert");
printf("\n 2. Display");
printf("\n 3. Delete");
printf("\n 4. Search");
printf("\n 5. Modify");
printf("\n 6. Exit");
printf("\n\n Enter your option : ");
scanf("%d",&op);
switch(op)
{
case 1:
insert();
printf("\n Inserted Successfully\n");
break;
case 2:
display();
break;
8/13/2019 Lab Report System Software
http://slidepdf.com/reader/full/lab-report-system-software 5/26
8/13/2019 Lab Report System Software
http://slidepdf.com/reader/full/lab-report-system-software 6/26
System Software Lab (CS652)
Department of Computer Science and Engineering, Christ University 4
scanf("%s",l);
n=search(l);
if(n==1)
{ printf("\n The label already exists. Duplicate cant be inserted\n");
}
else
{
struct symbtab *p;
p=malloc(sizeof(struct symbtab));
strcpy(p->label,l);
printf("\n Enter the address : ");
scanf("%d",&p->addr);
p->next=null;
if(size==0)
{
first=p;
last=p;
}
else
{
last->next=p;
last=p;
}
size++;
}
}
void display()
{
int i;
struct symbtab *p;
p=first;
8/13/2019 Lab Report System Software
http://slidepdf.com/reader/full/lab-report-system-software 7/26
System Software Lab (CS652)
Department of Computer Science and Engineering, Christ University 5
printf("\n\n\t\t LABEL\tADDRESS\n\n");
for(i=0;i<size;i++)
{
printf("\t\t %s\t%d\n\n",p->label,p->addr); p=p->next;
}
}
int search(char lab[])
{
int i,flag=0;
struct symbtab *p;
p=first;
for(i=0;i<size;i++)
{
if(strcmp(p->label,lab)==0)
{
flag=1;
}
p=p->next;
}
return flag;
}
void modify()
{
char l[10],nl[10];
int add, choice, i, s;
struct symbtab *p;
p=first;
printf("\n 1. Modify label");
printf("\n 2. Modify address");
printf("\n 3. Modify label and address");
8/13/2019 Lab Report System Software
http://slidepdf.com/reader/full/lab-report-system-software 8/26
System Software Lab (CS652)
Department of Computer Science and Engineering, Christ University 6
printf("\n Enter your choice : ");
scanf("%d",&choice);
switch(choice)
{case 1:printf("\n Enter the old label\n");
scanf("%s",l);
printf("\n Enter the new label\n");
scanf("%s",nl);
s=search(l);
if(s==0)
{
printf("\n Doesn't Exist");
}
else
{
for(i=0;i<size;i++)
{
if(strcmp(p->label,l)==0)
{
strcpy(p->label,nl);
}
p=p->next;
}
}
break;
case 2:
printf("\n Enter the label whose address is to modified: ");
scanf("%s",l);
printf("\n Enter the new address: ");
scanf("%d",&add);
s=search(l);
if(s==0)
{
8/13/2019 Lab Report System Software
http://slidepdf.com/reader/full/lab-report-system-software 9/26
System Software Lab (CS652)
Department of Computer Science and Engineering, Christ University 7
printf("\n Doesn't Exist");
}
else
{for(i=0;i<size;i++)
{
if(strcmp(p->label,l)==0)
{
p->addr=add;
}
p=p->next;
}
}
break;
case 3:
printf("\n Enter the old label : ");
scanf("%s",l);
printf(" Enter the new label : ");
scanf("%s",nl);
printf(" Enter the new address : ");scanf("%d",&add);
s=search(l);
if(s==0)
{
printf("\n Doesn't Exist");
}
else
{
for(i=0;i<size;i++)
{
if(strcmp(p->label,l)==0)
{
strcpy(p->label,nl);
p->addr=add;
}
p=p->next;
}
}
break;
}
}
8/13/2019 Lab Report System Software
http://slidepdf.com/reader/full/lab-report-system-software 10/26
System Software Lab (CS652)
Department of Computer Science and Engineering, Christ University 8
void del()
{
int a;
char l[10];
struct symbtab *p,*q;
p=first; printf("\n Enter the label to be deleted: ");
scanf("%s",l);
a=search(l);
if(a==0)
{
printf("\n Doesn't Exist\n");
}
else
{
if(strcmp(first->label,l)==0)
{
first=first->next;
}
else if(strcmp(last->label,l)==0)
{
q=p->next;
while(strcmp(q->label,l)!=0)
{
p=p->next;
q=q->next;
} p->next=null;
last=p;
}
else
{
q=p->next;
while(strcmp(q->label,l)!=0)
{
p=p->next;
q=q->next;
} p->next=q->next;
}
size--;
}
}
Result: - The symbol table algorithm was implemented successfully in C.
8/13/2019 Lab Report System Software
http://slidepdf.com/reader/full/lab-report-system-software 11/26
8/13/2019 Lab Report System Software
http://slidepdf.com/reader/full/lab-report-system-software 12/26
System Software Lab (CS652)
Department of Computer Science and Engineering, Christ University 10
MODIFY: -
8/13/2019 Lab Report System Software
http://slidepdf.com/reader/full/lab-report-system-software 13/26
System Software Lab (CS652)
Department of Computer Science and Engineering, Christ University 11
Experiment 2 – Pass One of Two Pass Assembler
Aim: Write a program to implement single pass assembler.
Algorithm:
1. Open and Read the input file
2. If the input line has the opcode "START' do the following
a. Find if there is any operand field after "START', initialize the LOCCTR to the
operand value
b. Otherwise if there is no value in the operand field then LOCC TR is set to 0
3. Write the input line to the intermediate file
4. Do the following steps until the opcode is END
a. Check the Symbol table, if the symbol is not available then enter that symbol
into the SYMTAB, along with the memory address in which it is
stored.Otherwise, the error message should be displayed
b. If there is a opcode
i. If opcode is present in the OPTAB, then increment the LOCCTR by 3
ii. If opcode is "WORD", then increment LOCCTR. by 3;
iii. If opcode is "BYTE", then increment L OCC TR by 1;
iv. If opcode is 'RESW" then increment LOCCTR by the integer
equivalent of the operand value * 3;
v. If opcode is "FESS", then increment LOCCTR by the integer
equivalent of the operand value
c. Write the processed lines in the intermediate file along with their location
counters
5. To find the length of the program, Subtract the starting address of the progam from
the final value of the LOCCTR
6. Close all the files and exit
Program:
# include <stdio.h>
# include <conio.h>
# include <string.h>void main()
8/13/2019 Lab Report System Software
http://slidepdf.com/reader/full/lab-report-system-software 14/26
System Software Lab (CS652)
Department of Computer Science and Engineering, Christ University 12
{
char opcode[10],mnemonic[3],operand[10],label[10],code[10];
int locctr,start,length;
FILE *fp1,*fp2,*fp3,*fp4;
clrscr();
fp1=fopen("input.txt","r");
fp2=fopen("symtab.txt","w");
fp3=fopen("out.txt","w");
fp4=fopen("optab.txt","r");
fscanf(fp1,"%s%s%s",label,opcode,operand);
if(strcmp(opcode,"START")==0)
{
start=atoi(operand);
locctr=start;
fprintf(fp3,"\t%s\t%s\t%s\n",label,opcode,operand);
fscanf(fp1,"%s%s%s",label,opcode,operand);}
else
locctr=0;
while(strcmp(opcode,"END")!=0)
{
fprintf(fp3,"%d\t",locctr);
if(strcmp(label,"**")!=0)
fprintf(fp2,"%s\t%d\n",label,locctr);
rewind(fp4);
fscanf(fp4,"%s",code);while(strcmp(code,"END")!=0)
{
if(strcmp(opcode,code)==0)
{
locctr+=3;
break;
}
fscanf(fp4,"%s",code);
}
if(strcmp(opcode,"WORD")==0)
locctr+=3;else if(strcmp(opcode,"RESW")==0)
locctr+=(3*(atoi(operand)));
else if(strcmp(opcode,"RESB")==0)
locctr+=(atoi(operand));
else if(strcmp(opcode,"BYTE")==0)
++locctr;
fprintf(fp3,"%s\t%s\t%s\n",label,opcode,operand);
fscanf(fp1,"%s%s%s",label,opcode,operand);}
8/13/2019 Lab Report System Software
http://slidepdf.com/reader/full/lab-report-system-software 15/26
System Software Lab (CS652)
Department of Computer Science and Engineering, Christ University 13
fprintf(fp3,"%d\t%s\t%s\t\%s\n",locctr,label,opcode,operand);
length=locctr-start;
printf("The length of the program is %d",length);
fclose(fp1);
fclose(fp2);
fclose(fp3);
fclose(fp4);
getch();
}
Result: - Pass one of two-pass assembler was implemented successfully in C.
Output:
Input Files –
Output Files –
8/13/2019 Lab Report System Software
http://slidepdf.com/reader/full/lab-report-system-software 16/26
System Software Lab (CS652)
Department of Computer Science and Engineering, Christ University 14
Experiment 3 – Pass Two of Two-Pass Assembler
Aim: Write a program to implement pass 2 assembler.
Algorithm:
1. Open and read the first line from the intermediate file.
2. If the first line contains the opcode "START', then write the label, opcode and
operand field values of the corresponding statement directly to the final output file.
3. Do the following steps, until an "END" statement is reached.
a. Start writing the location counter, opcode and operand fields of the
corresponding statement to the output file, along with the object code.
b. If them is no symbol label in the operand field, then the operand address is
assigned as zero and it is assembled with the object code of the instruction
c. If the opcode is BYTE, WORD, RESB etc convert the constants to the object
code.
4. Close the files and exit
Program:
#include<stdio.h>
#include<stdio.h>
#include<conio.h>
#include<string.h>
#include<stdlib.h>
void main()
{
char a[10],ad[10],label[10],opcode[10],operand[10],mnemonic[10],symbol[10];
int i,locctr,code,add,len,actual_len;FILE *fp1,*fp2,*fp3,*fp4;
clrscr();
fp1=fopen("twoout.dat","w");
fp2=fopen("symtab.dat","r");
fp3=fopen("out.dat","r");
fp4=fopen("optab.dat","r");
fscanf(fp3,"%s%s%s",label,opcode,operand);
if(strcmp(opcode,"START")==0)
{
fprintf(fp1,"\t%s\t%s\t%s\n",label,opcode,operand);
fscanf(fp3,"%d%s%s%s",&locctr,label,opcode,operand);
}
8/13/2019 Lab Report System Software
http://slidepdf.com/reader/full/lab-report-system-software 17/26
System Software Lab (CS652)
Department of Computer Science and Engineering, Christ University 15
while(strcmp(opcode,"END")!=0)
{
if(strcmp(opcode,"BYTE")==0)
{
fprintf(fp1,"%d\t%s\t%s\t%s\t",locctr,label,opcode,operand);
len=strlen(operand);
actual_len=len-3;
for(i=2;i<(actual_len+2);i++)
{
itoa(operand[i],ad,16);
fprintf(fp1,"%s",ad);
}
fprintf(fp1,"\n");
}
else if(strcmp(opcode,"WORD")==0)
{len=strlen(operand);
itoa(atoi(operand),a,10);
fprintf(fp1,"%d\t%s\t%s\t%s\t00000%s\n",locctr,label,opcode,operand,a);
}
else if((strcmp(opcode,"RESB")==0)||(strcmp(opcode,"RESW")==0))
{
fprintf(fp1,"%d\t%s\t%s\t%s\n",locctr,label,opcode,operand);
}
else
{rewind(fp4);
fscanf(fp4,"%s%d",mnemonic,&code);
while(strcmp(opcode,mnemonic)!=0)
fscanf(fp4,"%s%d",mnemonic,&code);
if(strcmp(operand,"**")==0)
{
fprintf(fp1,"%d\t%s\t%s\t%s\t%d0000\n",locctr,label,opcode,operand,code);
}
Else
{
rewind(fp2);fscanf(fp2,"%s%d",symbol,&add);
while(strcmp(operand,symbol)!=0){fscanf(fp2,"%s%d",symbol,&add);
}
fprintf(fp1,"%d\t%s\t%s\t%s\t%d%d\n",locctr,label,opcode,operand,code,add);
}
}
fscanf(fp3,"%d%s%s%s\n",&locctr,label,opcode,operand);
}
fprintf(fp1,"%d\t%s\t%s\t%s\n",locctr,label,opcode,operand);
printf("FINISHED");fclose(fp1);
8/13/2019 Lab Report System Software
http://slidepdf.com/reader/full/lab-report-system-software 18/26
System Software Lab (CS652)
Department of Computer Science and Engineering, Christ University 16
fclose(fp2);
fclose(fp3);
fclose(fp4);
getch();
}
Result: - Pass two of Two-Pass Assembler was implemented successfully in C.
Output:
Input Files: –
Output files: -
8/13/2019 Lab Report System Software
http://slidepdf.com/reader/full/lab-report-system-software 19/26
8/13/2019 Lab Report System Software
http://slidepdf.com/reader/full/lab-report-system-software 20/26
System Software Lab (CS652)
Department of Computer Science and Engineering, Christ University 18
iv. If opcode is "RESW" then increment LC by the integer equivalent of
the operand value * 3
v. If opcode is "RESB", then increment LC by the integer equivalent of
the operand valuevi. If them is no symbol label in the operand field, then the operand
address is assigned as zero and it is assembled with the object code of
the instruction
vii. Writ the processed lines in the intermediate file along with their
location counters
5. 5. To find the length of the program, Subtract the starting address of the progam from
the final value of the LC
6. Close all the files and exit
Program:
#include<stdio.h>
#include<stdlib.h>
#include<conio.h>
#include<string.h>
void main()
{
FILE *f1,*f2,*f3,*f4,*f5;
int lc,sa,i=0,j=0,m[10],pgmlen,len,k,len1,l=0;
char name[10],opnd[10],la[10],mne[10],s1[10],mne1[10],opnd1[10];
char lcs[10],ms[10];
char sym[10],symaddr[10],obj1[10],obj2[10],s2[10],q[10],s3[10];
clrscr();
f1=fopen("input.txt","r");
f2=fopen("optab.txt","r");
f3=fopen("symtab.txt","w+");
f4=fopen("symtab1.txt","w+");
f5=fopen("output.txt","w+");
fscanf(f1,"%s%s%s",la,mne,opnd);
if(strcmp(mne,"START")==0)
8/13/2019 Lab Report System Software
http://slidepdf.com/reader/full/lab-report-system-software 21/26
System Software Lab (CS652)
Department of Computer Science and Engineering, Christ University 19
{
sa=atoi(opnd);
strcpy(name,la);
lc=sa;}
strcpy(s1,"*");
fscanf(f1,"%s%s%s",la,mne,opnd);
while(strcmp(mne,"END")!=0)
{
if(strcmp(la,"-")==0)
{
fscanf(f2,"%s%s",mne1,opnd1);
while(!feof(f2))
{
if(strcmp(mne1,mne)==0)
{
m[i]=lc+1;
fprintf(f3,"%s\t%s\n",opnd,s1);
fprintf(f5,"%s\t0000\n",opnd1);
lc=lc+3;
i=i+1;
break;
}
else
fscanf(f2,"%s%s",mne1,opnd1);
}
}
else
{
fseek(f3,SEEK_SET,0);
fscanf(f3,"%s%s",sym,symaddr);
8/13/2019 Lab Report System Software
http://slidepdf.com/reader/full/lab-report-system-software 22/26
System Software Lab (CS652)
Department of Computer Science and Engineering, Christ University 20
while(!feof(f3))
{
if(strcmp(sym,la)==0)
{itoa(lc,lcs,10);
fprintf(f4,"%s\t%s\n",la,lcs);
itoa(m[j],ms,10);
j=j+1;
fprintf(f5,"%s\t%s\n",ms,lcs);
i=i+1;
break;
}
else
fscanf(f3,"%s%s",sym,symaddr);
} //f3
if(strcmp(mne,"RESW")==0)
lc=lc+3*atoi(opnd);
else if(strcmp(mne,"BYTE")==0)
{
strcpy(s2,"-");
len=strlen(opnd);
lc=lc+len-2;
for(k=2;k<len;k++)
{
q[l]=opnd[k];
l=l+1;
}
fprintf(f5,"%s\t%s\n",q,s2);
break;
}
else if(strcmp(mne,"RESB")==0)
lc=lc+atoi(opnd);
else if(strcmp(mne,"WORD")==0)
8/13/2019 Lab Report System Software
http://slidepdf.com/reader/full/lab-report-system-software 23/26
System Software Lab (CS652)
Department of Computer Science and Engineering, Christ University 21
{
strcpy(s3,"#");
lc=lc+3;
fprintf(f5,"%s\t%s\n",opnd,s3); break;
}
} // else la=-
fseek(f2,SEEK_SET,0);
fscanf(f1,"%s%s%s",la,mne,opnd);
}
fseek(f5,SEEK_SET,0);
pgmlen=lc-sa;
printf("H^%s^%d^0%x\n",name,sa,pgmlen);
printf("T^");
printf("00%d^0%x",sa,pgmlen);
fscanf(f5,"%s%s",obj1,obj2);
while(!feof(f5))
{
if(strcmp(obj2,"0000")==0)
printf("^%s%s",obj1,obj2);
else if(strcmp(obj2,"-")==0)
{
printf("^");
len1=strlen(obj1);
for(k=0;k<len1;k++)
printf("%d",obj1[k]);
}
else if(strcmp(obj2,"#")==0)
{
printf("^");
printf("%s",obj1);
8/13/2019 Lab Report System Software
http://slidepdf.com/reader/full/lab-report-system-software 24/26
System Software Lab (CS652)
Department of Computer Science and Engineering, Christ University 22
}
fscanf(f5,"%s%s",obj1,obj2);
}
fseek(f5,SEEK_SET,0);fscanf(f5,"%s%s",obj1,obj2);
while(!feof(f5))
{
if(strcmp(obj2,"0000")!=0)
{
if(strcmp(obj2,"-")!=0)
{
if(strcmp(obj2,"#")!=0)
{
printf("\n");
printf("T^%s^02^%s",obj1,obj2);
}
}
}
fscanf(f5,"%s%s",obj1,obj2);
}
printf("\nE^00%d",sa);
getch();
}
Result: - The Single-Pass assembler was implemented successfully in C.
Output: -
INPUT FILE:- OPTAB FILE:-
8/13/2019 Lab Report System Software
http://slidepdf.com/reader/full/lab-report-system-software 25/26
System Software Lab (CS652)
Department of Computer Science and Engineering, Christ University 23
SYMTAB FILE: - REFERENCE FILE: -
OUTPUT FILE: -
8/13/2019 Lab Report System Software
http://slidepdf.com/reader/full/lab-report-system-software 26/26