ARMv8/src/assemble.c
2024-06-12 00:49:25 +01:00

36 lines
1.0 KiB
C
Executable File

#include <stdlib.h>
#include <stdio.h>
#include "a64instruction/a64instruction.h"
#include "parser.h"
#include "fileio.h"
#include "parser.h"
#include "twopassassembly.c"
int main(int argc, char **argv) {
// Check the arguments
if (argc < 3) {
fprintf(stderr, "Error: A source file and an object output file are required. Syntax: ./assemble <file_in> <file_out>");
return EXIT_FAILURE;
}
// Load the source file into memory
int lineCount = countLines(argv[1]);
char **source = readAssemblyFile(argv[1], lineCount);
// Parse the source file
a64inst_instruction *instructions = parse(source, lineCount);
// First Pass: Create the symbol table
st *table = firstPass(instructions, lineCount);
// Second Pass: Assemble the instructions
word *binary = secondPass(instructions, lineCount, table); // 1000 is just a temp fix.
// Write the binary to the output file
writeBinaryFile(binary, argv[2], lineCount); // 1000 is just a temp fix.
/* TODO: FREE MEMORY!! */
return EXIT_SUCCESS;
}