class AVR::Instruction

Attributes

args[R]
cpu[R]
mnemonic[R]
opcode[R]

Public Class Methods

new(cpu, mnemonic, args) click to toggle source
# 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

Public Instance Methods

args_to_s() click to toggle source
# 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() click to toggle source
# 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() click to toggle source
# File lib/avr/instruction.rb, line 57
def inspect
  "#<#{self.class.name} {#{self}}>"
end
to_s() click to toggle source
# File lib/avr/instruction.rb, line 50
def to_s
  return mnemonic.to_s if args.empty?

  "#{mnemonic} #{args_to_s}"
end
valid?() click to toggle source
# File lib/avr/instruction.rb, line 36
def valid?
  validate
  true
end
validate() click to toggle source
# File lib/avr/instruction.rb, line 31
def validate
  opcode.validate(args)
end