File tree 2 files changed +10
-5
lines changed
2 files changed +10
-5
lines changed Original file line number Diff line number Diff line change @@ -198,9 +198,10 @@ def initialize(op, *operands)
198
198
199
199
def opcode
200
200
return {
201
- :complement => "101" ,
202
- :add => "010" ,
203
- :subtract => "110" } [ @op ]
201
+ :complement => "011" ,
202
+ :and => "001" ,
203
+ :add => "100" ,
204
+ :subtract => "101" } [ @op ]
204
205
end
205
206
end
206
207
@@ -312,6 +313,10 @@ def add(operand1, operand2)
312
313
Computer ::ALUOperation . new ( :add , operand1 , operand2 )
313
314
end
314
315
316
+ def bitwise_and ( operand1 , operand2 )
317
+ Computer ::ALUOperation . new ( :and , operand1 , operand2 )
318
+ end
319
+
315
320
def subtract ( operand1 , operand2 )
316
321
Computer ::ALUOperation . new ( :subtract , operand1 , operand2 )
317
322
end
Original file line number Diff line number Diff line change 22
22
end
23
23
24
24
computer . instruction "add" do |i |
25
- i . move :MA , :IR
25
+ i . move :MA , bitwise_and ( :IR , 0x0F )
26
26
i . move :A , add ( :A , :MD )
27
27
end
28
28
42
42
end
43
43
44
44
computer . instruction "jmp" do |i |
45
- i . move :pc , :IR
45
+ i . move :pc , bitwise_and ( :IR , 0x0F )
46
46
end
47
47
end
You can’t perform that action at this time.
0 commit comments