Class: Remian::Memory
- Inherits:
-
Object
- Object
- Remian::Memory
- Defined in:
- lib/remian/memory.rb
Instance Attribute Summary collapse
-
#size ⇒ Object
Returns the value of attribute size.
-
#store ⇒ Object
Returns the value of attribute store.
Instance Method Summary collapse
-
#initialize(size) ⇒ Memory
constructor
A new instance of Memory.
- #read(address) ⇒ Object
- #write(address, value) ⇒ Object
- #write_data(data) ⇒ Object
Constructor Details
#initialize(size) ⇒ Memory
Returns a new instance of Memory.
7 8 9 10 |
# File 'lib/remian/memory.rb', line 7 def initialize size @size = size @store = Array.new @size, "" end |
Instance Attribute Details
#size ⇒ Object
Returns the value of attribute size.
5 6 7 |
# File 'lib/remian/memory.rb', line 5 def size @size end |
#store ⇒ Object
Returns the value of attribute store.
5 6 7 |
# File 'lib/remian/memory.rb', line 5 def store @store end |
Instance Method Details
#read(address) ⇒ Object
12 13 14 15 |
# File 'lib/remian/memory.rb', line 12 def read address memory_key = convert_address_to_memory_key address @store[memory_key] end |
#write(address, value) ⇒ Object
17 18 19 20 21 22 |
# File 'lib/remian/memory.rb', line 17 def write address, value memory_key = convert_address_to_memory_key address if memory_key >= 0 && memory_key < @store.length @store[memory_key] = value end end |
#write_data(data) ⇒ Object
24 25 26 27 28 |
# File 'lib/remian/memory.rb', line 24 def write_data data data.split("\n").each_with_index do |instruction, i| write i + 1, instruction end end |