Class: Vm::Instructions::MemoryAccessInstruction
- Inherits:
-
Object
- Object
- Vm::Instructions::MemoryAccessInstruction
- Defined in:
- lib/hackasm/vm/instructions/memory_access_instruction.rb
Instance Attribute Summary collapse
-
#index ⇒ Object
readonly
Returns the value of attribute index.
-
#object_name ⇒ Object
readonly
Returns the value of attribute object_name.
-
#operation ⇒ Object
readonly
Returns the value of attribute operation.
-
#segment ⇒ Object
readonly
Returns the value of attribute segment.
Instance Method Summary collapse
- #comment ⇒ Object
-
#initialize(instruction, object_name) ⇒ MemoryAccessInstruction
constructor
A new instance of MemoryAccessInstruction.
- #to_asm ⇒ Object
Constructor Details
#initialize(instruction, object_name) ⇒ MemoryAccessInstruction
Returns a new instance of MemoryAccessInstruction.
11 12 13 14 15 16 |
# File 'lib/hackasm/vm/instructions/memory_access_instruction.rb', line 11 def initialize(instruction, object_name) @segment = instruction[:segment].to_s @operation = instruction[:operation].to_s @index = instruction[:index].to_s @object_name = object_name end |
Instance Attribute Details
#index ⇒ Object (readonly)
Returns the value of attribute index.
9 10 11 |
# File 'lib/hackasm/vm/instructions/memory_access_instruction.rb', line 9 def index @index end |
#object_name ⇒ Object (readonly)
Returns the value of attribute object_name.
9 10 11 |
# File 'lib/hackasm/vm/instructions/memory_access_instruction.rb', line 9 def object_name @object_name end |
#operation ⇒ Object (readonly)
Returns the value of attribute operation.
9 10 11 |
# File 'lib/hackasm/vm/instructions/memory_access_instruction.rb', line 9 def operation @operation end |
#segment ⇒ Object (readonly)
Returns the value of attribute segment.
9 10 11 |
# File 'lib/hackasm/vm/instructions/memory_access_instruction.rb', line 9 def segment @segment end |
Instance Method Details
#comment ⇒ Object
31 32 33 |
# File 'lib/hackasm/vm/instructions/memory_access_instruction.rb', line 31 def comment "// #{operation} #{segment} #{index}\n" end |
#to_asm ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/hackasm/vm/instructions/memory_access_instruction.rb', line 18 def to_asm comment + case segment when *MemoryAccessOperations::ConstantOperation.segments MemoryAccessOperations::ConstantOperation.new(index).to_asm when *MemoryAccessOperations::StaticOperation.segments MemoryAccessOperations::StaticOperation.new(index, object_name).to_asm when *MemoryAccessOperations::VirtualSegmentOperation.segments MemoryAccessOperations::VirtualSegmentOperation.new(operation, segment, index).to_asm when *MemoryAccessOperations::FixedSegmentOperation.segments MemoryAccessOperations::FixedSegmentOperation.new(operation, segment, index).to_asm end.split("\n").map(&:strip).join("\n") end |