Top Banner
8/8/2019 Final File Sp http://slidepdf.com/reader/full/final-file-sp 1/44 SUBMITTED TO: SUBMITED BY:  1
44

Final File Sp

Apr 09, 2018

Download

Documents

Haspreet Singh
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Final File Sp

8/8/2019 Final File Sp

http://slidepdf.com/reader/full/final-file-sp 1/44

SUBMITTED TO: SUBMITED BY: 

1

Page 2: Final File Sp

8/8/2019 Final File Sp

http://slidepdf.com/reader/full/final-file-sp 2/44

NAME OF THE EXPERIMENT PAGENO. REMARKS

1. BASIC C++ PROGRAMS

a) To multiply two 3-digit nums

without direct multiplication

b) To perform various set operations

c) To find the inverse of a matrix

d) To find the reverse of a number

e) To perform switch case statements

 

2. ASSEMBLERS

3. STUDY OF COMPILERS & IT’S PHASES

 

4. EDITORS

5. MICRO PROCESSOR 8085 INSTRUCTION SET

6. STUDY OF LEXICAL & SYNTAX ANALYSIS

7. DEBUGGING IN C++ ENVIRONMENT

 

2

Page 3: Final File Sp

8/8/2019 Final File Sp

http://slidepdf.com/reader/full/final-file-sp 3/44

To multiply two 3-digit numbers without direct multiplication

#include<iostream.h>

#include<conio.h>

void main()

{ int flag;

int m1,m2;int r1,temp1=0,r2,temp2=0;

do

{ clrscr();

int n1,n2;

cout<<"Enter multiplicand:";

cin>>n1;

m1=n1;cout<<"\n\nEnter multiplier:";

cin>>n2;m2=n2;

//loop to check first no.

while(n1!=0)

{ r1=n1%10;

n1=n1/10;temp1++;

}

//loop to check second no.

while(n2!=0)

{ r2=n2%10;n2=n2/10;

temp2++;

}

if(temp1!=3||temp2!=3)

{

cout<<"\n\nPlease enter three digit no.......";flag=0;

temp1=0;

temp2=0;getch();

}

elseflag=1;

3

Page 4: Final File Sp

8/8/2019 Final File Sp

http://slidepdf.com/reader/full/final-file-sp 4/44

}while(flag==0);

int term=0,mul=0;

cout<<"\n\nMultiplication is......";cout<<"\n\n\t\t\t"<<m1;

cout<<"\n\n\t\t\t "<<m2;

cout<<"\n\n\t\t ------------------";

//loop to multiply

int k=1;while(m2!=0)

{ r1=m2%10;

term=m1*r1;

m2=m2/10;cout<<"\n\n\t\t\t"<<setw(5)<<term;

term=term*k;

k=k*10;

mul=mul+term;

}

cout<<"\n\n\t\t ------------------";

cout<<"\n\n\t\t\t"<<mul;getch();

}

4

Page 5: Final File Sp

8/8/2019 Final File Sp

http://slidepdf.com/reader/full/final-file-sp 5/44

Output:

Enter multiplicand:345

Enter multiplier:456

Multiplication is......

345

456

------------------

2070

1725

1380

------------------

26248

To perform various set operations

5

Page 6: Final File Sp

8/8/2019 Final File Sp

http://slidepdf.com/reader/full/final-file-sp 6/44

#include<iostream.h>#include<conio.h>

void main(){ clrscr();

int a[20],b[20],c[40],j,n,m,k,choice;

int i;cout<<"Enter no of elements of a";

cin>>n;

cout<<"\nEnter ";

for(i=0;i<n;i++){ cin>>a[i];

}

cout<<"Enter no of elements of b";

cin>>m;cout<<"\nEnter ";

for(i=0;i<m;i++){ cin>>b[i];

}

while(1){cout<<"\n\t\tMENU";

cout<<"\n\t\t1.inter";

cout<<"\n\t\t2.union";

int ch;cout<<"\nEnter choice";

cin>>ch;

if(ch==2)

{ for(i=0;i<n;i++){ c[i]=a[i];

}

int k=n;

for(i=0;i<m;i++){ for(j=0;j<n+i;j++)

{ if(c[j]==b[i])

 break;}

if(j==n+i)

{c[k]=b[i];

k++;

}}

6

Page 7: Final File Sp

8/8/2019 Final File Sp

http://slidepdf.com/reader/full/final-file-sp 7/44

cout<<"\nUNION ";

for(i=0;i<k;i++)

{ cout<<c[i];}

}

k=0;if(ch==1)

{ for(i=0;i<n;i++)

{ for(j=0;j<m;j++)

{ if(a[i]==b[j]){ c[k]=a[i];

k++;

break;}

}

}

cout<<"\nINTERSECTION ";

for(i=0;i<k;i++)

{ cout<<c[i];}

}

cout<<"\nWANT TO EXIT?(enter1)";cin>>choice;

if(choice==1)

break;}

}

Output:

7

Page 8: Final File Sp

8/8/2019 Final File Sp

http://slidepdf.com/reader/full/final-file-sp 8/44

Enter no of elements of a4

Enter 5

