Commit 8e00a9e5 authored by sea19's avatar sea19
Browse files

Started on input values for assembler

parent 097de796
CC = gcc
CFLAGS = -Wall -g -std=c99 -Werror -pedantic
FILES = emulate.c fetch.c decode.c execute.c instrType.c
EMULATEFILES = emulate.c fetch.c decode.c execute.c instrType.c
ASSEMBLEFILES = assemble.c readFile.c
#.PHONY: all clean
all: emulate.o fetch.o execute.o decode.o instrType.o
$(CC) $(CFLAGS) $(FILES) -o emulate
all: emulate assemble
emulate: emulate.o fetch.o decode.o execute.o instrType.o
$(CC) $(CFLAGS) $(EMULATEFILES) -o emulate
assemble: assemble.o readFile.o
$(CC) $(CFLAGS) $(ASSEMBLEFILES) -o assemble
clean:
rm -f $(wildcard *.o)
......
#include <stdlib.h>
#include <stdio.h>
#include <assert.h>
#include "readFile.h"
#define MAX_SIZE_OF_STRING 50
int main(int argc, char **argv) {
assert(argc == 3);
int length = getLengthOfFile(argv[1]);
char **instruction = calloc(length, sizeof(char *));
if (!instruction) {
perror("Node allocation failed!");
exit(EXIT_FAILURE);
}
for (int i = 0; i < length; i++) {
instruction[i] = calloc(MAX_SIZE_OF_STRING, sizeof(char));
if (!instruction[i]) {
perror("Node allocation failed!");
exit(EXIT_FAILURE);
}
}
readSourceFile(argv[1], instruction);
for (int i = 0; i < length; i++) {
printf("%s\n", instruction[i]);
}
free(instruction);
for (int i = 0; i < length; i++) {
free(instruction[i]);
}
return EXIT_SUCCESS;
}
#include <stdio.h>
int getLengthOfFile(char *fileName) {
FILE *ptr = fopen(fileName, "r");
int size = 0;
char c = getc(ptr);
while (c != EOF) {
if (c == '\n' || c == ' ') {
size++;
}
c = getc(ptr);
}
fclose(ptr);
return size;
}
void readSourceFile(char *fileName, char **instruction) {
int i = 0;
FILE *ptr = fopen(fileName, "r");
while (!feof(ptr)) {
fscanf(ptr, "%s", instruction[i]);
i++;
}
fclose(ptr); //Closes file "filename"
}
int getLengthOfFile(char *fileName);
void readSourceFile(char *fileName, char **instruction);
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment