ST. JOSEPH UNIVERSITY IN TANZANIA ST. JOSEPH UNIVERSITY IN TANZANIA St. Joseph University College of

download ST. JOSEPH UNIVERSITY IN TANZANIA ST. JOSEPH UNIVERSITY IN TANZANIA St. Joseph University College of

of 58

  • date post

    02-Oct-2020
  • Category

    Documents

  • view

    2
  • download

    0

Embed Size (px)

Transcript of ST. JOSEPH UNIVERSITY IN TANZANIA ST. JOSEPH UNIVERSITY IN TANZANIA St. Joseph University College of

  • ST. JOSEPH UNIVERSITY IN TANZANIA

    St. Joseph University College of Engineering and Technology

    Department of Computer Science and Engineering

    System Software and Database Management Systems Laboratory 055CS38

    By Robert Innocent Karamagi

    List of Experiments

    1. Implementation of a Symbol Table 2. Implementation of Pass One of a Two Pass Assembler

    3. Implementation of Pass Two of a Two Pass Assembler

    4. Relocation Loader

    5. Absolute Loader

    6. Macroprocessor

    7. Implementation of Pass One of Direct Linking

    8. Data Definition Language Commands

    9. Data Manipulation Language Commands

    10. Data Control Language Commands

    11. Procedures and Functions in Database Management Systems

    12. Triggers in Database Management Systems

    13. Cursors in Database Management Systems

    14. Implementation of Payroll Processing System

    15. Implementation of Banking System

    16. Implementation of Library System

  • Experiment 1

    /* Implementation of a Symbol Table*/

    #include

    #include

    #include

    #include

    struct table

    {

    char var[10];int value;

    };

    struct table tb1[20];

    int i,j,n;

    void create();

    void modify();

    int search(char variable[],int n);

    void insert();

    void display();

    void main()

    {

    int ch,result=0;

    char v[10];

    clrscr();

    do

    {

    printf("\n\n1.CREATE\n2.INSERT\n3.MODIFY\n4.SEARCH\n5.DISPLAY\n6.EXIT:\t");

    scanf("%d",&ch);

    switch(ch)

    {

    case 1:create();break;

    case 2:insert();break;

    case 3:modify();break;

    case 4:

    printf("\nEnter the variable to be searched:");

    scanf("%s",&v);

    result=search(v,n);

    if(result==0)

    printf("\nThe variable is not present\n");

    else

    printf("\nThe location of the variable is %d \n The value of %s is

    %d.",result,tb1[result].var,tb1[result].value);

    break;

    case 5:display();break;

    case 6:exit(1);

    }

    }while(ch!=6);

  • getch();

    }

    void create()

    {

    printf("\nEnter the no. of entries:");

    scanf("%d",&n);

    printf("\nEnter the variable and the values:-\n");

    for(i=1;i='0'&&tb1[i].var[0]='0'&&tb1[i].var[0]

  • if(strcmp(tb1[j].var,tb1[i].var)==0)

    {

    printf("\nThe variable already present. Enter another:");

    scanf("%s%d",&tb1[i].var,&tb1[i].value);

    goto check1;

    }

    }

    printf("\nThe table after insertion is:");

    display();

    }

    }

    void modify()

    {

    char variable[10];

    int result=0;

    printf("\nEnter the variable to be modified:");

    scanf("%s",&variable);

    result=search(variable,n);

    if(result==0)

    printf("%s not present\n",variable);

    else

    {

    printf("\nThe current value of the variable %s is %d.\nEnter the new variable and its

    value:",tb1[result].var,tb1[result].value);

    scanf("%s%d",tb1[result].var,&tb1[result].value);

    check:

    if(tb1[i].var[0]>='0'&&tb1[i].var[0]

  • }

    void display()

    {

    printf("\nVariable\tvalue\n");

    for(i=1;i

  • Output

  • Experiment 2

    /* Implementation of Pass One of a Two Pass Assembler*/

    #include

    #include

    #include

    #include

    void main()

    {

    char opcode[10],mnemonic[10],operand[10],label[10],code[10];

    int locctr,start,length;

    FILE *fp1,*fp2,*fp3,*fp4;

    clrscr();

    fp1=fopen("ex2ina.txt","r");

    fp2=fopen("ex2outa.txt","w");

    fp3=fopen("ex2outb.txt","w");

    fp4=fopen("ex2inb.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);

    fscanf(fp4,"%s%s",code,mnemonic);

    while(strcmp(code,"END")!=0)

    {

    if(strcmp(opcode,code)==0)

    {

    locctr+=10;

    break;

    }

    fscanf(fp4,"%s%s",code,mnemonic);

    }

    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\t\n",label,opcode,operand);

    fscanf(fp1,"%s%s%s",label,opcode,operand);

    }

    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();

    }

    Input files

    ex2ina.txt

    ** START 1111

    ** LDA FIVE

    ** STA ALPHA

    ** LDCH CHARZ

    ** STCH C1

    ALPHA RESW 1

    FIVE WORD 5

    CHARZ BYTE C'Z'

    C1 RESB 1

    ** END **

    ex2inb.txt

    START *

    LDA AA

    STA 0A

    LDCH DE

    STCH 5B

    END *

    Output

  • ex2outa.txt

    ex2outb.txt

  • Experiment 3

    /*Implementation of Pass Two of a Two Pass Assembler*/

    #include

    #include

    #include

    #include

    void main()

    {

    char

    opcode[10],operand[10],symbol[10],label[10],code[10],mnemonic[5],character,add[10],objectcode[10];

    int flag,flag1,locctr,location,loc;

    FILE *fp1,*fp2,*fp3,*fp4;

    clrscr();

    fp1=fopen("ex2outb.txt","r"); fp2=fopen("ex3out.txt","w");

    fp3=fopen("ex2inb.txt","r"); fp4=fopen("ex2outa.txt","r");

    fscanf(fp1,"%s%s%s",label,opcode,operand);

    if(strcmp(opcode,"START")==0)

    {

    fprintf(fp2,"%s\t%s\t%s\n",label,opcode,operand);

    fscanf(fp1,"%d%s%s%s",&locctr,label,opcode,operand);

    }

    while(strcmp(opcode,"END")!=0)

    {

    flag=0;

    fscanf(fp3,"%s%s",code,mnemonic);

    while(strcmp(code,"END")!=0)

    {

    if((strcmp(opcode,code)==0) && (strcmp(mnemonic,"*"))!=0)

    {

    flag=1;

    break;

    }

    fscanf(fp3,"%s%s",code,mnemonic);

    }

    if(flag==1)

    {

    flag1=0; rewind(fp4);

    while(!feof(fp4))

    {

    fscanf(fp4,"%s%d",symbol,&loc);

    if(strcmp(symbol,operand)==0)

    {

    flag1=1; break;

    }

    }

    if(flag1==1)

    {

    itoa(loc,add,10);

  • strcpy(objectcode,strcat(mnemonic,add));

    }

    }

    else if(strcmp(opcode,"BYTE")==0 || strcmp(opcode,"WORD")==0)

    {

    if((operand[0]=='C') || (operand[0]=='X'))

    {

    character=operand[2];

    itoa(character,add,16);

    strcpy(objectcode,add);

    }

    else

    {

    itoa(atoi(operand),add,10);

    strcpy(objectcode,add);

    }

    }

    else

    strcpy(objectcode,"\0");

    fprintf(fp2,"%s\t%s\t%s\t%d\t%s\n",label,opcode,operand,locctr,objectcode);

    fscanf(fp1,"%d%s%s%s",&locctr,label,opcode,operand);

    }

    fprintf(fp2,"%s\t%s\t%s\t%d\n",label,opcode,operand,locctr);

    fclose(fp1); fclose(fp2);

    fclose(fp3); fclose(fp4);

    getch();

    }

    Input files

    ex2inb.txt

    START *

    LDA AA

    STA 0A

    LDCH DE

    STCH 5B

    END *

    ex2outa.txt

    ALPHA 1151

    FIVE 1154

    CHARZ 1157

    C1 1158

  • ex2outb.txt

    ** START 1111

    1111 ** LDA FIVE

    1121 ** STA ALPHA

    1131 ** LDCH CHARZ

    1141 ** STCH C1

    1151 ALPHA RESW 1

    1154 FIVE WORD 5

    1157 CHARZ BYTE C'Z'

    1158 C1 RESB 1

    1159 ** END **

    Output

  • Experiment 4

    /* Relocation Loader*/

    #include

    #include

    #include

    #include

    void convert(char h[12]);

    char bitmask[12];

    char bit[12]={0};

    void main()

    {

    char add[6],length[10],input[10],binary[12],relocbit,ch,pn[5];

    int start,inp,len,i,address,opcode,addr,actualadd,tlen;

    FILE *fp1,*fp2;