2014-10-03 10:07:18 +02:00
|
|
|
module Register
|
2015-06-21 20:00:16 +02:00
|
|
|
|
2016-12-25 17:05:39 +01:00
|
|
|
# SlotToReg moves data into a register from memory.
|
2016-12-25 17:02:39 +01:00
|
|
|
# RegToSlot moves data into memory from a register.
|
2015-06-21 20:00:16 +02:00
|
|
|
# Both use a base memory (a register)
|
|
|
|
|
|
|
|
# This is because that is what cpu's can do. In programming terms this would be accessing
|
2016-12-25 17:05:39 +01:00
|
|
|
# an element in an array, in the case of SlotToReg setting the value in the array.
|
2015-06-21 20:00:16 +02:00
|
|
|
|
|
|
|
# btw: to move data between registers, use RegisterTransfer
|
|
|
|
|
2016-12-25 17:05:39 +01:00
|
|
|
class SlotToReg < Getter
|
2015-06-21 20:00:16 +02:00
|
|
|
|
|
|
|
# If you had a c array and index offset
|
|
|
|
# the instruction would do register = array[index]
|
2015-10-13 16:30:39 +02:00
|
|
|
# The arguments are in the order that makes sense for the Instruction name
|
2016-12-25 17:05:39 +01:00
|
|
|
# So SlotToReg means the slot (array and index) moves to the register (last argument)
|
2016-12-11 13:12:35 +01:00
|
|
|
# def initialize source , array , index , register
|
|
|
|
# super
|
|
|
|
# end
|
|
|
|
# attr_accessor :array , :index , :register
|
2015-07-24 12:23:56 +02:00
|
|
|
|
2014-10-03 10:07:18 +02:00
|
|
|
end
|
2015-06-30 08:43:50 +02:00
|
|
|
|
2016-12-25 17:05:39 +01:00
|
|
|
# Produce a SlotToReg instruction.
|
2015-07-27 11:13:39 +02:00
|
|
|
# Array and to are registers or symbols that can be transformed to a register by resolve_to_register
|
2015-06-30 08:43:50 +02:00
|
|
|
# index resolves with resolve_index.
|
2016-12-25 17:05:39 +01:00
|
|
|
def self.slot_to_reg source , array , index , to
|
2015-07-27 11:13:39 +02:00
|
|
|
index = resolve_index( array , index)
|
|
|
|
array = resolve_to_register array
|
2015-06-30 08:43:50 +02:00
|
|
|
to = resolve_to_register to
|
2016-12-25 17:05:39 +01:00
|
|
|
SlotToReg.new( source , array , index , to)
|
2015-06-30 08:43:50 +02:00
|
|
|
end
|
2014-10-03 10:07:18 +02:00
|
|
|
end
|