27

1

Enter no of elements of b4

Enter 7

3

82

MENU

1.inter 2.union

Enter choice2

UNION 527138

WANT TO EXIT?(enter1)

To find the inverse of a matrix

8

Page 9: Final File Sp

8/8/2019 Final File Sp

http://slidepdf.com/reader/full/final-file-sp 9/44

#include<iostream.h>

#include<conio.h>

int a[2][2];int det(int,int);

void main()

{ clrscr();

int i,j;cout<<"Enter elements";

for(i=0;i<2;i++)

{ //cout<<"\n";for(j=0;j<2;j++)

{ //a[i][j]=getche();

//cout<<"\t";

cin>>a[i][j];}

}

cout<<"\nElements are";

for(i=0;i<2;i++)

{ cout<<"\n\n";for(j=0;j<2;j++)

{ cout<<a[i][j]<<"\t";

}}

cout<<det(0,0);

getch();

}

int det(int i,int j){ int d=0;

d+=a[i][j]*a[i+1][j+1];

d-=a[i][j+1]*a[i+1][j];return d;

}

Output:

9

Page 10: Final File Sp

8/8/2019 Final File Sp

http://slidepdf.com/reader/full/final-file-sp 10/44

Enter elements57

2

3

Elements are

5 7

2 3 1

To find the reverse of a number

10

Page 11: Final File Sp

8/8/2019 Final File Sp

http://slidepdf.com/reader/full/final-file-sp 11/44

#include<iostream.h>#include<conio.h>

void main()

{ clrscr();

int num,rev;

cout<<"\nEnter num";

cin>>num;cout<<"\Rev is";

while(num>1)

{rev=num%10;

cout<<rev;

num=num/10;

}getch();

}

Output:

Enter num573Rev is375

11

Page 12: Final File Sp

8/8/2019 Final File Sp

http://slidepdf.com/reader/full/final-file-sp 12/44

//PROGRAM TO PERFORM SWITCH CASE STATEMENTS

#include<iostream.h>#include<conio.h>

#include<process.h>

void table();

void prime();void matrix();

void fibo();

void fact();void evodd();

void main()

{ char ch;

do{clrscr();

cout<<"MENU:-";

cout<<"\n\n1. To generate table of the no.";cout<<"\n2. To check wheteher the no. is prime or not";

cout<<"\n3.To perform matrix operations";

cout<<"\n4.To print fibonacci series";cout<<"\n5.To print factorial of no.";

cout<<"\n6.To check whether the no. is even or odd";

cout<<"\n7.Exit";int cho;

cout<<"\n\nEnter your choice(1-7):";

cin>>cho;switch(cho)

{ case 1: table();

 break;

case 2: prime(); break;

case 3: matrix(); break;

case 4: fibo();

break;case 5: fact();

 break;

case 6: evodd();

 break;case 7: exit(0);

 

12

Page 13: Final File Sp

8/8/2019 Final File Sp

http://slidepdf.com/reader/full/final-file-sp 13/44

default : cout<<"\nWrong choice!!!";

}

cout<<"\n\nDo you want to continue with more operations(y or n):";

cin>>ch;

}while(ch=='Y'||ch=='y');getch();

}

void table(){ int n;

cout<<"\nEnter the no.:";

cin>>n;for(int i=1;i<=10;i++)

{

cout<<"\n"<<n<<"\t"<<"*\t"<<i<<"\t"<<"="<<"\t"<<n*i;

}}

void prime(){ int n;

cout<<"\nEnter the no.:";

cin>>n;for(int i=2;i<n;i++)

{ if(n%i==0)

{ cout<<"\n\nNo. is not prime";  break; }

}

if(n==i)cout<<"\n\nThe no is prime";

}

void matrix()

