115 lines
2.6 KiB
C
115 lines
2.6 KiB
C
#ifndef bci_core_methods_h__
|
|
#define bci_core_methods_h__
|
|
#include "interpreter.h"
|
|
|
|
|
|
/*
|
|
* This library brings a set of essential core methods.
|
|
* */
|
|
|
|
|
|
/*
|
|
* Naming conventions:
|
|
*
|
|
* x = 0, 1, 2, 3...: arguments.
|
|
* 0: small_arg (6 bit)
|
|
* 1, 2, ...: 16 bit optional arguments
|
|
*
|
|
* $x: value of data register x
|
|
* @x: value of memory word x
|
|
* #x: value of argument x
|
|
* 0, 1, 2, ...: integer 0, 1, 2, ...
|
|
*
|
|
* -> write result in register/word on the right
|
|
*
|
|
* st_reg: status register
|
|
* su_reg: shutdown register
|
|
* pc: program counter
|
|
*
|
|
* stack: the builtin stack
|
|
* */
|
|
|
|
// #1 -> $0
|
|
char bci_cm_ldi(uint8_t small_arg, machine_state_t state);
|
|
|
|
// @($1) -> $0
|
|
char bci_cm_ld(uint8_t small_arg, machine_state_t state);
|
|
|
|
// $0 -> @($1)
|
|
char bci_cm_st(uint8_t small_arg, machine_state_t state);
|
|
|
|
|
|
// NOTES on inc, dec, add, sub, mul, div:
|
|
//
|
|
// These methods will store the overflow-word in $st_reg.
|
|
|
|
|
|
// $0 + 1 -> $0
|
|
char bci_cm_inc(uint8_t small_arg, machine_state_t state);
|
|
|
|
// $0 - 1 -> $0
|
|
char bci_cm_dec(uint8_t small_arg, machine_state_t state);
|
|
|
|
// $0 + $1 -> $0
|
|
char bci_cm_add(uint8_t small_arg, machine_state_t state);
|
|
|
|
// $0 - $1 -> $0
|
|
char bci_cm_sub(uint8_t small_arg, machine_state_t state);
|
|
|
|
// $0 * $1 -> $0
|
|
char bci_cm_mul(uint8_t small_arg, machine_state_t state);
|
|
|
|
// $0 / $1 -> $0
|
|
char bci_cm_div(uint8_t small_arg, machine_state_t state);
|
|
|
|
// if($0 > 0): 1 -> $st_reg
|
|
// else: 0 -> $st_reg
|
|
char bci_cm_gt(uint8_t small_arg, machine_state_t state);
|
|
|
|
// if($0 >= 0): 1 -> $st_reg
|
|
// else: 0 -> $st_reg
|
|
char bci_cm_ge(uint8_t small_arg, machine_state_t state);
|
|
|
|
// if($0 < 0): 1 -> $st_reg
|
|
// else: 0 -> $st_reg
|
|
char bci_cm_lt(uint8_t small_arg, machine_state_t state);
|
|
|
|
// if($0 <= 0): 1 -> $st_reg
|
|
// else: 0 -> $st_reg
|
|
char bci_cm_le(uint8_t small_arg, machine_state_t state);
|
|
|
|
// if($0 == 0): 1 -> $st_reg
|
|
// else: 0 -> $st_reg
|
|
char bci_cm_eq(uint8_t small_arg, machine_state_t state);
|
|
|
|
// 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
|
|
// else: do nothing
|
|
char bci_cm_cjmp(uint8_t small_arg, machine_state_t state);
|
|
|
|
// $pc -> @stack
|
|
// $0 -> $pc
|
|
char bci_cm_call(uint8_t small_arg, machine_state_t state);
|
|
|
|
// if($st_reg): $pc -> @stack; $0 -> $pc
|
|
// else: do nothing
|
|
char bci_cm_ccall(uint8_t small_arg, machine_state_t state);
|
|
|
|
// @stack -> $pc
|
|
char bci_cm_ret(uint8_t small_arg, machine_state_t state);
|
|
|
|
// 0 -> $st_reg
|
|
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);
|
|
|
|
|
|
#endif
|