commetの実装やらなにやら
http://alohakun.blog7.fc2.com/blog-entry-597.html
あろはさんが、そんなこと言ってます。
おお、これ面白そう。
アセンブラはnasmを参考にx86のやつ作ってみたいと思って挫折してたりするので、
簡単なマシンで練習っていうのはいいんだろうなと。
とりあえず、Dに適当移植中。あれ、bitフィールドってDになかったんだっけ?
仕様をぱっと見ないな。ライブラリにあったんだっけ?
まぁ、セットするのと取り出す関数作るとかすればいいかと。
クラスのほうがわかりいいかなぁ。
いや、テンプレートにしたほうがとか、いや、簡単なのはstructを使ったものでいいのではとか思うのでした。
以下ソース。
ushort PR; ushort GR0; ushort GR1; ushort GR2; ushort GR3; ushort GR4; ushort GR5; ushort GR6; ushort[65536] memory; struct FLAG_REG { // uchar OF : 1; // uchar SF : 1; // uchar ZF : 1; bit OF; bit SF; bit ZF; } FLAG_REG flag_reg; /* * 第一ワード : 4 bit 区切りで,それぞれ |主 OP | 副 OP | レジスタ 1 | レジスタ 2| * 第二ワード : アドレス (無い命令もある) */ int MAIN_OP(int W1) { return ((W1 & 0xf000) >> 12); } int SUB_OP(int W1) { return ((W1 & 0x0f00) >> 8); } int R1(int W1) { return ((W1 & 0x00f0) >> 4); } int R2(int W1) { return (W1 & 0x000f); } int NOP(int W1) { return ((MAIN_OP(W1) == 0x0) && (SUB_OP(W1) == 0x0)); } /* no operation */ int LD(int W1) { return ((MAIN_OP(W1) == 0x1) && (SUB_OP(W1) == 0x0)); } /* load */ int ST(int W1) { return ((MAIN_OP(W1) == 0x1) && (SUB_OP(W1) == 0x1)); } /* store */ int LAD(int W1) { return ((MAIN_OP(W1) == 0x1) && (SUB_OP(W1) == 0x2)); } /* load address */ int LD(int W1) { return ((MAIN_OP(W1) == 0x1) && (SUB_OP(W1) == 0x3)); } /* load */ int ADDA(int W1) { return ((MAIN_OP(W1) == 0x2) && (SUB_OP(W1) == 0x0)); } /* add arithmetic */ int SUBA(int W1) { return ((MAIN_OP(W1) == 0x2) && (SUB_OP(W1) == 0x1)); } /* subtract arithmetic */ int ADDL(int W1) { return ((MAIN_OP(W1) == 0x2) && (SUB_OP(W1) == 0x2)); } /* add logical */ int SUBL(int W1) { return ((MAIN_OP(W1) == 0x2) && (SUB_OP(W1) == 0x3)); } /* subtract logical */ int ADDA(int W1) { return ((MAIN_OP(W1) == 0x2) && (SUB_OP(W1) == 0x4)); } /* add arithmetic */ int SUBA(int W1) { return ((MAIN_OP(W1) == 0x2) && (SUB_OP(W1) == 0x5)); } /* subtract arithmetic */ int ADDL(int W1) { return ((MAIN_OP(W1) == 0x2) && (SUB_OP(W1) == 0x6)); } /* add logical */ int SUBL(int W1) { return ((MAIN_OP(W1) == 0x2) && (SUB_OP(W1) == 0x7)); } /* subtract logical */ int AND(int W1) { return ((MAIN_OP(W1) == 0x3) && (SUB_OP(W1) == 0x0)); } /* and */ int OR(int W1) { return ((MAIN_OP(W1) == 0x3) && (SUB_OP(W1) == 0x1)); } /* or */ int XOR(int W1) { return ((MAIN_OP(W1) == 0x3) && (SUB_OP(W1) == 0x2)); } /* exclusive or */ int AND(int W1) { return ((MAIN_OP(W1) == 0x3) && (SUB_OP(W1) == 0x3)); } /* and */ int OR(int W1) { return ((MAIN_OP(W1) == 0x3) && (SUB_OP(W1) == 0x4)); } /* or */ int XOR(int W1) { return ((MAIN_OP(W1) == 0x3) && (SUB_OP(W1) == 0x5)); } /* exclusive or */ int CPA(int W1) { return ((MAIN_OP(W1) == 0x4) && (SUB_OP(W1) == 0x0)); } /* compare arithmetic */ int CPL(int W1) { return ((MAIN_OP(W1) == 0x4) && (SUB_OP(W1) == 0x1)); } /* compare logical */ int CPA(int W1) { return ((MAIN_OP(W1) == 0x4) && (SUB_OP(W1) == 0x2)); } /* compare arithmetic */ int CPL(int W1) { return ((MAIN_OP(W1) == 0x4) && (SUB_OP(W1) == 0x3)); } /* compare logical */ int SLA(int W1) { return ((MAIN_OP(W1) == 0x5) && (SUB_OP(W1) == 0x0)); } /* shift left arithmetic */ int SRA(int W1) { return ((MAIN_OP(W1) == 0x5) && (SUB_OP(W1) == 0x1)); } /* shift right arithmetic */ int SLL(int W1) { return ((MAIN_OP(W1) == 0x5) && (SUB_OP(W1) == 0x2)); } /* shift left logical */ int SRL(int W1) { return ((MAIN_OP(W1) == 0x5) && (SUB_OP(W1) == 0x3)); } /* shift right logical */ int JMI(int W1) { return ((MAIN_OP(W1) == 0x6) && (SUB_OP(W1) == 0x1)); } /* jump on minus */ int JNZ(int W1) { return ((MAIN_OP(W1) == 0x6) && (SUB_OP(W1) == 0x2)); } /* jump on non zero */ int JZE(int W1) { return ((MAIN_OP(W1) == 0x6) && (SUB_OP(W1) == 0x3)); } /* jump on zero */ int JUMP(int W1) { return ((MAIN_OP(W1) == 0x6) && (SUB_OP(W1) == 0x4)); } /* unconditional jump */ int JPL(int W1) { return ((MAIN_OP(W1) == 0x6) && (SUB_OP(W1) == 0x5)); } /* jump on plus */ int JOV(int W1) { return ((MAIN_OP(W1) == 0x6) && (SUB_OP(W1) == 0x6)); } /* jump on overflow */ int PUSH(int W1) { return ((MAIN_OP(W1) == 0x7) && (SUB_OP(W1) == 0x0)); } /* push */ int POP(int W1) { return ((MAIN_OP(W1) == 0x7) && (SUB_OP(W1) == 0x1)); } /* pop */ int CALL(int W1) { return ((MAIN_OP(W1) == 0x8) && (SUB_OP(W1) == 0x0)); } /* call subroutine */ int RET(int W1) { return ((MAIN_OP(W1) == 0x8) && (SUB_OP(W1) == 0x1)); } /* return from subroutine */ int SVC(int W1) { return ((MAIN_OP(W1) == 0xf) && (SUB_OP(W1) == 0x0)); } /* supervisor call */
こんな、エラーでとります。
commet.d(38): function commet.LD conflicts with commet.LD at commet.d(35) commet.d(44): function commet.ADDA conflicts with commet.ADDA at commet.d(40) commet.d(45): function commet.SUBA conflicts with commet.SUBA at commet.d(41) commet.d(46): function commet.ADDL conflicts with commet.ADDL at commet.d(42) commet.d(47): function commet.SUBL conflicts with commet.SUBL at commet.d(43) commet.d(52): function commet.AND conflicts with commet.AND at commet.d(49) commet.d(53): function commet.OR conflicts with commet.OR at commet.d(50) commet.d(54): function commet.XOR conflicts with commet.XOR at commet.d(51) commet.d(58): function commet.CPA conflicts with commet.CPA at commet.d(56) commet.d(59): function commet.CPL conflicts with commet.CPL at commet.d(57)