{ clrscr();

int a[20][20],b[20][20],c[20][20];int m,n,p,q,r,s;

int i,j;

cout<<"\nEnter the no. of rows in first matrix:";cin>>m;

cout<<"\nEnter the no. of coulmns in first matrix:";

cin>>n;

cout<<"\nEnter the no. of rows in second matrix:"; 

13

Page 14: Final File Sp

8/8/2019 Final File Sp

http://slidepdf.com/reader/full/final-file-sp 14/44

cin>>p;

cout<<"\nEnter the no. of columns in second matrix:";

cin>>q;//input for matrix a

cout<<"\n\nEnter the elements of first matrix......";

for(i=1;i<=m;i++){ for(j=1;j<=n;j++)

{ cout<<"\nEnter the ("<<i<<","<<j<<") element of the matrix:";

cin>>a[i][j];

}}

//input for matrix b

cout<<"\n\nEnter the elements of second matrix......";for(i=1;i<=p;i++)

{ for(j=1;j<=q;j++)

{ cout<<"\nEnter the ("<<i<<","<<j<<") element of the matrix:";

cin>>b[i][j];}

}

//asking for operationcout<<"\n\nWhat do you want to perform:";

cout<<"\n\n1.Addition";

cout<<"\n2.Subtraction";cout<<"\n3.Multiplication";

cout<<"\n4.Exit";

int ch1;cout<<"\n\nEnter your choice:";

cin>>ch1;

switch(ch1)

{ case 1 : if((m==p)&&(n==q))

{ for(i=1;i<=p;i++)

{ for(j=1;j<=q;j++){ c[i][j]=a[i][j]+b[i][j];

}

}cout<<"\n\nMatrix obtained after addition is:";

for(i=1;i<=p;i++)

{ cout<<"\n\n";for(j=1;j<=q;j++)

{ cout<<c[i][j]<<"\t";

}

cout<<"\n";

14

Page 15: Final File Sp

8/8/2019 Final File Sp

http://slidepdf.com/reader/full/final-file-sp 15/44

}

}

else{ cout<<"\n\nMatrix can not be added";

}

break;case 2 : if((m==p)&&(n==q))

{ for(i=1;i<=p;i++)

{ for(j=1;j<=q;j++)

{ c[i][j]=a[i][j]-b[i][j];

}

}cout<<"\n\nMatrix obtained after subtraction is:";

for(i=1;i<=p;i++)

{ cout<<"\n\n";

for(j=1;j<=q;j++){ cout<<c[i][j]<<"\t";

}

cout<<"\n";}

}

else{ cout<<"\n\nMatrix can not be subtracted";

}

break;case 3 : if(n==p)

{ for(i=1;i<=m;i++)

{ for(j=1;j<=q;j++){c[i][j]=0;

for(int k=1;k<=n;k++)

{ c[i][j]=c[i][j]+a[i][k]*b[k][j];

}}

}

cout<<"\n\nMatrix obtained after multiplication is:";for(i=1;i<=m;i++)

{ cout<<"\n\n";

for(j=1;j<=q;j++){ cout<<c[i][j]<<"\t";

}

 

cout<<"\n";

}}

15

Page 16: Final File Sp

8/8/2019 Final File Sp

http://slidepdf.com/reader/full/final-file-sp 16/44

else

{ cout<<"\n\nMatrix can not be multiplied";

}break;

default : cout<<"\n\nReturning to main menu....";

}}

void fibo()

{ int curr=1,prev=0,next;int n;

cout<<"\n\nHow many elements of the fibonacci series you want:";

cin>>n;if(n==1)

{ cout<<"\n"<<prev;

}

else if(n==2){ cout<<"\n"<<prev<<"\t"<<curr; }

else

{ cout<<"\nThe fibonacci series is:\n";curr=1;

prev=0;

next=prev+curr;cout<<prev<<"\t"<<curr<<"\t";

for(int i=3;i<=n;i++)

{ cout<<next<<"\t";prev=curr;

curr=next;

next=prev+curr;}

}

}

void fact()

{ int n,fact=1;

cout<<"\n\nEnter the no. whose factorial is to be find out:";cin>>n;

for(int i=n;i>=1;i--)

{fact=fact*i;}

cout<<"\n\nThe factorial of the no. is:"<<fact;

}

16

Page 17: Final File Sp

8/8/2019 Final File Sp

http://slidepdf.com/reader/full/final-file-sp 17/44

void evodd()

{ int n;

cout<<"\n\nEnter the no.:";cin>>n;

if(n%2==0)

cout<<"\n\nThe no. "<<n<<" is even no.";else

cout<<"\n\nThe no. "<<n<<" is odd no.";

}

MENU:-

1. To generate table of the no.

2. To check wheteher the no. is prime or not

3.To perform matrix operations4.To print fibonacci series

17

Page 18: Final File Sp

8/8/2019 Final File Sp

http://slidepdf.com/reader/full/final-file-sp 18/44

5.To print factorial of no.

6.To check whether the no. is even or odd

7.Exit

Enter your choice(1-7):1

Enter the no.:5

5 * 1 = 5

5 * 2 = 105 * 3 = 15

5 * 4 = 20

5 * 5 = 255 * 6 = 30

5 * 7 = 35

5 * 8 = 40

5 * 9 = 455 * 10 = 50

MENU:-

1. To generate table of the no.2. To check wheteher the no. is prime or not

3.To perform matrix operations

4.To print fibonacci series5.To print factorial of no.

6.To check whether the no. is even or odd

7.Exit

Enter your choice(1-7):2

Enter the no.:23

The no is prime

Do you want to continue with more operations(y or n):n

ASSEMBLERS :- 

18

Page 19: Final File Sp

8/8/2019 Final File Sp

http://slidepdf.com/reader/full/final-file-sp 19/44

Assembler is a system program which converts a program written in assembly language into

machine language. Assembly language is a special language in which we use special mnemonic

symbols for each instruction . It takes input of an assembly language program known as source

 program and converts it into an equivalent machine language program which is our object program.

General design procedure:-

1. specify the problem

2. specify data structure

3. define format of DS

4. specific algorithm

5. look for modularity, i.e. capability on one program to be subdivided into several sub

 programs.

6. Repeat step 1 to 5 until our problem is resolved .

  Passes in assembler :-

There are two passes in assembler.

(1) Pass1 & (2) Pass2

PASS1 :-

The purpose of pass1 is to define symbols and literals . following are the steps included in pass1.

1. determine length of machine imstruction .it is known as MOTGET1.

