From 651507b4fd3a872ccfd212de55b733c0cc2b762f Mon Sep 17 00:00:00 2001 From: koostosh Date: Thu, 6 Jan 2022 14:44:09 +0100 Subject: [PATCH] NOT should be a bitwise negation, not logic --- README.md | 2 +- include/machine.hpp | 2 +- include/word.hpp | 5 +++++ test/word_test.cpp | 3 +-- 4 files changed, 8 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index cb5ddd2..1528722 100644 --- a/README.md +++ b/README.md @@ -52,7 +52,7 @@ $ ./von-neumann -rmf example/array_sum.vnm * **`DIV `**, code: `1001`, operation: `AC = AC / OR` * **`AND `**, code: `1010`, operation: `AC = AC & OR` * **`OR `**, code: `1011`, operation: `AC = AC | OR` -* **`NOT `**, code: `1100`, operation: `AC = !OR` +* **`NOT `**, code: `1100`, operation: `AC = ~OR` * **`CMP `**, code: `1101`, operation: `AC == OR => AC = -1`,`AC != OR => AC = 0` * **`SHZ `**, code: `1110`, operation: `OR < 0 => AC >> |OR|`, `OR > 0 => AC << |OR|` * **`SHC `**, code: `1111`, circular shift left or right, depending on the sign of the operand diff --git a/include/machine.hpp b/include/machine.hpp index 2c3bf1b..7b526c0 100644 --- a/include/machine.hpp +++ b/include/machine.hpp @@ -65,7 +65,7 @@ class machine [ & ]() { accumulator = accumulator / operand_reg; }, [ & ]() { accumulator = accumulator & operand_reg; }, [ & ]() { accumulator = accumulator | operand_reg; }, - [ & ]() { accumulator = !operand_reg; }, + [ & ]() { accumulator = ~operand_reg; }, [ & ]() { accumulator = *accumulator == *operand_reg ? static_cast( -1 ) diff --git a/include/word.hpp b/include/word.hpp index 3c009e4..ca8e6f1 100644 --- a/include/word.hpp +++ b/include/word.hpp @@ -157,6 +157,11 @@ class word return tmp; } + constexpr auto operator~() const -> word + { + return word( get() ^ 0xFFFF ); + } + private: type word_ { 0 }; bool is_instruction_ { false }; // not sure if necessary diff --git a/test/word_test.cpp b/test/word_test.cpp index 1dfff14..0df4b0f 100644 --- a/test/word_test.cpp +++ b/test/word_test.cpp @@ -186,8 +186,7 @@ TEST_CASE( "word operators test", "[word]" ) SECTION( "negation" ) { - auto w { word::type { 0b0100'0100'0010'1110u } }; - REQUIRE( *( !word { w } ) == !w ); + REQUIRE( *( ~word { lhs } ) == word::type { 0b1111'1111'0000'0101u } ); } SECTION( "increment" )