Skip to content

Commit

Permalink
NOT should be a bitwise negation, not logic
Browse files Browse the repository at this point in the history
  • Loading branch information
koostosh authored and hjaremko committed Jan 6, 2022
1 parent c6808d3 commit 651507b
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 4 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion include/machine.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<word::type>( -1 )
Expand Down
5 changes: 5 additions & 0 deletions include/word.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions test/word_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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" )
Expand Down

0 comments on commit 651507b

Please sign in to comment.