Skip to content

Commit 651507b

Browse files
koostoshHubert Jaremko
authored andcommitted
NOT should be a bitwise negation, not logic
1 parent c6808d3 commit 651507b

4 files changed

Lines changed: 8 additions & 4 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ $ ./von-neumann -rmf example/array_sum.vnm
5252
* **`DIV `**, code: `1001`, operation: `AC = AC / OR`
5353
* **`AND `**, code: `1010`, operation: `AC = AC & OR`
5454
* **`OR `**, code: `1011`, operation: `AC = AC | OR`
55-
* **`NOT `**, code: `1100`, operation: `AC = !OR`
55+
* **`NOT `**, code: `1100`, operation: `AC = ~OR`
5656
* **`CMP `**, code: `1101`, operation: `AC == OR => AC = -1`,`AC != OR => AC = 0`
5757
* **`SHZ `**, code: `1110`, operation: `OR < 0 => AC >> |OR|`, `OR > 0 => AC << |OR|`
5858
* **`SHC `**, code: `1111`, circular shift left or right, depending on the sign of the operand

include/machine.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ class machine
6565
[ & ]() { accumulator = accumulator / operand_reg; },
6666
[ & ]() { accumulator = accumulator & operand_reg; },
6767
[ & ]() { accumulator = accumulator | operand_reg; },
68-
[ & ]() { accumulator = !operand_reg; },
68+
[ & ]() { accumulator = ~operand_reg; },
6969
[ & ]() {
7070
accumulator = *accumulator == *operand_reg
7171
? static_cast<word::type>( -1 )

include/word.hpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,11 @@ class word
157157
return tmp;
158158
}
159159

160+
constexpr auto operator~() const -> word
161+
{
162+
return word( get() ^ 0xFFFF );
163+
}
164+
160165
private:
161166
type word_ { 0 };
162167
bool is_instruction_ { false }; // not sure if necessary

test/word_test.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,8 +186,7 @@ TEST_CASE( "word operators test", "[word]" )
186186

187187
SECTION( "negation" )
188188
{
189-
auto w { word::type { 0b0100'0100'0010'1110u } };
190-
REQUIRE( *( !word { w } ) == !w );
189+
REQUIRE( *( ~word { lhs } ) == word::type { 0b1111'1111'0000'0101u } );
191190
}
192191

193192
SECTION( "increment" )

0 commit comments

Comments
 (0)