diff --git a/interpreter/core_methods.c b/interpreter/core_methods.c index b63a863..448fc77 100644 --- a/interpreter/core_methods.c +++ b/interpreter/core_methods.c @@ -20,7 +20,7 @@ char bci_cm_ldi(uint8_t small_arg, machine_state_t state) return machine_state_t_default_afterexec(state, 1); } -// @1 -> $0 +// @($1) -> $0 char bci_cm_ld(uint8_t small_arg, machine_state_t state) { BCI_CORE_REGISTER_CHECK(small_arg); @@ -33,6 +33,9 @@ char bci_cm_ld(uint8_t small_arg, machine_state_t state) return res; } + BCI_CORE_REGISTER_CHECK(arg); + arg = state->data_reg[arg]; + res = machine_state_t_get_mem(state, arg, &arg); if(res) { @@ -43,7 +46,7 @@ char bci_cm_ld(uint8_t small_arg, machine_state_t state) return machine_state_t_default_afterexec(state, 1); } -// $0 -> @1 +// $0 -> @($1) char bci_cm_st(uint8_t small_arg, machine_state_t state) { BCI_CORE_REGISTER_CHECK(small_arg); @@ -56,6 +59,9 @@ char bci_cm_st(uint8_t small_arg, machine_state_t state) return res; } + BCI_CORE_REGISTER_CHECK(arg); + arg = state->data_reg[arg]; + res = machine_state_t_set_mem(state, arg, state->data_reg[small_arg]); if(res) { @@ -250,54 +256,43 @@ char bci_cm_eq(uint8_t small_arg, machine_state_t state) return machine_state_t_default_afterexec(state, 0); } -// #1 -> $pc; 0 -> $st_reg +// $0 -> $pc; 0 -> $st_reg char bci_cm_jmp(uint8_t small_arg, machine_state_t state) { - uint16_t arg; - char res = machine_state_t_get_word(state, state->program_counter + 1, &arg); - - if(res) - { - return res; - } + BCI_CORE_REGISTER_CHECK(small_arg) + uint16_t arg = state->data_reg[arg]; + state->status_reg = 0; state->program_counter = arg; return 0; } -// if($st_reg): #1 -> $pc; 0 -> $st_reg +// if($st_reg): $0 -> $pc; 0 -> $st_reg // else: do nothing char bci_cm_cjmp(uint8_t small_arg, machine_state_t state) { uint16_t arg; - char res = machine_state_t_get_word(state, state->program_counter + 1, &arg); - - if(res) - { - return res; - } + BCI_CORE_REGISTER_CHECK(small_arg) + arg = state->data_reg[arg]; if(state->status_reg) { state->program_counter = arg; return 0; } + state->status_reg = 0; - return machine_state_t_default_afterexec(state, 1); + return machine_state_t_default_afterexec(state, 0); } // $pc -> @stack -// #1 -> $pc +// $0 -> $pc char bci_cm_call(uint8_t small_arg, machine_state_t state) { uint16_t arg; - char res = machine_state_t_get_word(state, state->program_counter + 1, &arg); + BCI_CORE_REGISTER_CHECK(small_arg) + arg = state->data_reg[arg]; - if(res) - { - return res; - } - - res = bci_stack_t_push(&(state->stack), state->program_counter); + char res = bci_stack_t_push(&(state->stack), state->program_counter); if(res) { return res; @@ -305,17 +300,13 @@ char bci_cm_call(uint8_t small_arg, machine_state_t state) state->program_counter = arg; return 0; } -// if($st_reg): $pc -> @stack; #1 -> $pc; 0 -> $st_reg +// if($st_reg): $pc -> @stack; $0 -> $pc; 0 -> $st_reg // else: do nothing char bci_cm_ccall(uint8_t small_arg, machine_state_t state) { uint16_t arg; - char res = machine_state_t_get_word(state, state->program_counter + 1, &arg); - - if(res) - { - return res; - } + BCI_CORE_REGISTER_CHECK(small_arg); + arg = state->data_reg[small_arg]; if(state->status_reg) { @@ -328,7 +319,8 @@ char bci_cm_ccall(uint8_t small_arg, machine_state_t state) return 0; } - return machine_state_t_default_afterexec(state, 1); + state->status_reg = 0; + return machine_state_t_default_afterexec(state, 0); } // @stack -> $pc char bci_cm_ret(uint8_t small_arg, machine_state_t state) @@ -354,7 +346,21 @@ char bci_cm_cl(uint8_t small_arg, machine_state_t state) // 1 -> $su_reg char bci_cm_stop(uint8_t small_arg, machine_state_t state) { - state->shutdown_reg = 0; + state->shutdown_reg = 1; return machine_state_t_default_afterexec(state, 0); } +// if($st_reg): 0 -> $st_reg +// else: 1 -> $st_reg +char bci_cm_not(uint8_t small_arg, machine_state_t state) +{ + if(state->status_reg) + { + state->status_reg = 0; + } + else + { + status->status_reg = 1; + } + return machine_state_t_default_afterexec(state, 0); +} diff --git a/interpreter/core_methods.h b/interpreter/core_methods.h index b7fdd08..e36892a 100644 --- a/interpreter/core_methods.h +++ b/interpreter/core_methods.h @@ -32,10 +32,10 @@ // #1 -> $0 char bci_cm_ldi(uint8_t small_arg, machine_state_t state); -// @1 -> $0 +// @($1) -> $0 char bci_cm_ld(uint8_t small_arg, machine_state_t state); -// $0 -> @1 +// $0 -> @($1) char bci_cm_st(uint8_t small_arg, machine_state_t state); @@ -82,18 +82,22 @@ char bci_cm_le(uint8_t small_arg, machine_state_t state); // else: 0 -> $st_reg char bci_cm_eq(uint8_t small_arg, machine_state_t state); -// #1 -> $pc +// if($st_reg): 0 -> $st_reg +// else: 1 -> $st_reg +char bci_cm_not(uint8_t small_arg, machine_state_t state); + +// $1 -> $pc char bci_cm_jmp(uint8_t small_arg, machine_state_t state); -// if($st_reg): #1 -> $pc +// if($st_reg): $1 -> $pc // else: do nothing char bci_cm_cjmp(uint8_t small_arg, machine_state_t state); // $pc -> @stack -// #1 -> $pc +// $0 -> $pc char bci_cm_call(uint8_t small_arg, machine_state_t state); -// if($st_reg): $pc -> @stack; #1 -> $pc +// if($st_reg): $pc -> @stack; $0 -> $pc // else: do nothing char bci_cm_ccall(uint8_t small_arg, machine_state_t state);