Your Ad Here

Tuesday, August 25, 2009

Two Pass Assembler

#include< stdio.h>
#include< conio.h>
#include< string.h>
#define lines_in_program 9
void print(char *p,int loc,int len,char ra)
{printf("%s\t%d\t%d\t%c\n",p,loc,len,ra);}
void main()
{
char *p[9][4] = {{"PRG1","START","",""},{"","USING","*","15"},
{"","L","1","FIVE"}, {"","A","1","FOUR"},
{"","ST","1","TEMP"}, {"FOUR","DC","F'4'",""},
{"FIVE","DC","F'5'",""}, {"TEMP","DS","1F",""},
{"","END","",""}};
int i,j=0,location_counter=0;
clrscr();
for (i=0;i< 9;i++)
{ for(j=0;j< 4;j++)
printf("%s\t",p[i][j]);
printf("\n");
}
printf("\n\n\n\n Symbol ");
printf("Table:\nSYMBOL\tVALUE\tLENGTH\tRelocatable/Absolute\n");
printf("---------------------------------------------\n");
for(i=0;i< 9;i++)
{ if(strcmp(p[i][1],"START")==0)
print(p[i][0],location_counter,1,'R');
else if(strcmp(p[i][0],"")!=0)
{
print(p[i][0],location_counter,4,'R');
location_counter=4+location_counter;
}
else if(strcmp(p[i][1],"USING")==0){}
else{location_counter=4+location_counter;}
}
getch();
}


/*OUTPUT:
PRG1 START
USING * 15
L 1 FIVE
A 1 FOUR
ST 1 TEMP
FOUR DC F'4'
FIVE DC F'5'
TEMP DS 1F
END

Symbol Table:
SYMBOL VALUE LENGTH Relocatable/Absolute
---------------------------------------------
PRG1 0 1 R
FOUR 12 4 R
FIVE 16 4 R
TEMP 20 4 R */

Two Pass Assembler

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


