0% found this document useful (0 votes)
2 views3 pages

ss prgm

The document contains two C programs: the first is an absolute loader that reads input from a file, processes it, and writes output to another file, while the second is a pass one assembler that processes assembly language instructions and generates a symbol table and output file. The input and output file formats are specified, detailing how data is read and written. Additionally, the assembler calculates the program size based on the instructions processed.

Uploaded by

akshaia971
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views3 pages

ss prgm

The document contains two C programs: the first is an absolute loader that reads input from a file, processes it, and writes output to another file, while the second is a pass one assembler that processes assembly language instructions and generates a symbol table and output file. The input and output file formats are specified, detailing how data is read and written. Additionally, the assembler calculates the program size based on the instructions processed.

Uploaded by

akshaia971
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 3

ABSOLUTE LOADER

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

void main() {
char input[10];
int start, length, address;
FILE *fp1, *fp2;

clrscr();

fp1 = fopen("input2.dat", "r");


fp2 = fopen("out2.dat", "w");

fscanf(fp1, "%s", input);

while (strcmp(input, "E") != 0) {


if (strcmp(input, "H") == 0) {
fscanf(fp1, "%d", &start);
fscanf(fp1, "%d", &length);
fscanf(fp1, "%s", input);
} else if (strcmp(input, "T") == 0) {
fscanf(fp1, "%d", &address);
fscanf(fp1, "%s", input);

fprintf(fp2, "%d\t%c%c\n", address, input[0], input[1]);


fprintf(fp2, "%d\t%c%c\n", (address + 1), input[2], input[3]);
fprintf(fp2, "%d\t%c%c\n", (address + 2), input[4], input[5]);

address += 3;
fscanf(fp1, "%s", input);
} else {
fprintf(fp2, "%d\t%c%c\n", address, input[0], input[1]);
fprintf(fp2, "%d\t%c%c\n", (address + 1), input[2], input[3]);
fprintf(fp2, "%d\t%c%c\n", (address + 2), input[4], input[5]);

address += 3;
fscanf(fp1, "%s", input);
}
}

fclose(fp1);
fclose(fp2);

printf("FINISHED");
getch();
}

INPUT FILE
INPUT2.DAT
H 1000 232
T 1000 142033 483039 102036
T 2000 298300 230000 282030 302015
E
OUTPUT FILE
OUT2.DAT
1000 14
1001 20
1002 33
1003 48
1004 30
1005 39
1006 10
1007 20
1008 36
2000 29
2001 83
2002 00
2003 23
2004 00
2005 00
2006 28
2007 20
2008 30
2009 30
2010 20
2011 15

PASS ONE
Input.txt
** START 2000
** LDA FIVE
** STA ALPHA
** LDCH CHARZ
** STCH C1
ALPHA RESW 2
FIVE WORD 5
CHARZ BYTE C'Z'
C1 RESB 1
** END **

Optab.txt
START *
LDA 03
STA 0f
LDCH 53
STCH 57
END *

Pass one prgm


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

void main() {
char label[10], operand[10], opcode[10];
char code[10], mnemonic[10];
int start, locctr;
FILE *input, *optab, *output, *symtab;

input = fopen ("input.txt", "r");


optab = fopen ("optab.txt", "r");
output = fopen ("output.txt", "w");
symtab = fopen ("symtab.txt", "w");
fscanf (input, "%s\t%s\t%s", label, opcode, operand);
if (strcmp (opcode , "START") == 0) {
locctr = atoi (operand);
start = locctr;
fprintf (output, "\t%s\t%s\t%s\n",label, opcode, operand);
fscanf (input, "%s\t%s\t%s",label, opcode, operand);
} else {
locctr = 0;
start = 0;
}

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


fprintf (output, "%d\t",locctr);

if (strcmp (label, "") != 0 && strcmp (label, "**") != 0) {


fprintf (symtab, "%s\t%d\n",label, locctr);
}

fscanf (optab, "%s\t%s",code, mnemonic);


while (strcmp (code, "END") != 0) {
if (strcmp (code, opcode) == 0) {
locctr += 3;
break;
}
fscanf (optab, "%s\t%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 (output, "\t%s\t%s\t%s\n",label, opcode, operand);


fscanf (input, "%s\t%s\t%s",label, opcode, operand);
}

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


printf("\nProgram Size : %d\n", locctr - start);

fclose (input);
fclose (optab);
fclose (output);
fclose (symtab);
}

You might also like