2. Keep track of location counter .

3. rememeber values of symbols until pass2. it is known as STSTO.

4. process some pseudo ops like EQU, DS . it is known as POTGET!.

5. remember literals . it is known as LITSTO(literal store).

PASS 2 :-

The purpose of pass2 is to generate object program. Following are steps included in pass2.

19

Page 20: Final File Sp

8/8/2019 Final File Sp

http://slidepdf.com/reader/full/final-file-sp 20/44

1. look up value of symbols . it is known as STGET(single table get).

2. Generate instructions . it is known as MOTGET.

3. Generate data for DS(define storage), DC(define constant) and literals.

4. Process of pseudo ops .it is known as POTGET2.

program to implement pass1 of assembler

1. program to make MACHINE OPCODE TABLE & PSUEDO OPCODE TABLE

#include<stdio.h>#include<conio.h>

20

Page 21: Final File Sp

8/8/2019 Final File Sp

http://slidepdf.com/reader/full/final-file-sp 21/44

#include<process.h>

void main()

{clrscr();

struct mot

{char mnemonic[15];

int length;

};

char another;struct mot m;

FILE *a;

a=fopen ("aman.dat","a");int l;

do

{

 printf("enter mnemonic:");scanf("%s",m.mnemonic);

 printf("enter length:");

scanf("%d",&m.length);fwrite(&m,sizeof(m),l,a);

 printf("enter another (y/n):");

another=getche();}

while(another=='y');

fclose (a);struct pot

{

int memory;char pop[15];

};

struct pot p;

FILE *d;char more;

d=fopen("aman1.dat","a");

do{

 printf("\n enter psuedoopcode:");

scanf("%s",&p.pop);

 printf("enter memory length:");scanf("%d",&p.memory);

fwrite(&p,sizeof(p),l,d);

 printf("enter more (y/n):");scanf("%s",&more);

21

Page 22: Final File Sp

8/8/2019 Final File Sp

http://slidepdf.com/reader/full/final-file-sp 22/44

}

while(more=='y');

fclose(d);}

2. program to enter SYMBOL TABLE

#include<stdio.h>

#include<process.h>

#include<conio.h>void main()

{

clrscr();struct st

22

Page 23: Final File Sp

8/8/2019 Final File Sp

http://slidepdf.com/reader/full/final-file-sp 23/44

{

char symbol[15];

int value;int length;

};

struct st s;char another='y';

FILE *a;

a=fopen("har.cpp","w");

struct lt l;while(another=='y')

{

 printf("enter symbol");scanf("%s",&s.symbol);

 printf("enter value");

scanf("%s",&s.value);

getch();

 printf("enter length");

scanf("%d,",s.length);

fwrite(&s,sizeof(s),1,a); printf("enter more");

scanf("%s",&another);

}fclose(a);

}

3. Program to enter assembly language program

#include <stdio.h>#include<conio.h>

Void main( )

{

Clrscr( );Struct assembly

{

Char label [15];Char opcode[15];

23

Page 24: Final File Sp

8/8/2019 Final File Sp

http://slidepdf.com/reader/full/final-file-sp 24/44

Char op1 [10];

Char op2 [10];

};Char another;

Struct assembly s;

File *a;a = fopen (“aman2.dat”,”a”);

do

{

Print f (“entr label:”);Scanf(“%s”,&s.label);

Print f(“entr opcode:”);

Scanf (“%s”,&s.opcode);Print f(“entr op1:”);

Scan f(“%s”,&s.op1);

Print f(“entr op2:”);

Scan f(“%s”,&s.op2);Fwrite(&s,sizeof(s),1,a);

Print f(“enter another (y/n):”);

Another=getche( );Print f(“\n”);

}

While(another= =’y’);Fclose(a);

}

4. Program to generate value of LOCATION COUNTER 

#include<stdio.h>

#include<conio.h>

#include<process.h>

#include<string.h>struct assembly

{

char label[15];char opcode[15];

24

Page 25: Final File Sp

8/8/2019 Final File Sp

http://slidepdf.com/reader/full/final-file-sp 25/44

char op1[10];

char op2[10];

};struct mot

{

char mnemonic[15];int length;

};

struct pot

{int memory;

char pop[15];

};void main()

{

struct assembly s;

struct mot m;struct pot p;

int x;

int lc;FILE *a,*b,*c;

a=fopen("aman2.dat","r");

 b=fopen("aman.dat","r");c=fopen("aman1.dat","r");

while(fread(&s,sizeof(s),1,a)>0)

{ b=fopen("aman.dat","r");

while(fread(&m,sizeof(m),1,b)>0)

{

if(strcmp(s.opcode,m.mnemonic)==0)

{lc=lc+m.length;

}

}while(fread(&p,sizeof(p),1,c)>0)

{

if(strcmp(s.opcode,p.pop)==0)

{lc=lc+p.memory;

}

}fclose(b);

25

Page 26: Final File Sp

8/8/2019 Final File Sp

http://slidepdf.com/reader/full/final-file-sp 26/44

fclose(c);

}

fclose(a); printf("lc is %d",lc);

getch();

}

