class Vm::Instructions::ArithmeticInstruction

Attributes

operation[R]

Public Class Methods

new(instruction) click to toggle source
# File lib/hackasm/vm/instructions/arithmetic_instruction.rb, line 10
def initialize(instruction)
  @operation = instruction[:operation].to_s
end

Public Instance Methods

comment() click to toggle source
# File lib/hackasm/vm/instructions/arithmetic_instruction.rb, line 25
def comment
  "// #{operation}\n"
end
to_asm() click to toggle source
# File lib/hackasm/vm/instructions/arithmetic_instruction.rb, line 14
def to_asm
  comment + case operation
  when *ArithmeticOperations::Comparison.operations
    ArithmeticOperations::Comparison.new(operation).to_asm
  when *ArithmeticOperations::UnaryOperation.operations
    ArithmeticOperations::UnaryOperation.new(operation).to_asm
  when *ArithmeticOperations::BinaryOperation.operations
    ArithmeticOperations::BinaryOperation.new(operation).to_asm
  end.split("\n").map(&:strip).join("\n")
end