@@ 486,18 486,66 @@ to align things.
i ..
~~~
-char *insts = "..lwlhlbfwfhfbswshsbdudrsppupoeqneltgtadsumudmmdanorxontslsrunparlcaccjucjrecrsvhisitiiihaicacpcscrrrwcybcuu";
-
-int opcode_for(char *s) {
- int16_t* s16 = (int16_t *)s;
- int16_t* op16 = (int16_t *)insts;
- int i = 0;
- for (i = 0; i <= strlen(insts)/2; i++) {
- if (s16[0] == op16[i]) {
- return i;
- }
- }
- return 0;
+int opcode_for(char *raw) {
+ char s[3];
+ s[0] = raw[0]; s[1] = raw[1]; s[2] = '\0';
+ if (strcmp(s, "..") == 0) return 0;
+ if (strcmp(s, "lw") == 0) return 1;
+ if (strcmp(s, "lh") == 0) return 2;
+ if (strcmp(s, "lb") == 0) return 3;
+ if (strcmp(s, "fw") == 0) return 4;
+ if (strcmp(s, "fh") == 0) return 5;
+ if (strcmp(s, "fb") == 0) return 6;
+ if (strcmp(s, "sw") == 0) return 7;
+ if (strcmp(s, "sh") == 0) return 8;
+ if (strcmp(s, "sb") == 0) return 9;
+ if (strcmp(s, "du") == 0) return 10;
+ if (strcmp(s, "dr") == 0) return 11;
+ if (strcmp(s, "sp") == 0) return 12;
+ if (strcmp(s, "pu") == 0) return 13;
+ if (strcmp(s, "po") == 0) return 14;
+ if (strcmp(s, "eq") == 0) return 15;
+ if (strcmp(s, "ne") == 0) return 16;
+ if (strcmp(s, "lt") == 0) return 17;
+ if (strcmp(s, "gt") == 0) return 18;
+ if (strcmp(s, "ad") == 0) return 19;
+ if (strcmp(s, "su") == 0) return 20;
+ if (strcmp(s, "mu") == 0) return 21;
+ if (strcmp(s, "dm") == 0) return 22;
+ if (strcmp(s, "md") == 0) return 23;
+ if (strcmp(s, "an") == 0) return 24;
+ if (strcmp(s, "or") == 0) return 25;
+ if (strcmp(s, "xo") == 0) return 26;
+ if (strcmp(s, "nt") == 0) return 27;
+ if (strcmp(s, "sl") == 0) return 28;
+ if (strcmp(s, "sr") == 0) return 29;
+ if (strcmp(s, "pa") == 0) return 30;
+ if (strcmp(s, "un") == 0) return 31;
+ if (strcmp(s, "rl") == 0) return 32;
+ if (strcmp(s, "ca") == 0) return 33;
+ if (strcmp(s, "cc") == 0) return 34;
+ if (strcmp(s, "ju") == 0) return 35;
+ if (strcmp(s, "cj") == 0) return 36;
+ if (strcmp(s, "re") == 0) return 37;
+ if (strcmp(s, "cr") == 0) return 38;
+ if (strcmp(s, "sv") == 0) return 39;
+ if (strcmp(s, "hi") == 0) return 40;
+ if (strcmp(s, "si") == 0) return 41;
+ if (strcmp(s, "ti") == 0) return 42;
+ if (strcmp(s, "ii") == 0) return 43;
+ if (strcmp(s, "ha") == 0) return 44;
+ if (strcmp(s, "ic") == 0) return 45;
+ if (strcmp(s, "ac") == 0) return 46;
+ if (strcmp(s, "pc") == 0) return 47;
+ if (strcmp(s, "sc") == 0) return 48;
+ if (strcmp(s, "rr") == 0) return 49;
+ if (strcmp(s, "rw") == 0) return 50;
+ if (strcmp(s, "cy") == 0) return 51;
+ if (strcmp(s, "bc") == 0) return 52;
+ if (strcmp(s, "uu") == 0) return 53;
+ printf("Invalid opcode: %s\n", s);
+ exit(1);
+ return -1;
}
void instructions(char *s) {