diff --git a/asm/asm_const.h b/asm/asm_const.h index 60203ab..bfdee2a 100644 --- a/asm/asm_const.h +++ b/asm/asm_const.h @@ -33,6 +33,12 @@ typedef struct BinaryInstruction *instructions; } BinaryInstructionArray; +typedef struct +{ + uint16_t length; + uint16_t *values; +} BinaryDataValueArray; + typedef struct { char label[64]; diff --git a/asm/assembler.c b/asm/assembler.c index abbc68b..2a7e4f0 100644 --- a/asm/assembler.c +++ b/asm/assembler.c @@ -88,15 +88,15 @@ AsmInstructionArray *InterpretAssembly(char *data) { char *d = data; AsmInstructionArray *asmIA = malloc(sizeof(AsmInstructionArray)); - uint32_t cSize = 0, mSize = 32; - asmIA->instruction = malloc(sizeof(AsmInstruction) * 32); + uint32_t cSize = 0, mSize = ARRAY_SNAP_SIZE; + asmIA->instruction = malloc(sizeof(AsmInstruction) * ARRAY_SNAP_SIZE); while (true) { loopStart: if (cSize == mSize) { - mSize += 32; + mSize += ARRAY_SNAP_SIZE; asmIA->instruction = realloc(asmIA->instruction, mSize); } @@ -154,11 +154,42 @@ loopEnd: } final: - // TODO i think its mostly done, just need to make sure i free any rand temp - // shit used here - asmIA->instruction = realloc(asmIA->instruction, cSize); asmIA->length = cSize; return asmIA; -} \ No newline at end of file +} + +AsmLabelArray *GenerateLabels(AsmInstructionArray *assembly) +{ + AsmLabelArray *labels = malloc(sizeof(AsmLabelArray)); + uint32_t cSize = 0, mSize = ARRAY_SNAP_SIZE; + labels->labels = malloc(sizeof(AsmLabel) * ARRAY_SNAP_SIZE); + + for (int i = 0; i < assembly->length; i++) + { + if (cSize == mSize) + { + mSize += ARRAY_SNAP_SIZE; + labels->labels = reallc(labels->labels, mSize); + } + + if (assembly->instruction[0].label[0] == '\0') + continue; + + labels->labels[cSize].location = i; + strcpy(&labels->labels[cSize].label, &assembly->instruction[0].label); + + cSize++; + } + + labels->labels = realloc(labels->labels, cSize); + labels->length = cSize; + + return labels; +} + +uint16_t *CompileAsembly(AsmInstructionArray *assembly, AsmLabelArray *labels) +{ + +} diff --git a/asm/assembler.h b/asm/assembler.h index 76dee9a..9abe729 100644 --- a/asm/assembler.h +++ b/asm/assembler.h @@ -1,6 +1,17 @@ #ifndef ASM_ASSEMBLER_H #define ASM_ASSEMBLER_H +#include +#include "asm_const.h" +#define ARRAY_SNAP_SIZE 32 + +char *FindNextChar(char *data, char toFind, bool careAboutNull); +char *FindNextNonSpaceChar(char *data, bool careAboutNull); +char *FindNextSpaceChar(char *data, bool careAboutNull); + +AsmInstructionArray *InterpretAssembly(char *data); +AsmLabelArray *GenerateLabels(AsmInstructionArray *assembly); +BinaryInstructionArray *CompileAsembly(AsmInstructionArray *assembly); #endif \ No newline at end of file