Sha256: 8b494f47acda15365cc05d527341de1f35cba001aaca2d28db3b4fd52d382c00

Contents?: true

Size: 506 Bytes

Versions: 1

Compression:

Stored size: 506 Bytes

Contents

module Assembler
  module Instructions
    class AddressInstruction
      def initialize(instruction, symbol_table)
        @instruction = instruction.compact.map { |key, value| [key, value.to_s] }.to_h
        @symbol_table = symbol_table
      end

      def to_b
        if memory_address = @instruction[:memory_address]
          memory_address.to_i
        elsif identifier = @instruction[:identifier]
          @symbol_table[identifier]
        end.to_s(2).rjust(16, '0')
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
hackasm-0.1.0 lib/hackasm/assembler/instructions/address_instruction.rb