some changes

This commit is contained in:
Rose Apollo 2024-04-25 20:40:09 +01:00
parent ffc77bef9f
commit 415828d694
3 changed files with 31 additions and 3 deletions

View File

@ -203,15 +203,42 @@ uint16_t *BinaryInstructionToBin(BinaryInstruction instruction)
return bin;
}
int WhereIn2DCharArray(int x, int y, char array[x][y], char *val)
{
for (int i = 0; i < x; i++)
{
if (strcmp(array[i], val) == 0)
return i;
}
return -1;
}
uint16_t *CompileAsembly(AsmInstructionArray *assembly, AsmLabelArray *labels)
{
uint16_t *ret = malloc(sizeof(uint16_t) * UINT16_MAX);
uint16_t cSize = 0, mSize = ARRAY_SNAP_SIZE;
uint16_t cSize = 0;
for (int i = 0; i < assembly->length; i++)
{
BinaryInstruction binaryIns;
int instruction = WhereIn2DCharArray(LEN(CpuInstructionsHumanReadable),
LEN(CpuInstructionsHumanReadable[0]),
CpuInstructionsHumanReadable,
assembly->instruction[i].instruction);
if (instruction < 0)
{
fprintf(stderr, "INSTRUCTION NOT FOUND\n");
exit(-1);
}
binaryIns.instruction = instruction;
cSize++;
}
ret = realloc(ret, cSize);
return ret;
}

View File

@ -7,6 +7,8 @@
#define ARRAY_SNAP_SIZE 32
#define LEN(arr) ((int) (sizeof (arr) / sizeof (arr)[0]))
char *FindNextChar(char *data, char toFind, bool careAboutNull);
char *FindNextNonSpaceChar(char *data, bool careAboutNull);
char *FindNextSpaceChar(char *data, bool careAboutNull);

View File

@ -47,7 +47,6 @@ char CpuInstructionsHumanReadable[25][4] =
"OUT",
"DIN",
"DOT",
"MOV"
};
"MOV"};
#endif