void main()
{
char *code[9][4]={
{"PRG1","START","",""},
{"","USING","*","15"},
{"","L","",""},
{"","A","",""},
{"","ST","",""},
{"FOUR","DC","F",""},
{"FIVE","DC","F",""},
{"TEMP","DS","1F",""},
{"","END","",""}
};
char av[2],avail[15]={'N','N','N','N','N','N','N','N','N','N','N','N','N','N','N'};
int i,j,k,count[3],lc[9]={0,0,0,0,0,0,0,0,0},loc=0;
clrscr();
printf("----------------------------------------------------\n");
printf("LABEL\t\tOPCODE\n");
printf("----------------------------------------------------\n\n");
for(i=0;i< =8;i++)
{
for(j=0;j< =3;j++)
{
printf("%s\t\t",code[i][j]);
}
j=0;
printf("\n");
}
getch();
printf("-----------------------------------------------------");
printf("\nVALUES FOR LC : \n\n");
for(j=0;j< =8;j++)
{
if((strcmp(code[j][1],"START")!=0)&&(strcmp(code[j][1],"USING")!=0)&&(strcmp(code[j][1],"L")!=0))
lc[j]=lc[j-1]+4;
printf("%d\t",lc[j]);
}
printf("\n\nSYMBOL TABLE:\n----------------------------------------------------\n");
printf("SYMBOL\t\tVALUE\t\tLENGTH\t\tR/A");
printf("\n----------------------------------------------------\n");

for(i=0;i< 9;i++)
{
if(strcmp(code[i][1],"START")==0)
{
printf("%s\t\t%d\t\t%d\t\t%c\n",code[i][0],loc,4,'R');
}
else if(strcmp(code[i][0],"")!=0)
{
printf("%s\t\t%d\t\t%d\t\t%c\n",code[i][0],loc,4,'R');
loc=4+loc;
}
else if(strcmp(code[i][1],"USING")==0){}
else
{loc=4+loc;}
}
printf("----------------------------------------------------");

printf("\n\nBASE TABLE:\n-------------------------------------------------------\n");
printf("REG NO\t\tAVAILIBILITY\tCONTENTS OF BASE TABLE");
printf("\n-------------------------------------------------------\n");
for(j=0;j< =8;j++)
{
if(strcmp(code[j][1],"USING")!=0)
{}
else
{
strcpy(av,code[j][3]);
}
}
count[0]=(int)av[0]-48;
count[1]=(int)av[1]-48;
count[2]=count[0]*10+count[1];
avail[count[2]-1]='Y';

for(k=0;k< 16;k++)
{
printf(" %d\t\t %c\n",k,avail[k-1]);
}

printf("-------------------------------------------------------\n");
printf("Continue..??");
getchar();
printf("PASS2 TABLE:\n\n");
printf("LABEL\t\tOP1\t\tLC\t\t");
printf("\n----------------------------------------------------\n");
loc=0;
for(i=0;i< =8;i++)
{
for(j=0;j< =3;j++)
{
printf("%s\t\t",code[i][j]);
}
j=0;
printf("\n");
}
printf("-----------------------------------------------------");

getch();

}
/*
----------------------------------------------------
LABEL OPCODE
----------------------------------------------------

PRG1 START
USING * 15
L
A
ST
FOUR DC F
FIVE DC F
TEMP DS 1F
END



-----------------------------------------------------
VALUES FOR LC :

0 0 0 4 8 12 16 20 24

SYMBOL TABLE:
----------------------------------------------------
SYMBOL VALUE LENGTH R/A
----------------------------------------------------

PRG1 0 4 R
FOUR 12 4 R
FIVE 16 4 R
TEMP 20 4 R


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

BASE TABLE:
-------------------------------------------------------
REG NO AVAILIBILITY CONTENTS OF BASE TABLE
-------------------------------------------------------
0 -----------------------------------
1 N
2 N
3 N
4 N
5 N
6 N
7 N
8 N
9 N
10 N
11 N
12 N
13 N
14 N
15 Y

-------------------------------------------------------
Continue..??
PASS2 TABLE:

LABEL OP1 LC
----------------------------------------------------
PRG1 START
USING * 15
L
A
ST
FOUR DC F
FIVE DC F
TEMP DS 1F
END
-----------------------------------------------------


*/

Lexical Analizer

/* TO IMPLEMENT LEXICAL ANALIZER IN C */

#include< conio.h>
#include< string.h>

void main()
{
int i,j,lc;
char *a[9][4]={"PRG","START" ," " ," ",
" " ,"USING" ,"*" ,"15",
" ","L","1","FIVE",
" ","A","1","FOUR",
" ","ST","1","TEMP",
"FOUR ","DC","F","4",
"FIVE","DC","F","5",
"TEMP","DS","1","F",
" " ,"END"," "," ", };
clrscr();
printf("\n \t\t LEXICAL ANALIZER \n");

for(i=0;i< 9;i++)
{ for(j=0;j< 4;j++)
{ if(isalpha(*a[i][j]))
printf("\n STRING : %s",a[i][j]);
if(isdigit(*a[i][j]))
printf("\n DIGIT : %s",a[i][j]);
}
printf("\n");
}

getch();
}
/* OUTPUT:-

LEXICAL ANALIZER

STRING : PRG
STRING : START

STRING : USING
DIGIT : 15

STRING : L
DIGIT : 1
STRING : FIVE

STRING : A
DIGIT : 1
STRING : FOUR

STRING : ST
DIGIT : 1
STRING : TEMP

STRING : FOUR
STRING : DC
STRING : F
DIGIT : 4

STRING : FIVE
STRING : DC
STRING : F
DIGIT : 5

STRING : TEMP
STRING : DS
DIGIT : 1
STRING : F

STRING : END

*/

Thursday, June 11, 2009

Free Web Hosting

If you wish to have a professional shared hosting quality in a free hosting package, come and host with 000webhost.com and experience the best service you can get absolutely free.

