minor tweaks
This commit is contained in:
parent
f177471663
commit
1bea05115a
@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.15)
|
||||
|
||||
project(r16)
|
||||
|
||||
set(CMAKE_C_STANDARD 11)
|
||||
set(CMAKE_C_STANDARD 11 LANGUAGES c)
|
||||
|
||||
add_library(carg-parse
|
||||
./lib/carg-parse/carg-parse.c
|
||||
|
@ -88,8 +88,9 @@ AsmInstructionArray *InterpretAssembly(char *data)
|
||||
{
|
||||
char *d = data;
|
||||
AsmInstructionArray *asmIA = malloc(sizeof(AsmInstructionArray));
|
||||
uint32_t cSize = 0, mSize = ARRAY_SNAP_SIZE;
|
||||
asmIA->length = 0;
|
||||
asmIA->instruction = malloc(sizeof(AsmInstruction) * ARRAY_SNAP_SIZE);
|
||||
uint32_t cSize = 0, mSize = ARRAY_SNAP_SIZE;
|
||||
|
||||
int gfususc = 0;
|
||||
|
||||
@ -118,7 +119,9 @@ AsmInstructionArray *InterpretAssembly(char *data)
|
||||
|
||||
if (*(FindNextSpaceChar(d, true) - 1) == ':')
|
||||
{
|
||||
memcpy(¤t.label, d, (FindNextSpaceChar(d, true) - 1) - d);
|
||||
size_t l = (FindNextSpaceChar(d, true) - 1) - d;
|
||||
memcpy(¤t.label, d, l);
|
||||
current.label[l] = '\0';
|
||||
|
||||
d = FindNextNonSpaceChar(d, true);
|
||||
}
|
||||
@ -127,7 +130,8 @@ AsmInstructionArray *InterpretAssembly(char *data)
|
||||
current.label[0] = '\0';
|
||||
}
|
||||
|
||||
memcpy(¤t.instruction, d, 3);
|
||||
memcpy(¤t.instruction, d, sizeof(char) * 3);
|
||||
current.instruction[3] = '\0';
|
||||
|
||||
d = FindNextNonSpaceChar(d, false);
|
||||
|
||||
@ -139,20 +143,26 @@ AsmInstructionArray *InterpretAssembly(char *data)
|
||||
goto loopEnd;
|
||||
}
|
||||
|
||||
char *comma = FindNextChar(d, ',', true),
|
||||
*nline = FindNextChar(d, '\n', true);
|
||||
char *comma = FindNextChar(d + 3, ',', true),
|
||||
*nline = FindNextChar(d + 3, '\n', true);
|
||||
|
||||
bool a2 = comma < nline;
|
||||
char *eoA1 = a2 ? comma : nline;
|
||||
memcpy(¤t.arg1, d, eoA1 - d);
|
||||
size_t s = eoA1 - (d + 3);
|
||||
memcpy(¤t.arg1, d + 3, s);
|
||||
current.arg1[s] = '\0';
|
||||
|
||||
if (!a2)
|
||||
goto loopEnd;
|
||||
|
||||
d = FindNextNonSpaceChar(eoA1 + 1, true);
|
||||
memcpy(¤t.arg2, d, nline - d);
|
||||
s = nline - d;
|
||||
memcpy(¤t.arg2, d, s);
|
||||
current.arg2[s] = '\0';
|
||||
d = nline + 1;
|
||||
|
||||
printf("l: %s, i: %s, a1: %s, a2: %s\n", current.label, current.instruction, current.arg1, current.arg2);
|
||||
|
||||
loopEnd:
|
||||
cSize++;
|
||||
}
|
||||
@ -207,6 +217,10 @@ uint16_t *BinaryInstructionToBin(BinaryInstruction instruction)
|
||||
return bin;
|
||||
}
|
||||
|
||||
static void just() {
|
||||
|
||||
}
|
||||
|
||||
int WhereIn2DCharArray(int x, int y, char array[25][4], char* val)
|
||||
{
|
||||
for (int i = 0; i < x; i++)
|
||||
@ -236,13 +250,13 @@ void ParseArgument(char *argData, AsmLabelArray *labels, uint16_t labelOffset,
|
||||
{
|
||||
*argInfoOut = value;
|
||||
|
||||
|
||||
// todo: something here probably??
|
||||
}
|
||||
else
|
||||
{
|
||||
*argInfoOut = valueInRegister;
|
||||
|
||||
|
||||
// todo: something here probably??
|
||||
}
|
||||
}
|
||||
else if (!pointer && value) // value
|
||||
@ -284,6 +298,7 @@ void ParseArgument(char *argData, AsmLabelArray *labels, uint16_t labelOffset,
|
||||
case '7':
|
||||
case '8':
|
||||
case '9':
|
||||
just();
|
||||
total += '0' - *a;
|
||||
break;
|
||||
case 'a':
|
||||
@ -330,6 +345,8 @@ uint16_t *CompileAsembly(AsmInstructionArray *assembly, AsmLabelArray *labels)
|
||||
|
||||
for (int i = 0; i < assembly->length; i++)
|
||||
{
|
||||
printf("cabii: %d\n", i);
|
||||
|
||||
BinaryInstruction binaryIns;
|
||||
|
||||
int instruction = WhereIn2DCharArray(LEN(CpuInstructionsHumanReadable),
|
||||
|
@ -8,9 +8,9 @@
|
||||
const char demo[] =
|
||||
"mov R0, 0x1\n\
|
||||
mov ACU, 0x0\n\
|
||||
loop: add ACU, R0\n\
|
||||
add ACU, R0\n\
|
||||
out ACU, 0x0\n\
|
||||
jmp loop, 0x0\n";
|
||||
jmp 0x8, 0x0\n";
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user