commit 05ba1a534e7081c3aaed75570bf6715175db2108
parent 6bd8a1b98acaa0f692e80a8758cc8b44772ac1b2
Author: bsandro <[email protected]>
Date: Sun, 9 Jan 2022 23:15:08 +0200
basic opcodes
Diffstat:
M | main.c | | | 27 | ++++++++++++++++++++++++--- |
1 file changed, 24 insertions(+), 3 deletions(-)
diff --git a/main.c b/main.c
@@ -83,7 +83,7 @@ int main(void)
instruction.reg_b = (platter & 56) >> 3; // mask 000 111 000 = 56
instruction.reg_c = platter & 7; // mask 000 000 111 = 7
}
- print_instruction(instruction);
+ //print_instruction(instruction);
exec_instruction(&state, instruction);
finger++;
if (finger >= state.arena.arrays[0].size / PLATTER_SIZE) {
@@ -113,8 +113,29 @@ void print_instruction(struct instruction_t instruction) {
}
void exec_instruction(struct state_t *state, struct instruction_t in) {
- (void)state;
- (void)in;
+ switch (in.opcode) {
+ case CMOV:
+ if (state->registers[in.reg_c] != 0) state->registers[in.reg_a] = state->registers[in.reg_b];
+ break;
+ case ARRI:
+ state->registers[in.reg_a] = state->arena.arrays[state->registers[in.reg_b]].data[state->registers[in.reg_c]];
+ break;
+ case ARRA:
+ state->arena.arrays[in.reg_a].data[state->registers[in.reg_b]] = state->registers[in.reg_c];
+ break;
+ case ADD:
+ state->registers[in.reg_a] = state->registers[in.reg_b] + state->registers[in.reg_c]; //@todo: modulo 2^32 ?
+ break;
+ case MUL:
+ state->registers[in.reg_a] = state->registers[in.reg_b] * state->registers[in.reg_c]; //@todo: modulo 2^32 ?
+ break;
+ case DIV:
+ state->registers[in.reg_a] = state->registers[in.reg_b] / state->registers[in.reg_c]; //@todo: modulo 2^32 ?
+ break;
+ case NOTA:
+ state->registers[in.reg_a] = ~(state->registers[in.reg_b] & state->registers[in.reg_c]);
+ break;
+ }
}
uint32_t array_add(struct arena_t *arena, uint32_t size) {