Class: Vm::Instructions::ArithmeticOperations::BinaryOperation
- Inherits:
-
Object
- Object
- Vm::Instructions::ArithmeticOperations::BinaryOperation
- Defined in:
- lib/hackasm/vm/instructions/arithmetic_operations/binary_operation.rb
Constant Summary collapse
- OPERATION_TO_INSTRUCTION =
{ "add" => "M=M+D", "sub" => "M=M-D", "and" => "M=M&D", "or" => "M=M|D", }.freeze
Instance Attribute Summary collapse
-
#operation ⇒ Object
readonly
Returns the value of attribute operation.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(operation) ⇒ BinaryOperation
constructor
A new instance of BinaryOperation.
- #to_asm ⇒ Object
Constructor Details
#initialize(operation) ⇒ BinaryOperation
Returns a new instance of BinaryOperation.
14 15 16 |
# File 'lib/hackasm/vm/instructions/arithmetic_operations/binary_operation.rb', line 14 def initialize(operation) @operation = operation end |
Instance Attribute Details
#operation ⇒ Object (readonly)
Returns the value of attribute operation.
12 13 14 |
# File 'lib/hackasm/vm/instructions/arithmetic_operations/binary_operation.rb', line 12 def operation @operation end |
Class Method Details
.operations ⇒ Object
35 36 37 |
# File 'lib/hackasm/vm/instructions/arithmetic_operations/binary_operation.rb', line 35 def self.operations OPERATION_TO_INSTRUCTION.keys end |
Instance Method Details
#to_asm ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/hackasm/vm/instructions/arithmetic_operations/binary_operation.rb', line 18 def to_asm %Q{ @SP M=M-1 @SP A=M D=M @SP M=M-1 @SP A=M #{instruction} @SP M=M+1 }.strip end |