Class: Noofakku::Processor
- Inherits:
-
Object
- Object
- Noofakku::Processor
- Defined in:
- lib/noofakku/processor.rb
Instance Attribute Summary collapse
-
#data_pointer ⇒ Object
Returns the value of attribute data_pointer.
-
#instruction_pointer ⇒ Object
Returns the value of attribute instruction_pointer.
Instance Method Summary collapse
-
#initialize(instruction_to_handler) ⇒ Processor
constructor
A new instance of Processor.
- #run(program, memory, input, output) ⇒ Object
Constructor Details
#initialize(instruction_to_handler) ⇒ Processor
Returns a new instance of Processor.
7 8 9 10 11 |
# File 'lib/noofakku/processor.rb', line 7 def initialize(instruction_to_handler) raise "instruction_to_handler cannot be nil" unless instruction_to_handler != nil @instruction_to_handler = instruction_to_handler @instruction_pointer = @data_pointer = 0 end |
Instance Attribute Details
#data_pointer ⇒ Object
Returns the value of attribute data_pointer.
5 6 7 |
# File 'lib/noofakku/processor.rb', line 5 def data_pointer @data_pointer end |
#instruction_pointer ⇒ Object
Returns the value of attribute instruction_pointer.
5 6 7 |
# File 'lib/noofakku/processor.rb', line 5 def instruction_pointer @instruction_pointer end |
Instance Method Details
#run(program, memory, input, output) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/noofakku/processor.rb', line 13 def run(program, memory, input, output) raise "program cannot be nil" unless program != nil raise "memory cannot be nil" unless memory != nil raise "input cannot be nil" unless input != nil raise "output cannot be nil" unless output != nil while (0...program.length).include? @instruction_pointer instruction = @instruction_to_handler[program[@instruction_pointer]] instruction.perform(self, memory, program, input, output) @instruction_pointer += 1 end end |