From df0bb9d8f66fd04ee929457af819b51d1d6a059d Mon Sep 17 00:00:00 2001 From: chaoskagami Date: Sat, 4 Jun 2016 23:56:56 -0400 Subject: [PATCH] Add or, xor, and not to the VM --- host/bytecode_asm.py | 17 ++++++++++++++-- source/interp.c | 46 +++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 60 insertions(+), 3 deletions(-) diff --git a/host/bytecode_asm.py b/host/bytecode_asm.py index 7d67c19..2f882e1 100755 --- a/host/bytecode_asm.py +++ b/host/bytecode_asm.py @@ -148,11 +148,24 @@ def parse_op(token_list, instr_offs): # We cut corners and calculate stuff manually. return bytearray.fromhex("09") + bytearray([len(token_list[1]) / 2]) + bytearray.fromhex(token_list[1]) - elif token_list[0] == "title": + elif token_list[0] == "or": if s != 2: syn_err("invalid number of arguments") - return bytearray.fromhex("0A") + bytearray([len(token_list[1]) / 2 / 8]) + bytearray.fromhex(token_list[1]) + # We cut corners and calculate stuff manually. + return bytearray.fromhex("0A") + bytearray([len(token_list[1]) / 2]) + bytearray.fromhex(token_list[1]) + elif token_list[0] == "xor": + if s != 2: + syn_err("invalid number of arguments") + + # We cut corners and calculate stuff manually. + return bytearray.fromhex("0B") + bytearray([len(token_list[1]) / 2]) + bytearray.fromhex(token_list[1]) + elif token_list[0] == "not": + if s != 2: + syn_err("invalid number of arguments") + + # We cut corners and calculate stuff manually. + return bytearray.fromhex("09") + bytearray.fromhex(token_list[1]) def pad_zero_r(x, c): while len(x) < c: diff --git a/source/interp.c b/source/interp.c index 0823938..6460716 100644 --- a/source/interp.c +++ b/source/interp.c @@ -18,7 +18,10 @@ #define OP_JMP 0x07 #define OP_REWIND 0x08 #define OP_AND 0x09 -#define OP_TITLE 0x0A +#define OP_OR 0x0A +#define OP_XOR 0x0B +#define OP_NOT 0x0C + #define OP_NEXT 0xFF #ifdef LOADER @@ -254,6 +257,47 @@ exec_bytecode(uint8_t *bytecode, uint32_t len, int debug) } code += *(code - 1); break; + case OP_OR: + if (debug) + log("or\n"); + code += 2; + if (!test_was_false) { + for (i = 0; i < *(code - 1); i++) { + *(current_mode->memory + offset) |= code[i]; + } + offset += *(code - 1); + } else { + test_was_false = 0; + } + code += *(code - 1); + break; + case OP_XOR: + if (debug) + log("xor\n"); + code += 2; + if (!test_was_false) { + for (i = 0; i < *(code - 1); i++) { + *(current_mode->memory + offset) ^= code[i]; + } + offset += *(code - 1); + } else { + test_was_false = 0; + } + code += *(code - 1); + break; + case OP_NOT: + if (debug) + log("not\n"); + if (!test_was_false) { + for (i = 0; i < *(code + 1); i++) { + *(current_mode->memory + offset) = ~*(current_mode->memory + offset); + } + offset += *(code + 1); + } else { + test_was_false = 0; + } + code += 2; + break; case OP_NEXT: if (debug) log("next\n"); -- 2.39.5