Class: Vm::Instructions::ArithmeticOperations::UnaryOperation

Inherits:
Object
  • Object
show all
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

Class Method Summary collapse

Instance Method Summary collapse

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

#operationObject (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

.operationsObject



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_asmObject



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