Class: AVR::Instruction
- Inherits:
-
Object
- Object
- AVR::Instruction
- Extended by:
- T::Sig
- Defined in:
- lib/avr/instruction.rb
Instance Attribute Summary collapse
-
#args ⇒ Object
readonly
Returns the value of attribute args.
-
#cpu ⇒ Object
readonly
Returns the value of attribute cpu.
-
#mnemonic ⇒ Object
readonly
Returns the value of attribute mnemonic.
-
#opcode ⇒ Object
readonly
Returns the value of attribute opcode.
Instance Method Summary collapse
- #args_to_s ⇒ Object
- #execute ⇒ Object
-
#initialize(cpu, mnemonic, args) ⇒ Instruction
constructor
A new instance of Instruction.
- #inspect ⇒ Object
- #to_s ⇒ Object
- #valid? ⇒ Boolean
- #validate ⇒ Object
Constructor Details
#initialize(cpu, mnemonic, args) ⇒ Instruction
Returns a new instance of Instruction.
21 22 23 24 25 26 27 28 |
# File 'lib/avr/instruction.rb', line 21 def initialize(cpu, mnemonic, args) raise "Unknown opcode #{mnemonic}" unless Opcode.opcodes.include?(mnemonic) @cpu = cpu @mnemonic = mnemonic @args = args @opcode = T.let(Opcode.opcodes.fetch(mnemonic), Opcode) end |
Instance Attribute Details
#args ⇒ Object (readonly)
Returns the value of attribute args.
15 16 17 |
# File 'lib/avr/instruction.rb', line 15 def args @args end |
#cpu ⇒ Object (readonly)
Returns the value of attribute cpu.
9 10 11 |
# File 'lib/avr/instruction.rb', line 9 def cpu @cpu end |
#mnemonic ⇒ Object (readonly)
Returns the value of attribute mnemonic.
12 13 14 |
# File 'lib/avr/instruction.rb', line 12 def mnemonic @mnemonic end |
#opcode ⇒ Object (readonly)
Returns the value of attribute opcode.
18 19 20 |
# File 'lib/avr/instruction.rb', line 18 def opcode @opcode end |
Instance Method Details
#args_to_s ⇒ Object
42 43 44 45 46 47 |
# File 'lib/avr/instruction.rb', line 42 def args_to_s #return args.join(', ') unless opcode return nil if opcode.arg_types.empty? opcode.format_args(args).join(', ') end |
#execute ⇒ Object
62 63 64 65 66 67 68 69 70 |
# File 'lib/avr/instruction.rb', line 62 def execute raise 'Invalid instruction' unless valid? cpu.next_pc = cpu.pc + 1 opcode.execute(cpu, nil, args) cpu.pc = cpu.next_pc nil end |
#inspect ⇒ Object
57 58 59 |
# File 'lib/avr/instruction.rb', line 57 def inspect "#<#{self.class.name} {#{self}}>" end |
#to_s ⇒ Object
50 51 52 53 54 |
# File 'lib/avr/instruction.rb', line 50 def to_s return mnemonic.to_s if args.empty? "#{mnemonic} #{args_to_s}" end |
#valid? ⇒ Boolean
36 37 38 39 |
# File 'lib/avr/instruction.rb', line 36 def valid? validate true end |
#validate ⇒ Object
31 32 33 |
# File 'lib/avr/instruction.rb', line 31 def validate opcode.validate(args) end |