changed behaviour of some core methods

This commit is contained in:
Daniel Knüttel 2018-10-09 11:43:00 +02:00
parent 7ecf1d5036
commit a3583fa3ba
2 changed files with 51 additions and 41 deletions

View File

@ -20,7 +20,7 @@ char bci_cm_ldi(uint8_t small_arg, machine_state_t state)
return machine_state_t_default_afterexec(state, 1); return machine_state_t_default_afterexec(state, 1);
} }
// @1 -> $0 // @($1) -> $0
char bci_cm_ld(uint8_t small_arg, machine_state_t state) char bci_cm_ld(uint8_t small_arg, machine_state_t state)
{ {
BCI_CORE_REGISTER_CHECK(small_arg); BCI_CORE_REGISTER_CHECK(small_arg);
@ -33,6 +33,9 @@ char bci_cm_ld(uint8_t small_arg, machine_state_t state)
return res; return res;
} }
BCI_CORE_REGISTER_CHECK(arg);
arg = state->data_reg[arg];
res = machine_state_t_get_mem(state, arg, &arg); res = machine_state_t_get_mem(state, arg, &arg);
if(res) 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); return machine_state_t_default_afterexec(state, 1);
} }
// $0 -> @1 // $0 -> @($1)
char bci_cm_st(uint8_t small_arg, machine_state_t state) char bci_cm_st(uint8_t small_arg, machine_state_t state)
{ {
BCI_CORE_REGISTER_CHECK(small_arg); BCI_CORE_REGISTER_CHECK(small_arg);
@ -56,6 +59,9 @@ char bci_cm_st(uint8_t small_arg, machine_state_t state)
return res; 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]); res = machine_state_t_set_mem(state, arg, state->data_reg[small_arg]);
if(res) 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); 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) char bci_cm_jmp(uint8_t small_arg, machine_state_t state)
{ {
uint16_t arg; BCI_CORE_REGISTER_CHECK(small_arg)
char res = machine_state_t_get_word(state, state->program_counter + 1, &arg); uint16_t arg = state->data_reg[arg];
if(res)
{
return res;
}
state->status_reg = 0;
state->program_counter = arg; state->program_counter = arg;
return 0; return 0;
} }
// if($st_reg): #1 -> $pc; 0 -> $st_reg // if($st_reg): $0 -> $pc; 0 -> $st_reg
// else: do nothing // else: do nothing
char bci_cm_cjmp(uint8_t small_arg, machine_state_t state) char bci_cm_cjmp(uint8_t small_arg, machine_state_t state)
{ {
uint16_t arg; 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;
}
if(state->status_reg) if(state->status_reg)
{ {
state->program_counter = arg; state->program_counter = arg;
return 0; return 0;
} }
state->status_reg = 0;
return machine_state_t_default_afterexec(state, 1); return machine_state_t_default_afterexec(state, 0);
} }
// $pc -> @stack // $pc -> @stack
// #1 -> $pc // $0 -> $pc
char bci_cm_call(uint8_t small_arg, machine_state_t state) char bci_cm_call(uint8_t small_arg, machine_state_t state)
{ {
uint16_t arg; 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) char res = bci_stack_t_push(&(state->stack), state->program_counter);
{
return res;
}
res = bci_stack_t_push(&(state->stack), state->program_counter);
if(res) if(res)
{ {
return res; return res;
@ -305,17 +300,13 @@ char bci_cm_call(uint8_t small_arg, machine_state_t state)
state->program_counter = arg; state->program_counter = arg;
return 0; 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 // else: do nothing
char bci_cm_ccall(uint8_t small_arg, machine_state_t state) char bci_cm_ccall(uint8_t small_arg, machine_state_t state)
{ {
uint16_t arg; 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[small_arg];
if(res)
{
return res;
}
if(state->status_reg) if(state->status_reg)
{ {
@ -328,7 +319,8 @@ char bci_cm_ccall(uint8_t small_arg, machine_state_t state)
return 0; return 0;
} }
return machine_state_t_default_afterexec(state, 1); state->status_reg = 0;
return machine_state_t_default_afterexec(state, 0);
} }
// @stack -> $pc // @stack -> $pc
char bci_cm_ret(uint8_t small_arg, machine_state_t state) 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 // 1 -> $su_reg
char bci_cm_stop(uint8_t small_arg, machine_state_t state) 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); 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);
}

View File

@ -32,10 +32,10 @@
// #1 -> $0 // #1 -> $0
char bci_cm_ldi(uint8_t small_arg, machine_state_t state); 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); 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); 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 // else: 0 -> $st_reg
char bci_cm_eq(uint8_t small_arg, machine_state_t state); 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); 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 // else: do nothing
char bci_cm_cjmp(uint8_t small_arg, machine_state_t state); char bci_cm_cjmp(uint8_t small_arg, machine_state_t state);
// $pc -> @stack // $pc -> @stack
// #1 -> $pc // $0 -> $pc
char bci_cm_call(uint8_t small_arg, machine_state_t state); 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 // else: do nothing
char bci_cm_ccall(uint8_t small_arg, machine_state_t state); char bci_cm_ccall(uint8_t small_arg, machine_state_t state);