small changes to the asm itself

This commit is contained in:
nova 2024-05-01 22:30:44 +02:00
parent bf787c2d6d
commit c325e645f3

View File

@ -3,11 +3,11 @@
#include <stdlib.h> #include <stdlib.h>
void trit_flip(char *in, char *instruction) { void trit_flip(char *in, char *instruction) {
for (int i = 0; i<(sizeof(in)/sizeof(in[0])); i++) { for (int i = 0; i<27; i++) {
in[i] = instruction[i]; in[i] = instruction[i];
} }
} }
int asm_rules(char *in, char _asm[27]){ int asm_rules(char *in, char *_asm){
for (int i = 0; i < 27; i++) { for (int i = 0; i < 27; i++) {
_asm[i] = 0; _asm[i] = 0;
@ -23,53 +23,52 @@ int asm_rules(char *in, char _asm[27]){
//comments //comments
break; break;
} else { } else {
if(word[0] == 'i') {
//integer
_asm[7] = '0';
} else if(word[0] == 'f') {
//floating
_asm[7] = '-';
}
if (word[0] == '$' || word[0] == '@') {
//cases make larger checks harder to read //cases make larger checks harder to read
} else if (strstr(word, "max")) { if (strstr(word, "max")) {
trit_flip(_asm, "+00000+000000"); trit_flip(_asm, "000000+00000+");
} else if (strstr(word, "min")) { } else if (strstr(word, "min")) {
trit_flip(_asm, "-00000+000000"); trit_flip(_asm, "000000+00000-");
} else if (strstr(word, "any")) { } else if (strstr(word, "any")) {
trit_flip(_asm, "000000+000000"); trit_flip(_asm, "000000+000000");
} else if (strstr(word, "cons")) { } else if (strstr(word, "cons")) {
trit_flip(_asm, "-+0000+000000"); trit_flip(_asm, "000000+0000+-");
} else if (strstr(word, "add")) { } else if (strstr(word, "add")) {
trit_flip(_asm, "+-+000+000000"); trit_flip(_asm, "000000+000+-+");
} else if (strstr(word, "sub")) { } else if (strstr(word, "sub")) {
trit_flip(_asm, "+--000+000000"); trit_flip(_asm, "000000+000--+");
} else if (strstr(word, "mul")) { } else if (strstr(word, "mul")) {
trit_flip(_asm, "+0+000+000000"); trit_flip(_asm, "000000+000+0+");
} else if (strstr(word, "div")) { } else if (strstr(word, "div")) {
trit_flip(_asm, "+0-000+000000"); trit_flip(_asm, "000000+000+0-");
} else if (strstr(word, "dec")) { } else if (strstr(word, "dec")) {
trit_flip(_asm, "--0000+000000"); trit_flip(_asm, "000000+0000--");
} else if (strstr(word, "inc")) { } else if (strstr(word, "inc")) {
trit_flip(_asm, "-+0000+000000"); trit_flip(_asm, "000000+0000+-");
} else if (strstr(word, "iou")) { } else if (strstr(word, "iou")) {
trit_flip(_asm, "--0000-000000"); trit_flip(_asm, "000000-0000--");
} else if (strstr(word, "ieq")) { } else if (strstr(word, "ieq")) {
trit_flip(_asm, "+-0000-000000"); trit_flip(_asm, "000000-0000-+");
} else if (strstr(word, "jmp")) { } else if (strstr(word, "jmp")) {
trit_flip(_asm, "000000-000000"); trit_flip(_asm, "000000-000000");
} else if (strstr(word, "jec")) { } else if (strstr(word, "jec")) {
trit_flip(_asm, "+00000-000000"); trit_flip(_asm, "000000-00000+");
} else if (strstr(word, "mov")) { } else if (strstr(word, "mov")) {
trit_flip(_asm, "+000000000000"); trit_flip(_asm, "000000000000+");
} else if (strstr(word, "Nst")) { //underflow test } else if (strstr(word, "Nst")) { //underflow test
trit_flip(_asm, "-------------"); trit_flip(_asm, "-------------");
} else if (strstr(word, "Pst")) { //overflow test } else if (strstr(word, "Pst")) { //overflow test
trit_flip(_asm, "+++++++++++++"); trit_flip(_asm, "+++++++++++++");
} }
if(word[0] == 'i') {
//integer
_asm[5] = '0';
} else if(word[0] == 'f') {
//floating
_asm[5] = '-';
}
if (word[0] == '$' || word[0] == '@') {
}
} }