Add Versioning and finish Parser

This commit is contained in:
XOR 2022-12-24 01:02:09 +01:00
parent 91ee058d9d
commit e712a347b8

58
main.c
View file

@ -3,10 +3,32 @@
#include <stdlib.h>
#define MAX_MEMORY 1000000
#define INSTRUCTION_OPERATION 0
#define INSTRUCTION_ADRESS 1
//#define INSTRUCTION_COMMENT 2
// 0 = Operation | 1 = Adress | 2 = Comment
int instruction_part=0;
#define ALPHA 0
#define BETA 1
#define STABLE 2
#define VER_MAJOR 0
#define VER_MINOR 1
#define VER_PATCH 0
#define TAG ALPHA
int saveinstructionpart(unsigned short int part, char content[])
{
strcat(content,"\0"); //REMOVE
if(part==INSTRUCTION_OPERATION)
{
printf("Operation: %s\n",content);
}
else
{
printf("Adress: %s\n",content);
}
return 0;
}
int main(int argc, char const *argv[])
{
@ -22,12 +44,42 @@ int main(int argc, char const *argv[])
int *instructions = malloc(MAX_MEMORY*sizeof(int8_t));
char current_char = fgetc(assembly_file);
char instruction_part_string[10];
int instruction_part=0; // 0 = Operation | 1 = Adress | 2 = Comment REMOVE COMMENT
while(current_char!=EOF)
{
printf("%c",current_char);
//printf("%c",current_char);
if(current_char=='\n')
{
saveinstructionpart(instruction_part,instruction_part_string);
instruction_part = 0;
strcpy(instruction_part_string,"");
}
else if(current_char==';')
{
saveinstructionpart(instruction_part,instruction_part_string);
instruction_part=0;
strcpy(instruction_part_string,"");
while(current_char!='\n' && current_char!=EOF)
{
current_char = fgetc(assembly_file);
}
}
else if(current_char==' ')
{
saveinstructionpart(instruction_part,instruction_part_string);
instruction_part++;
strcpy(instruction_part_string,"");
}
else
{
strncat(instruction_part_string,&current_char,1);
}
current_char = fgetc(assembly_file);
}
saveinstructionpart(instruction_part,instruction_part_string);
fclose(assembly_file);
return 0;
}