Sha256: 8b7756c8b27aa4e2a0438f6ed20c2b9289c6236a5c2b2ea93976b0707151f3d3

Contents?: true

Size: 620 Bytes

Versions: 1

Compression:

Stored size: 620 Bytes

Contents

module Vm
  module Instructions
    module ArithmeticOperations
      class UnaryOperation
        OPERATION_TO_INSTRUCTION = {
          "neg" => "M=-M",
          "not" => "M=!M"
        }.freeze

        attr_reader :operation

        def initialize(operation)
          @operation = operation
        end

        def to_asm
          %Q{
          @SP
          M=M-1
          @SP
          A=M
          #{OPERATION_TO_INSTRUCTION[operation]}
          @SP
          M=M+1
          }.strip
        end

        def self.operations
          OPERATION_TO_INSTRUCTION.keys
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
hackasm-0.1.0 lib/hackasm/vm/instructions/arithmetic_operations/unary_operation.rb