#include "emul_inst_exec.h" #include <stdio.h> int emul_inst_exec_loadfile(char *filename) { return emul_inst_dec_load(filename); } void emul_inst_exec_closefile() { emul_inst_dec_close(); } /* オペコード解読処理群 - START */ void emul_inst_exec_add(int r0, int r1, int r2) { printf("Execute: add r0[%d], r1[%d], r2[%d];\n", r0, r1, r2); } void emul_inst_exec_sub(int r0, int r1, int r2) { printf("Execute: sub r0[%d], r1[%d], r2[%d];\n", r0, r1, r2); } /* オペコード解読処理群 - END */ /* Execute Step * RETURN: * seccsess: 1 * failed : 0 */ int emul_inst_exec_step() #define COUNT_OPERAND_MAX 3 { char token[LOAD_TOKEN_MAX]; int op_id, oprs[COUNT_OPERAND_MAX]; // トークンを取得 emul_inst_dec_get_token(token); // オペコードIDを取得 op_id = emul_inst_dec_get_opecode(token); // 例外処理: オペコードが見つからない if ( op_id == OPECODE_DECODE_ERROR ) { printf("Non exist next operand\n"); return 0; } // オペコード実行 switch (op_id) { case ADD : emul_inst_exec_add( emul_inst_dec_get_next_operand(), emul_inst_dec_get_next_operand(), emul_inst_dec_get_next_operand() ); break; //case ADDI: // break; case SUB : emul_inst_exec_sub( emul_inst_dec_get_next_operand(), emul_inst_dec_get_next_operand(), emul_inst_dec_get_next_operand() ); break; //case SLT : // break; //case SLTI: // break; //case SEQ : // break; //case SGE : // break; //case SGT : // break; //case SLE : // break; //case SNE : // break; //case B : // break; //case BEQ : // break; //case BNE : // break; //case J : // break; //case LW : // break; //case SW : // break; //case MOVE: // break; default: printf("まだ実装してないので待って!\n"); } //emul_inst_dec_get_operand(token); return 1; } /* Execute Run All * RETURN: * seccsess: 1 * failed : 0 */ int emul_inst_exec_run() { // step関数を終わるまで呼び出せばよい return ; } int main(void) { emul_inst_exec_loadfile("test.asm"); while ( emul_inst_exec_step() ) { puts("...Wait for step, please input key enter."); getchar(); } emul_inst_exec_closefile(); return 0; }