Class: Tataru::Instructions::GotoIfInstruction
- Inherits:
-
ImmediateModeInstruction
- Object
- Tataru::Instruction
- ImmediateModeInstruction
- Tataru::Instructions::GotoIfInstruction
- Defined in:
- lib/tataru/instructions/goto_if_instruction.rb
Overview
goto if temp result is non zero
Instance Attribute Summary
Attributes inherited from Tataru::Instruction
Instance Method Summary collapse
Methods inherited from ImmediateModeInstruction
Methods inherited from Tataru::Instruction
Constructor Details
This class inherits a constructor from Tataru::Instructions::ImmediateModeInstruction
Instance Method Details
#label_branch! ⇒ Object
17 18 19 20 21 22 23 |
# File 'lib/tataru/instructions/goto_if_instruction.rb', line 17 def label_branch! unless memory.hash[:labels]&.key?(@param) raise "Label '#{@param}' not found" end memory.hash[:labels][@param] - 1 end |
#run ⇒ Object
7 8 9 10 11 12 13 14 15 |
# File 'lib/tataru/instructions/goto_if_instruction.rb', line 7 def run return if memory.hash[:temp][:result].zero? memory.program_counter = if @param.is_a? Integer @param - 1 else label_branch! end end |