Founded in December 2006, 000webhost.com has a trusted free hosting members base of over 60,000 members and still counting! Offering professional quality hosting, support, uptime and reliability, we have a great community of webmasters, you'd love to be a part of!
I have been using it for sometime now and had found it quiet satisfying..

Register now and get it all free:
*** 1500 MB of disk space
*** 100 GB of data transfer
*** PHP and MySQL support with no restrictions
*** cPanel control panel
*** Website Builder
*** Absolutely no advertising!

Join us now: http://www.000webhost.com/173150.html

Sunday, December 21, 2008

Diamond In C

/* C program to display a diamond using arrays */

#include< iostream.h>
#include< conio.h>
void main()
{
int i,j;
clrscr();
int no;
cout< < "Enter A Value";
cin>>no;
for(i=no;i>=1;i--)
{
cout< < endl;
for(int k=1;k< =i;k++)
cout< < " ";

for(j=i;j< =no;j++)
cout< < "*";

for(j=i;j< no;j++)
cout< < "*";
}
//SECOND PART

for(i=no;i>=1;i--)
{
cout< < endl;
cout< < " ";
for(int k=no;k>=i;k--)
cout<<" ";

for(j=i-1;j>=1;j--)
cout< < "*";

for(j=i-1;j>1;j--)
cout<<"*";

}
getch();
}

Call By Reference in C

/* Program for inerchanging two numbers demonstrating Call By Reference in C */

#include<>
#include<>

void swap(int *,int *);

void main()
{
int x,y;
x=15;y=20;
clrscr();
printf("x=%d,y=%d\n",x,y);
swap(&x,&y);
//printf("\n%x %x",&x,&y);
printf("\n after interchanging x=%d,y=%d\n",x,y);
getch();
}

void swap(int *u,int *v)
{
int temp;
temp=*u;
*u=*v;
*v=temp;

return;
}

Call by Values in C

/* Program on interchanging two numbers demonstrating Call By Values in C*/
#include< stdio.h>
#include< conio.h>
void main()
{
int x,y;
x=15;y=20;
clrscr();
printf("x=%d,y=%d\n",x,y);
swap(x,y);
printf("\n after interchanging x=%d,y=%d\n",x,y);
getch();
}
swap(int u,int v)
{
int temp;
temp=u;
u=v;
v=temp;
return;
}

Pointers example

/* Example of pointers in C. Thsi program uses a function to modify a string using pointers */

#include< stdio.h>
#include< conio.h>
void main()
{
void getstr(char *ptr_str,int *ptr_int);
int var=5;
char *pstr="lionel";
clrscr();
getstr(pstr,&var);
printf("The value of var after modification using pointer in a function is %d,var");
}
void getstr (char *ptr_str,int *ptr_int)
{
printf("%s\n",ptr_str);
*ptr_int=6;
getch();
}

Two Dimentional array in C

/* C program to input and display a 2-d array*/

#include< stdio.h>
#include< conio.h>
void main()
{
int num[3][3],i,j;
clrscr();
for(i=0;i< 3;i++)
{
for(j=0;j< 3;j++)
{
scanf("%d",&num[i][j]);
}
}
for(i=0;i< 3;i++)
{
for(j=0;j< 3;j++)
{
printf("\n%d",num[i][j]);
}
printf("\n");
}
getch();
}

Thursday, December 11, 2008

Carlsberg launches Web-TV channel about football and fan life.

Recently Carlsberg Brewery launched a football web-TV-channel partofthegame.tv.

They launched 5 channels showing all aspects about football from the classic football matches to life as a fan.

Be sure not to miss the video clips about football funnies and rituals from the Football Magic channel or the bizarre story about fans in the stand and how fan culture sometimes go beyond reason.
As an extra feature you can upload your own favourite football and fan moments.

Its an amazing site with loads of features present in it. So log on to partofthegame.tv and experience the diference.

Your Ad Here