diff --git a/asm_rules.c b/asm_rules.c index 5248540..10b9a17 100644 --- a/asm_rules.c +++ b/asm_rules.c @@ -1,4 +1,5 @@ #include +#include void asm_rules(char *in, char _asm[27]){ @@ -10,30 +11,87 @@ void asm_rules(char *in, char _asm[27]){ while(word != NULL) { - if (word[strlen(word)-1] == '\n') { - word[strlen(word)-1] = '\0'; //cleans newline from string - } + //instruction set + //aaaaaa bbbbbbb ccccccc ddddddd + //a = opcode, b = input 0, c = input 1, d = output if (strcmp(word, "nop") == 0) { - //keeps the default value (0) + //keeps the default value (0) if nop + } else if (word[0] == ';') { + //comments + break; } else { - if (strcmp(word, "max") == 0) { - _asm[6] = 1; - } else if (strcmp(word, "min") == 0) { - _asm[6] = 2; - } else if (strcmp(word, "any") == 0) { - _asm[6] = 2; - _asm[5] = 1; - } else if (strcmp(word, "cons") == 0) { - _asm[6] = 1; - _asm[5] = 1; + //cases make larger checks harder to read + if(word[0] == 'i') { + //integer + _asm[1] = 1; + } else if(word[0] == 'f') { + //floating + _asm[1] = 2; } - else if (word[0] == '$') { + if (word[0] == '$') { //constants + _asm[0] = 2; //set constant loading (on input 1) } else if (word[0] == '@') { //address location + //beware: beginning yandev style + } else if (strstr(word, "max")) { + _asm[2] = 2; //set layer to arithmetics and logic + _asm[3] = 0; + _asm[4] = 0; + _asm[5] = 1; + } else if (strstr(word, "min")) { + _asm[2] = 2; //set layer to arithmetics and logic + _asm[3] = 0; + _asm[4] = 0; + _asm[5] = 2; + } else if (strstr(word, "any")) { + _asm[2] = 2; //set layer to arithmetics and logic + _asm[3] = 0; + _asm[4] = 2; + _asm[5] = 2; + } else if (strstr(word, "cons")) { + _asm[2] = 2; //set layer to arithmetics and logic + _asm[3] = 0; + _asm[4] = 1; + _asm[5] = 1; + } else if (strstr(word, "add")) { + _asm[2] = 2; //set layer to arithmetics and logic + _asm[3] = 1; + _asm[4] = 0; + _asm[5] = 1; + } else if (strstr(word, "sub")) { + _asm[2] = 2; //set layer to arithmetics and logic + _asm[3] = 1; + _asm[4] = 0; + _asm[5] = 2; + } else if (strstr(word, "mul")) { + _asm[2] = 2; //set layer to arithmetics and logic + _asm[3] = 1; + _asm[4] = 1; + _asm[5] = 0; + } else if (strstr(word, "div")) { + _asm[2] = 2; //set layer to arithmetics and logic + _asm[3] = 1; + _asm[4] = 2; + _asm[5] = 0; + } else if (strstr(word, "dec")) { + _asm[2] = 2; //set layer to arithmetics and logic + _asm[3] = 2; + _asm[4] = 2; + _asm[5] = 0; + } else if (strstr(word, "inc")) { + _asm[2] = 2; //set layer to arithmetics and logic + _asm[3] = 2; + _asm[4] = 2; + _asm[5] = 1; + } else if (strstr(word, "not")) { + _asm[2] = 2; //set layer to arithmetics and logic + _asm[3] = 2; + _asm[4] = 2; + _asm[5] = 2; } }