Professional Documents
Culture Documents
#Include #Include #Include Void
#Include #Include #Include Void
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
void main()
{
printf("Yadul Manoj\t69\n\n");
// Stores starting address of program
int start_addr;
// Location counter
int locctr;
// Stores the length of the instruction
int length;
// Stores the label received from input file
char label[20];
// Stores the opcode received from input file
char opcode[20];
// Stores operand received from input file
char operand[20];
// File pointers to input program, optab, symtab, intermediate file, and length file
FILE *input_ptr, *optab_ptr, *symtab_ptr, *intermed_ptr, *length_ptr;
if (operand[0] == 'C')
length = strlen(operand) - 3;
}
// If opcode = WORD, set length of instruction = 3
else if (strcmp(opcode, "WORD") == 0)
length = 3;
// If opcode = RESB, set length of instruction = operand
else if (strcmp(opcode, "RESB") == 0)
length = (int)strtol(operand, NULL, 16);
// If opcode = RESW, set length of instruction = 3 * operand
else if (strcmp(opcode, "RESW") == 0)
length = 3 * (int)strtol(operand, NULL, 16);
// Search optab for opcode
else
{
// Check if current line is a 4 byte instruction (opcode starts with '+')
if (opcode[0] == '+')
length = 4;
else
length = 3;
if (flag == 0)
{
printf("Invalid opcode.\n");
break;
}
}
fclose(input_ptr);
fclose(symtab_ptr);
fclose(intermed_ptr);
fclose(length_ptr);
}
Yadul Manoj 69
Length of program: 1a
input.txt
optab.txt:
LDA 00
STA 0C
ADD 18
SUB 1C
intermediate.txt:
symtab.txt
START 1000
ALPHA 100d
ONE 1012
TWO 1014
BETA 1017
length.txt
1a