diff --git a/emul_inst_exec.c b/emul_inst_exec.c index 7c8dafa..01f2203 100644 --- a/emul_inst_exec.c +++ b/emul_inst_exec.c @@ -2,6 +2,25 @@ #include "emul_io_std.h" #include +// exit message +static char faild_message(); +#define EXIT_MESSAGE_LENGTH 128 +void emul_inst_exec_get_faild_message(char *msg); +// Private +//void emul_inst_exec_set_faild_message(); + +// propaty +static RUNMODE RunMode; + +void emul_inst_exec_set_runmode(RUNMODE mode) { + RunMode = mode; +} +RUNMODE emul_inst_exec_get_runmode() { + return RunMode; +} + +// + int emul_inst_exec_load(char *filename) { return emul_inst_dec_load(filename); } @@ -192,9 +211,9 @@ /* Execute pseudocode * RETURN: - * seccsess: 1 + * succsess: 1 * failed : 0 */ -int emul_inst_exec_pseudo(char token[LOAD_TOKEN_MAX]) { +exitcode_t emul_inst_exec_pseudo(char token[LOAD_TOKEN_MAX]) { char label[LABEL_NAME_LENGTH_MAX]; char temp[LOAD_TOKEN_MAX]; // execute pseudocode. @@ -205,7 +224,7 @@ // 例外処理:疑似コードが見つからない if ( ps_id == PSEUDO_DECODE_ERROR ) { - return 0; + return Failed; } switch( ps_id ) { @@ -235,10 +254,12 @@ emul_reg_get(Spc) ); break; - //case RUN: - // break; - //case STEP: - // break; + case RUN: + emul_inst_exec_set_runmode(Run); + break; + case STEP: + emul_inst_exec_set_runmode(Step); + break; //case INPUT: // break; //case OUTPUT: @@ -251,14 +272,14 @@ emul_out_std_debug("[疑似コード]まだ実装してないので待って!\n"); } - return 1; + return Success; } /* Execute Step * RETURN: - * seccsess: 1 + * succsess: 1 * failed : 0 */ -int emul_inst_exec_step() +exitcode_t emul_inst_exec_step() #define COUNT_OPERAND_MAX 3 { char token[LOAD_TOKEN_MAX]; @@ -275,7 +296,7 @@ if ( emul_inst_dec_get_token(token) == 0 ) { emul_out_std_err("Non exist next token\n"); // 次のトークンが見つからない場合終了 - return 0; + return Failed; } emul_out_std_debug("token: %s\n", token); // オペコードIDを取得 @@ -288,11 +309,10 @@ // 例外処理:疑似コードが見つからない if ( ps_id == PSEUDO_DECODE_ERROR ) { emul_out_std_err("Non exist next pseudocode\n"); - return 0; + return Failed; } else { // 疑似コードを実行 - emul_inst_exec_pseudo(token); - return 1; + return emul_inst_exec_pseudo(token); } } @@ -395,26 +415,27 @@ } //emul_inst_dec_get_operand(token); - return 1; + return Success; } /* Execute Run All * RETURN: - * seccsess: 1 + * succsess: 1 * failed : 0 */ -int emul_inst_exec_run() { +exitcode_t emul_inst_exec_run() { // step関数を終わるまで呼び出せばよい int exit_code; - while ( (exit_code = emul_inst_exec_step()) ); + while ( (exit_code = emul_inst_exec_step()) == Success ) { + if (RunMode == Step) { + puts("...Wait for step, please input key enter."); + getchar(); + } + } return exit_code; } int main(void) { emul_inst_exec_load("test_asm/test.asm"); emul_reg_init(); - while ( emul_inst_exec_step() ) { - puts("...Wait for step, please input key enter."); - getchar(); - } - //emul_inst_exec_run(); + emul_inst_exec_run(); } diff --git a/emul_inst_exec.h b/emul_inst_exec.h index 45470cb..3cc4428 100644 --- a/emul_inst_exec.h +++ b/emul_inst_exec.h @@ -7,6 +7,21 @@ #include "emul_mem.h" #include "emul_label.h" +// Exit code +typedef enum { + Failed, + Success, + Stop +} exitcode_t; + +// ランモード +typedef enum { + Run, + Step +} RUNMODE; + +void emul_inst_exec_set_runmode(RUNMODE mode); +RUNMODE emul_inst_exec_get_runmode(); int emul_inst_exec_load(char *filename); @@ -14,12 +29,12 @@ * RETURN: * seccsess: 1 * failed : 0 */ -int emul_inst_exec_step(); +exitcode_t emul_inst_exec_step(); /* Execute Run All * RETURN: * seccsess: 1 * failed : 0 */ -int emul_inst_exec_run(); +exitcode_t emul_inst_exec_run(); #endif diff --git a/test_asm/for-0-10.asm b/test_asm/for-0-10.asm new file mode 100644 index 0000000..8ac6197 --- /dev/null +++ b/test_asm/for-0-10.asm @@ -0,0 +1,18 @@ +:DUMP DEBUG1 +addi $s0 $zero 0 +:REGCAT $s0 + +:DUMP DEBUG0 + +:LABEL LOOP +addi $s0 $s0 1 +:REGCAT $s0 +slti $t0 $s0 10 +bne $t0 $zero LOOP + +addi $s0 $zero 0 +:LABEL LOOP1 +addi $s0 $s0 1 +:REGCAT $s0 +slti $t0 $s0 10 +bne $t0 $zero LOOP1 diff --git a/test_asm/test.asm b/test_asm/test.asm index 8ac6197..eebc433 100644 --- a/test_asm/test.asm +++ b/test_asm/test.asm @@ -1,8 +1,9 @@ -:DUMP DEBUG1 +:DUMP DEBUG0 +:RUN addi $s0 $zero 0 :REGCAT $s0 -:DUMP DEBUG0 +:STEP :LABEL LOOP addi $s0 $s0 1 @@ -10,6 +11,7 @@ slti $t0 $s0 10 bne $t0 $zero LOOP +:RUN addi $s0 $zero 0 :LABEL LOOP1 addi $s0 $s0 1