STUDY OF LEXICAL & SYNTAX ANALYSIS

LEXICAL ANALYSIS:

  It is a first phase of the compiler. In this phase compiler separates characters

of source language into groups that logical belongs together. These groups are tokens. This part of 

compiler is known as lexical analyzer or scanner. On order to perform lexical analyzer must know

what are the tokens of the language to implemented .i.e. It must we know identifiers ,keywords ,

operators or punctuations symbols etc. so that when it scan the source program it will be able to

return a suitable tokens.

26

Page 27: Final File Sp

8/8/2019 Final File Sp

http://slidepdf.com/reader/full/final-file-sp 27/44

SYNTAX ANALYSIS:

It is also known as passing and the program used for this purpose is known

as parser. A parser obtains a string of tokens from the lexical analyzer and verify whether the string

is valid instruct of the source language .for this purpose of parser either attempts to derive the string

of tokens W from the start symbol S or attempts to reduce W to start symbol S of the grammar.

TWO TYPES OF PARSING:

1.) TOP-DOWN PARSING

2.) BOTTOM-UP PARSING

LEFTMOST DERIVATION:

If while generating a language from a given grammar. We don’t scan

the next variable until the leftmost variable scanned as leftmost derivation.

RIGHTMOST DERIVATION:

While generating a language from a given grammar we don’t scan

the next variable until the rightmost variable is scanned is known as rightmost derivation.

TOP-DOWN PARSING:

  In an attempt to generate a leftmost derivation of a given grammar. The

 basic idea is to parse our program starting from top and moving bottom. It means until or unless our 

first line is not error free or correct according to syntax .we can not move on to next line. E.g.

LL(K) grammar context free grammars called LL(K) from left to right scan producing a left most

derivation with K symbols look ahead if we can always make a correct decision by checking at

most the first K symbols of W. Let this is our context free grammar.

 

P is S A+B-C

 

A b

27

Page 28: Final File Sp

8/8/2019 Final File Sp

http://slidepdf.com/reader/full/final-file-sp 28/44

B c

C d

 

BOTTOM –UP PARSING:

While parsing our program if we are moving starting from bottom and

going to top of our source program then it is known as bottom up parsing. The basic idea is unless or 

until the last line of our source program is not error free or correct according to the syntax. We can

not move to the next line and it is equivalent to finding the right most derivation of any grammar.e.g.

LR (K) grammar: while finding a rightmost derivation of any grammar by looking ahead K symbols

we determine which production to use then is known as LR (K) grammar. It equivalent to finding

the right most derivation of the grammar. Let this is our given grammar.

Instruction set of 8085 microprocessor 

INTRODUCTION:

An instruction is a command given to the computer to perform a specified operation on given data.

These instructions are classified into following groups:

1. Data Transfer Group

2. Arithmetic Group

3. Logical Group

4. Branch Control

5. I/O and machine Control

28

Page 29: Final File Sp

8/8/2019 Final File Sp

http://slidepdf.com/reader/full/final-file-sp 29/44

Data Transfer Group: Instructions which are used to transfer data from one register to another 

register, from memory to register or register to memory. Various commands are:

1. MOV r1, r2: Move data; Move the content of one register to another.

2. MOV r, M: Move the content of memory to register.

3. MOV M, r: Move the content of register to memory.

4. MVI r, data: Move immediate data register.

5. LXI rp, data 16: Load registers pair immediate.

6. LDA addr: Load accumulator direct.

7. STA addr: Store accumulator direct.

8. LHLD addr: Load H-L pair direct.

9. SHLD addr: Store H-L pair direct.

10. XCHG: Exchange the contents of H-L with D-E pair.

Arithmetic Group: The instructions of this group perform arithmetic operations such as addition,

subtraction, increment, decrement of the contents of the register or memory. Various commands are:

1. ADD r: Add register to accumulator.

2. ADD M: Add memory to accumulator.

3. ADC r: Add register with carry to accumulator.

4. ADC M: Add memory with carry to accumulator.

5. ADI data: Add immediate data to accumulator.

6. DAD rp: Add register pair to accumulator.

7. SUB r: Subtract register from accumulator.

8. SUB M: Subtract memory from accumulator.

9. SBI data: Subtract immediate data from accumulator with borrow.

10. INR r: Increment registers content.

11. INR M: Increment memory content.

12. DCR r: Decrement registers content.

29

Page 30: Final File Sp

8/8/2019 Final File Sp

http://slidepdf.com/reader/full/final-file-sp 30/44

Logical Group: The instructions under this group perform logical operations such as AND, OR,

COMPARE, ROTATE etc.Various commands are:

1. ANA r: AND register with accumulator.

2. ANA M: AND memory with accumulator.

3. ANI data: AND immediate data with accumulator.

4. ORA r: OR register with accumulator.

5. ORA M: OR memory with accumulator.

6. XRA r: EXCLUSIVE –OR register with accumulator.

7. XRA M: EXCLUSIVE-OR memory with accumulator.

8. CMA: Complement accumulator.

9. CMC: Complement the carry status.

10. STC: Set carry status.

11. CPI data: Compare immediate data with accumulator.

