Wrote the first step for the binary output. Doesn't handle instruction pointer symbols yet since those emit addresses that still need to be computed.
This commit is contained in:
+45
@@ -8,6 +8,10 @@
|
||||
#include "../includes/futil.h"
|
||||
#include "../includes/scanner.h"
|
||||
|
||||
unsigned char Memory[2000];
|
||||
|
||||
void Setup(IRState*);
|
||||
|
||||
int main(int argc, char* args[]) {
|
||||
if (argc == 1) {
|
||||
printf("Usage: assm <file1.asm>\n");
|
||||
@@ -159,6 +163,8 @@ int main(int argc, char* args[]) {
|
||||
printf("\n");
|
||||
}
|
||||
}
|
||||
|
||||
Setup(image);
|
||||
//free(image);
|
||||
//Disassemble(image);
|
||||
//for(int i = 0; i < image->Opcodes->size; i++) {
|
||||
@@ -172,4 +178,43 @@ int main(int argc, char* args[]) {
|
||||
//fclose(program);
|
||||
|
||||
free(source_code);
|
||||
}
|
||||
|
||||
void Setup(IRState* state) {
|
||||
int start = 4;
|
||||
int end = start;
|
||||
|
||||
for(int i = 0; i < state->SymbolsTable->Size; i++) {
|
||||
Symbol* symbol = state->SymbolsTable->Symbols[i];
|
||||
|
||||
switch(symbol->Type) {
|
||||
case StringSymbol:
|
||||
memccpy(&Memory[end], symbol->Value.String->String, 0, strlen(symbol->Value.String->String));
|
||||
|
||||
end += strlen(symbol->Value.String->String);
|
||||
|
||||
if (symbol->Value.String->Terminated) {
|
||||
Memory[end] = symbol->Value.String->TerminatingByte;
|
||||
end++;
|
||||
}
|
||||
|
||||
//end++;
|
||||
break;
|
||||
case NumericSymbol:
|
||||
Memory[end] = symbol->Value.Number >> 8 & 0xFF;
|
||||
Memory[end + 1] = symbol->Value.Number & 0xFF;
|
||||
end += 2;
|
||||
break;
|
||||
case InstructionPointerSymbol:
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
for(int i = 0; i < end; i++) {
|
||||
if (i != 0 && i % 8 == 0) printf("\n");
|
||||
printf("%02x ", Memory[i]);
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
Reference in New Issue
Block a user