Class: Vm::Instructions::MemoryAccessOperations::StaticOperation
- Inherits:
-
Object
- Object
- Vm::Instructions::MemoryAccessOperations::StaticOperation
- Defined in:
- lib/hackasm/vm/instructions/memory_access_operations/static_operation.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.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(object_name, index) ⇒ StaticOperation
constructor
A new instance of StaticOperation.
- #to_asm ⇒ Object
Constructor Details
#initialize(object_name, index) ⇒ StaticOperation
Returns a new instance of StaticOperation.
8 9 10 11 |
# File 'lib/hackasm/vm/instructions/memory_access_operations/static_operation.rb', line 8 def initialize(object_name, index) @index = index @object_name = object_name end |
Instance Attribute Details
#index ⇒ Object (readonly)
Returns the value of attribute index.
6 7 8 |
# File 'lib/hackasm/vm/instructions/memory_access_operations/static_operation.rb', line 6 def index @index end |
#object_name ⇒ Object (readonly)
Returns the value of attribute object_name.
6 7 8 |
# File 'lib/hackasm/vm/instructions/memory_access_operations/static_operation.rb', line 6 def object_name @object_name end |
Class Method Details
.segments ⇒ Object
37 38 39 |
# File 'lib/hackasm/vm/instructions/memory_access_operations/static_operation.rb', line 37 def self.segments %w[static] end |
Instance Method Details
#to_asm ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/hackasm/vm/instructions/memory_access_operations/static_operation.rb', line 13 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 |