12. RLC: Rotate accumulator left.

13. RAL: Rotate accumulator left through carry.

14. RAR: Rotate accumulator right through carry.

Branch Control Group:

This group includes the instructions for conditional and unconditional jump, subroutine call and

return and restart.Various Commands are:

1. JMP addr (label): unconditional Jump: jump to the instruction specified by the address.

2. Conditional jump addr: after the execution of the conditional jump instruction the program

 jumps to the instruction specified by the address. If the specified condition is fulfilled.

3. CALL addr: Unconditional call; Call the subroutine identify by the address.

4. RET: Return from subroutine.

5. RST n: Restart: It is a one word CALL instruction.

 

30

Page 31: Final File Sp

8/8/2019 Final File Sp

http://slidepdf.com/reader/full/final-file-sp 31/44

Stack and I/O, Machine Control Group: This group includes the instructions from I/O ports,

Stack and machine control. Various commands are:

1. IN Port addr: Input to accumulator from I/O port.

2. OUT Port addr: Output from accumulator to I/O port.

3. PUSH PSW: Push processor status word.

4. PUSH rp: Push the content of register pair to Stack.

5. POP rp: Pop the content of register pair to Stack.

6. HLT: Halt

7. EI: Enable interrupts.

8. DI: Disable interrupts.

9. SIM: Set interrupt mask.

10. RIM: Read interrupt mask.

11. NOP: No operation.

STUDY OF COMPILER AND ITS VARIOUS PHASES

COMPILER:

Compiler is a system program which converts a program written in high level language into

machine language. The high level language program given as input is known as source program and

machine equivalent is known as object program. The functionality of compiler is divided into seven

 phases:

1. Lexical Phase 2. Syntax Phase

3. Interpretor Phase 4. optimisation5. Storage Assignment 6. Assembly Phase

7. Code Generation

31

Page 32: Final File Sp

8/8/2019 Final File Sp

http://slidepdf.com/reader/full/final-file-sp 32/44

 

Phases of a compiler

1. LEXICAL PHASE:

Action of parsing source program into proper classes is the task of lexical analyzer. The

 program is scanned and separated into basic elements known as tokens. The basic elements

like identifier, literals are placed into tables as other phases recognize the use and meaning of 

elements further information is entered into these tables like data types, length, storage

classes etc.

 

2. SYNTAX PHASE:

32

Page 33: Final File Sp

8/8/2019 Final File Sp

http://slidepdf.com/reader/full/final-file-sp 33/44

Compiler interprets the meaning of the constant syntax analyzer is also known as parsing.

The basic function of the syntax phase is to recognize the major constructs of language and to

calculate the appropriate action routines that will generate the intermediate form or matrix for 

these constructs.

INTERMEDIATE PHASE:Once the program is correct according to syntax , the compiler generates a intermediate code

, in this phase , the intermediate code is compiler directed .This intermediate co ode may be

in form of parse tree ,postfix notation and three address code .

OPTIMISATION:

Any program is set to be optimized, if it is consumes less memory and the compiler time is

fast.The code optimizer receives intermediate code and optimize them considering the like

memory,execution time and other. This phase removes the retandent code.

STORAGE ASSUGNMENT:

It is the process of allocating memory to various resources. The memory can be allocated to

various literals, storage, symbols, machine-OP etc. also the processing environment may

need some memory. All these memory allocation are performed by compiler in this phase.

CODE GENERATION:

It is the last phase of compiler. This phase receives optimized intermediate code and

generates the code for execution. This code generated generally will be relocatable machine

code or assembly code. This phase generates the executed code. It receives the input from

intermediate code generator from code optimizer in case of optimizing compilers. The input

to code generator must be error free, it must have undergone lexical analysis, syntax and

other intermediate phases. The target program may be in the form of 

33

Page 34: Final File Sp

8/8/2019 Final File Sp

http://slidepdf.com/reader/full/final-file-sp 34/44

1. Assembly language

2. Relocate machine code

3. Absolute machine language

The absolute machine code is 1 which is ready to be executed. It is

Linker and loaded by the loader, thus making it ready for execution.

DEBUGGING

Locating and removing errors is known as debugging.

A debugger is a system program which locates bugs and removes them.

Debugging Procedure:

1. Type any program in the given language.

2. Compile it.

3. Look for errors.

4. Remove errors and recompile the program.

5. Repeat steps 3 & 4 until our program becomes error free.

CASE STUDY: Debugging in C++ environment

We can divide the debugging procedure in C++ in tywo main categories:

1. Single-step control debugging

2. Break point control debugging

34

Page 35: Final File Sp

8/8/2019 Final File Sp

http://slidepdf.com/reader/full/final-file-sp 35/44

Single step control debugging:

There are three main methods of debugging in C++ ewnvironment under this category:

a) Single line control

 b) Watch window

c) Procedure control

Single line control: Aftewr compliation if there are any errors in our program then pressing the F7

key will check our program in a single line control. Where there is any error or bug in

any line then that particular line is skipped and the control is transferred to the next adjacent line.

Watch window: After pressing F7 key, if we press Ctrl+F7 then a watch window will be displayed

