Merge branch 'assembler-s' into 'assembler-e'

Assembler s

See merge request lab2324_summer/armv8_43!14
This commit is contained in:
sb3923 2024-06-12 16:49:36 +00:00
commit 5221189304

View File

@ -35,11 +35,13 @@ int countLines(char *filename) {
int count = 0; int count = 0;
char c; char c;
char prevC = '\n';
while ((c = fgetc(file)) != EOF) { while ((c = fgetc(file)) != EOF) {
if (c == '\n') { if (c == '\n' && prevC != '\n') {
count++; count++;
} }
prevC = c;
} }
return count; return count;
@ -71,6 +73,11 @@ char **readAssemblyFile(char filename[], int lineCount) {
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
if (*buffer == '\n') {
// Skip empty lines.
continue;
}
lines[currentLine] = malloc(strlen(buffer) + 1); lines[currentLine] = malloc(strlen(buffer) + 1);
if (lines[currentLine] == NULL) { if (lines[currentLine] == NULL) {
fprintf(stderr, "Error: Could not allocate memory to store the assembly line"); fprintf(stderr, "Error: Could not allocate memory to store the assembly line");