#include #include #include void trit_flip(char *in, char n0, char n1, char n2, char n3) { in[0] = n0; in[1] = n1; in[2] = n2; in[3] = n3; } void asm_rules(char *in, char *_asm){ char *word = strtok(in, " "); while(word != NULL) { //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) if nop } else if (word[0] == ';') { //comments break; } else { if(word[0] == 'i') { _asm[1] = 1; } else if(word[0] == 'f') { //floating } if (word[0] == '$') { //constants _asm[12] = 2; //set constant loading (on input 1) } else if (word[0] == '@') { //address location //cases make larger checks harder to read } else if (strstr(word, "max")) { trit_flip(_asm, '+', '0', '0', '0'); } else if (strstr(word, "min")) { trit_flip(_asm, '-', '0', '0', '0'); } else if (strstr(word, "any")) { trit_flip(_asm, '0', '0', '0', '0'); } else if (strstr(word, "cons")) { trit_flip(_asm, '-', '+', '0', '0'); } else if (strstr(word, "add")) { trit_flip(_asm, '+', '-', '+', '0'); } else if (strstr(word, "sub")) { trit_flip(_asm, '+', '-', '-', '0'); } else if (strstr(word, "mul")) { trit_flip(_asm, '+', '0', '+', '0'); } else if (strstr(word, "div")) { trit_flip(_asm, '+', '0', '-', '0'); } else if (strstr(word, "dec")) { trit_flip(_asm, '-', '-', '0', '0'); } else if (strstr(word, "inc")) { trit_flip(_asm, '-', '+', '0', '0'); } } word = strtok(NULL, " "); } }