Class: Vm::Instructions::MemoryAccessOperations::ConstantOperation

Inherits:
Object
  • Object
show all
Defined in:
lib/hackasm/vm/instructions/memory_access_operations/constant_operation.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(index) ⇒ ConstantOperation

Returns a new instance of ConstantOperation.



8
9
10
# File 'lib/hackasm/vm/instructions/memory_access_operations/constant_operation.rb', line 8

def initialize(index)
  @index = index
end

Instance Attribute Details

#indexObject (readonly)

Returns the value of attribute index.



6
7
8
# File 'lib/hackasm/vm/instructions/memory_access_operations/constant_operation.rb', line 6

def index
  @index
end

Class Method Details

.segmentsObject



24
25
26
# File 'lib/hackasm/vm/instructions/memory_access_operations/constant_operation.rb', line 24

def self.segments
  %w[constant]
end

Instance Method Details

#to_asmObject



12
13
14
15
16
17
18
19
20
21
22
# File 'lib/hackasm/vm/instructions/memory_access_operations/constant_operation.rb', line 12

def to_asm
  %Q{
    @#{index}
    D=A
    @SP
    A=M
    M=D
    @SP
    M=M+1
  }.strip
end