Sha256: c0530fec87b391cd2870362a94cb18e199f53857d6514b83cd4c2a7f592ea5f1

Contents?: true

Size: 806 Bytes

Versions: 1

Compression:

Stored size: 806 Bytes

Contents

module Vm
  module Instructions
    module MemoryAccessOperations
      class StaticOperation

        attr_reader :object_name, :index

        def initialize(object_name, index)
          @index = index
          @object_name = object_name
        end

        def to_asm
          if operation == "push"
            %Q{
              @#{object_name}.#{index}
              D=M
              @SP
              A=M
              M=D
              @SP
              M=M+1
            }.strip
          else
            %Q{
              @SP
              M=M-1
              @SP
              A=M
              D=M
              @#{object_name}.#{index}
              M=D
            }.strip
          end
        end

        def self.segments
          %w[static]
        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/memory_access_operations/static_operation.rb