on the screen. The user has to type a variable in the add watch window and the value of that variable

will be displayed.

Procedure control: This debugging technique is used if our program is very large and it is divided

into several sub-procedures. Simply pressing F8 key will result our program to be compiled on

 procedure basis.

Break point control debugging:

The break point methopd as the name employs allows the user to set break points in the program in

order to check the cointents of registers, memories and other programming entitites like variables

etc. In fact the break point allows the user to halt the execution of the program at that break point.

Then the user can examine thhe iunbtermediate results or contents of various registers, memories,

35

Page 36: Final File Sp

8/8/2019 Final File Sp

http://slidepdf.com/reader/full/final-file-sp 36/44

variables, addresses and I/O ports. The break point can be inserted at any particualr position in opur 

 program by the user himself.

STUDY OF EDITORS AND TYPES OF EDITORS

Editor is a system program that interfaces a program with the entity that generates a data (originator).It also interfaces the results of the program with the entity that consumes them (consumer).There are

a few steps in program development:

1) program design, coding and documentation

2) preparation of programs in machine readable form

3) program translation, linking and coding

4) program testing an d debugging

5) performance enhancement of the program

6) reforming the data or the result of the program

Design and Coding:

There are two methods for design and coding:

Program Generator

  It generates a program which performs a set of functions described in its specifications. The user 

has to only specify the functions to be performed and not how to perform them.

Program Environment

36

Page 37: Final File Sp

8/8/2019 Final File Sp

http://slidepdf.com/reader/full/final-file-sp 37/44

It supports programming by including awareness of the programming language syntax and

semantics in the language editor.

 

Program entry and editing

The soft tools used are text editors. Editor function in two modes

1. Command Mode

It accepts the user commands specifying the editing function to be performed.

2. Data Mode

The user keys in the text to be added to the files.

Testing and Debugging

Various task to be performed here are selection of test data for the programs, analysis of test results

to detect errors if any and debugging. Software tools used to implement these steps are:

1. Test data generators

They help the user to select test data for the program. Test data is a set of input values that

satisfy the conditions required for correct flow of data.

2. Automated test drivers

Here the program correctness is verified by subjecting is to a standard set of tests after every

modification. This is called regression testing.

3. Debug Monitors

It is a software which provides debugging support for a program. It executes the program

 been debugged under its control. It also enables the monitor to perform dynamically specified

debugging actions. They perform the following facilities for dynamic debugging:

a) Setting break points in a program.

 b) Initiate a debug conversation when the control reaches the break point.

c) Display the value of variables.

d) Assign new values to variables.

37

Page 38: Final File Sp

8/8/2019 Final File Sp

http://slidepdf.com/reader/full/final-file-sp 38/44

e) Testing user defined assertions involving program variables.

Enhancement of program performance

Program efficiency depends on efficiency of the algorithm and efficiency of the coding.

Editor comes in different forms:

1) Line editor 

2) Stream editor 

3) Screen editor 

4) Word processors

5) Structure editor 

6) Graphical editors

 

LINE EDITOR 

The scope of edit operations on line editor is limited to line of text.

The line is designated:

Positonaly

By specifying a serial number in text

Contextually

By specifying a unique character string in it.

The primary advantage of line editors is there simplicity.

STREAM EDITOR 

A stream editor views the entire text as a stream of character this permits edit operations to cross line

 boundaries.stream editors typically supports character oriented , line oriented and context oriented

modes. The current pointer can be manipulated using all these modes.

38

Page 39: Final File Sp

8/8/2019 Final File Sp

http://slidepdf.com/reader/full/final-file-sp 39/44

SCREEN EDITORS

Line or stream editors does not display the text in manner it would appear if printed.screen editor 

uses the “What-you-see-is-what-you-get principle.the editor displays a screen full of text at a time

the user can move the cursor over the screen , position it at a point where we want to perform. Some

editing proceed with the editing directly. Thus it is possible to see the effect of an edit operation on

screen.

WORD PROCESSOR 

Word processors are document editors with additional features to produce well formatted hard copy

output. Essential features of word processor are command for moving, merging of texts and

searching and replacing of words. Many word processors supports spell check options with the

adventure of personal computers. Word processors have seen wide spread use among authors,office

 personal and computer professional.

STRUCTURE EDITIOR 

A structure editor incorporate an awareness of the structure of a document .This is useful in

 browsing through a document

CASE STUDY OF MS-WORD , DOS EDITOR , VI –EDITOR 

DOS EDITOR 

Introduction

1. How to start the Dos editor.

2. How to create a file in the editor.

3. What is a batch file.

4. How to create a batch file.

5. How to execute a batch file.

39

Page 40: Final File Sp

8/8/2019 Final File Sp

http://slidepdf.com/reader/full/final-file-sp 40/44

What is DOS Editor?

The DOS Editor is used to display , create , print , and modify files.

The DOS Editor looks a little like a word processing document.

EDIT

How do you access the DOS Editor?

Type EDIT at the command prompt and press the ENTER key.

To name a file before starting type EDIT and the filename. Press the ENTER key.

BATCH FILE

Why do you want to use DOS Editor?

