class Vm::Instructions::MemoryAccessOperations::FixedSegmentOperation
Constants
- FIXED_SEGMENT_TO_START_INDEX
Attributes
index[R]
operation[R]
segment[R]
Public Class Methods
new(operation, segment, index)
click to toggle source
# File lib/hackasm/vm/instructions/memory_access_operations/fixed_segment_operation.rb, line 12 def initialize(operation, segment, index) @operation = operation @segment = segment @index = index end
segments()
click to toggle source
# File lib/hackasm/vm/instructions/memory_access_operations/fixed_segment_operation.rb, line 56 def self.segments FIXED_SEGMENT_TO_START_INDEX.keys end
Public Instance Methods
to_asm()
click to toggle source
# File lib/hackasm/vm/instructions/memory_access_operations/fixed_segment_operation.rb, line 18 def to_asm if operation == "push" %Q{ @#{index} D=A @#{FIXED_SEGMENT_TO_START_INDEX[segment]} A=A+D D=M @SP A=M M=D @SP M=M+1 }.strip else %Q{ @SP M=M-1 @SP A=M D=M @R14 M=D @#{index} D=A @#{FIXED_SEGMENT_TO_START_INDEX[segment]} D=A+D @R15 M=D @R14 D=M @R15 A=M M=D }.strip end end