diff --git a/assm b/assm deleted file mode 100755 index 3f39161..0000000 Binary files a/assm and /dev/null differ diff --git a/src/main.c b/src/main.c index 02176cc..f68bbc2 100644 --- a/src/main.c +++ b/src/main.c @@ -1,7 +1,15 @@ #include #include +#include + +typedef struct opcode { + char op[255]; + char param1[255]; + char param2[255]; +} Opcode; void print_file(char*); +Opcode* get_opcode(char*); int main(int argc, char* args[]) { const char *input_files[argc - 1]; @@ -33,7 +41,21 @@ void print_file(char* file_path) { } while((bytes_read = getline(&line, &len, file)) != -1) { - printf("%s", line); + //printf("%s", line); + + unsigned short int count = 0; + char* c; + char* opcode; + char* param1; + char* param2; + + //for(c = line; *c != '\0'; c++) { + Opcode* op = get_opcode(line); + //} + //printf("\n"); + if (strcmp(op->op, "NA") == 0) continue; + + printf("%s %s, %s\n", op->op, op->param1, op->param2); } printf("\n"); @@ -41,4 +63,37 @@ void print_file(char* file_path) { fclose(file); if (line) free(line); +} + +Opcode* get_opcode(char* line) { + Opcode *op = malloc(sizeof(Opcode)); + strcpy(op->op, "NA"); + + if (strlen(line) == 0 ) return op; + if (line[0] == ';') return op; + + int i = 0; + int count = 0; + + for (char* c = line; *c != '\0'; c++) { + if (*c == ';') break; + if (*c == ' ') { + i = 0; + count++; + continue; + } + + if (*c == ',') { + i = 0; + continue; + } + + if (count == 0) op->op[i] = *c; + else if (count == 1) op->param1[i] = *c; + else if (count == 2) op->param2[i] = *c; + + i++; + } + + return op; } \ No newline at end of file