Class: Vm::Instructions::ArithmeticOperations::UnaryOperation
- Inherits:
-
Object
- Object
- Vm::Instructions::ArithmeticOperations::UnaryOperation
- Defined in:
- lib/hackasm/vm/instructions/arithmetic_operations/unary_operation.rb
Constant Summary collapse
- OPERATION_TO_INSTRUCTION =
{ "neg" => "M=-M", "not" => "M=!M" }.freeze
Instance Attribute Summary collapse
-
#operation ⇒ Object
readonly
Returns the value of attribute operation.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(operation) ⇒ UnaryOperation
constructor
A new instance of UnaryOperation.
- #to_asm ⇒ Object
Constructor Details
#initialize(operation) ⇒ UnaryOperation
Returns a new instance of UnaryOperation.
12 13 14 |
# File 'lib/hackasm/vm/instructions/arithmetic_operations/unary_operation.rb', line 12 def initialize(operation) @operation = operation end |
Instance Attribute Details
#operation ⇒ Object (readonly)
Returns the value of attribute operation.
10 11 12 |
# File 'lib/hackasm/vm/instructions/arithmetic_operations/unary_operation.rb', line 10 def operation @operation end |
Class Method Details
.operations ⇒ Object
28 29 30 |
# File 'lib/hackasm/vm/instructions/arithmetic_operations/unary_operation.rb', line 28 def self.operations OPERATION_TO_INSTRUCTION.keys end |
Instance Method Details
#to_asm ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/hackasm/vm/instructions/arithmetic_operations/unary_operation.rb', line 16 def to_asm %Q{ @SP M=M-1 @SP A=M #{OPERATION_TO_INSTRUCTION[operation]} @SP M=M+1 }.strip end |