You use the DOS Editor to create Batch Files.

What are Batch Files?

A batch file contains a series of DOS commands.

Batch files have a .bat extension.

What do you do with a batch file?

Batch file are like icons on a toolbar . They simplify your life.

Imagine if you had a room full of computers. You wanted ti perform the same function on each of the

computers. You have a few options.

Sit at each computer and perform the function.

 

Build a batch file. Execute the batch file. Have time to relax before your next project.

How do you run or execute a batch file?

Type the batch file name.

There is no need to type the .bat extension.

How do you stop or pause a batch file?

40

Page 41: Final File Sp

8/8/2019 Final File Sp

http://slidepdf.com/reader/full/final-file-sp 41/44

Interrupt batch file: CTRL+S

Cancel batch file: CTRL+BREAK 

What are some special batch file commands and what is the purpose of each?

ECHO OFF

This turns off all DOS commands after the ECHO OFF command.

If a DOS command has related questions you will see the questions . The only thing you

do not see are the DOS commands.

@ ECHO OFF

This turn off all DOS commands including the ECHO OFF command .

 Now , do you understand the difference between ECHO OFF and @ECHO OFF?

ECHO OFF - You see ECHO OFF

@ECHO OFF - You don’t see ECHO OFF

ECHO.

  This create a blank line.

ECHO

This display a message on a monitor.

PAUSE

This pause your computer until you press any key.

VI EDITOR 

INTRODUCTION

The VI editor is a screen based editor used by many Unix users . The VI editor has a powerful

feature to aid programmer, but many beginning users avoid using VI because the different features

overwhelm them. This tutorial is written to help beginning users get accustomed to using the VI

41

Page 42: Final File Sp

8/8/2019 Final File Sp

http://slidepdf.com/reader/full/final-file-sp 42/44

editor , but also contains section relevant to regular users of VI as well. Examples are provided , and

the best way to learn is to try these examples as well………. There’s no better way than to

experience things yourself.

Starting the VI Editor

The VI editor lets a user create new files or edit existing files . The command to start

the VI editor is vi, followed by the file name. For example to edit a file called

temporary, you would type vi temporary and then return . You can start VI without a

filename , but when you want to save your work , you will have to save your work ,

you will have to tell VI which filename to save it into later.

The Two Modes of VI

The first thing most users learn about the VI editor is that it has two modes : command  

and insert . The command mode allows the entry of commands to manipulate text .

these commands are usually one or two characters long, and can be entered with few

keystrokes . The insert mode puts anything typed on the keyboard into the current

file. into insert mode . The most commonly used commands to get into insert mode

are a and i . These VI starts out in command mode. There are several commands

that put the VI editor two commands are described below . Once you are in insert  

mode , you get out of it by hitting the escape key . If your terminal does not have an

escape key , ^ [ should work(control-)]. You can hit escape two times in a row and VI

would definitely be in command mode . Hitting escape while you are already in

command mode doesn’t take the editor out of command mode . It may beep to tell

you that you are already in that mode.

42

Page 43: Final File Sp

8/8/2019 Final File Sp

http://slidepdf.com/reader/full/final-file-sp 43/44

STUDY OF LEXICAL & SYNTAX ANALYSIS

  SYNTAX ANALYSIS:

It is also known as passing and the program used for this purpose is known

as parser. A parser obtains a string of tokens from the lexical analyzer and verify whether the string

is valid instruct of the source language .for this purpose of parser either attempts to derive the string

of tokens W from the start symbol S or attempts to reduce W to start symbol S of the grammar.

TWO TYPES OF PARSING:

3.) TOP-DOWN PARSING

4.) BOTTOM-UP PARSING

LEFTMOST DERIVATION:

If while generating a language from a given grammar. We don’t scan

the next variable until the leftmost variable scanned as leftmost derivation.

RIGHTMOST DERIVATION:

While generating a language from a given grammar we don’t scan

the next variable until the rightmost variable is scanned is known as rightmost derivation.

TOP-DOWN PARSING:

In an attempt to generate a leftmost derivation of a given grammar. The

 basic idea is to parse our program starting from top and moving bottom. It means until or unless our 

first line is not error free or correct according to syntax .we can not move on to next line. E.g.

LL(K) grammar context free grammars called LL(K) from left to right scan producing a left most

derivation with K symbols look ahead if we can always make a correct decision by checking at

most the first K symbols of W. Let this is our context free grammar.

 

43

Page 44: Final File Sp

8/8/2019 Final File Sp

http://slidepdf.com/reader/full/final-file-sp 44/44

P is S A+B-C

 

A bB c

C d

 

BOTTOM –UP PARSING:

While parsing our program if we are moving starting from bottom and

going to top of our source program then it is known as bottom up parsing. The basic idea is unless or 

until the last line of our source program is not error free or correct according to the syntax. We can

not move to the next line and it is equivalent to finding the right most derivation of any grammar.e.g.

LR (K) grammar: while finding a rightmost derivation of any grammar by looking ahead K symbols

we determine which production to use then is known as LR (K) grammar. It equivalent to finding

the right most derivation of the grammar. Let this is our given grammar.