rubyx/lib/risc/instructions/transfer.rb

36 lines
964 B
Ruby
Raw Normal View History

module Risc
2018-03-21 15:48:04 +05:30
# Transfer the constents of one register to another.
# possibly called move in some cpus
# There are other instructions to move data from / to memory, namely SlotToReg and RegToSlot
# Get/Set Slot move data around in vm objects, but transfer moves the objects (in the machine)
#
# Also it is used for moving temorary data
#
2018-03-21 15:48:04 +05:30
class Transfer < Instruction
# initialize with from and to registers.
# First argument from
2015-10-14 13:48:42 +03:00
# second argument to
#
2015-07-24 13:23:56 +03:00
# Note: this may be reversed from some assembler notations (also arm)
2018-03-21 15:48:04 +05:30
def initialize( source , from , to )
super(source)
2015-10-15 09:32:47 +03:00
@from = from
@to = to
raise "Fix me #{from}" unless from.is_a? RegisterValue
raise "Fix me #{to}" unless to.is_a? RegisterValue
end
attr_reader :from, :to
2015-07-24 13:23:56 +03:00
def to_s
2018-03-22 18:38:19 +02:00
class_source "#{from} -> #{to}"
2015-07-24 13:23:56 +03:00
end
2015-11-21 14:17:54 +02:00
end
2016-12-28 18:37:15 +02:00
def self.transfer( source , from , to)
2018-03-21 15:48:04 +05:30
Transfer.new( source , from , to)
end
end