2014-10-03 10:07:18 +02:00
|
|
|
module Register
|
2015-06-21 20:00:16 +02:00
|
|
|
|
|
|
|
# SetSlot moves data into memory from a register.
|
|
|
|
# GetSlot moves data into a register from memory.
|
|
|
|
# Both use a base memory (a register)
|
|
|
|
|
|
|
|
# This is because that is what cpu's can do. In programming terms this would be accessing
|
|
|
|
# an element in an array, in the case of SetSlot setting the register in the array.
|
|
|
|
|
|
|
|
# btw: to move data between registers, use RegisterTransfer
|
|
|
|
|
2016-12-11 13:06:09 +01:00
|
|
|
class SetSlot < Setter
|
2015-06-21 20:00:16 +02:00
|
|
|
|
|
|
|
# If you had a c array and index offset
|
|
|
|
# the instruction would do array[index] = register
|
2015-06-29 19:56:11 +02:00
|
|
|
# So SetSlot means the register (first argument) moves to the slot (array and index)
|
2016-12-11 13:06:09 +01:00
|
|
|
|
|
|
|
# def initialize source , register , array , index
|
|
|
|
# super
|
|
|
|
# end
|
|
|
|
# attr_accessor :register , :array , :index
|
|
|
|
|
2015-07-24 12:23:56 +02:00
|
|
|
def to_s
|
2015-07-25 08:30:58 +02:00
|
|
|
"SetSlot: #{register} -> #{array} [#{index}]"
|
2015-07-24 12:23:56 +02:00
|
|
|
end
|
|
|
|
|
2014-10-03 10:07:18 +02:00
|
|
|
end
|
2015-06-30 08:43:50 +02:00
|
|
|
|
|
|
|
# Produce a SetSlot instruction.
|
|
|
|
# From and to are registers or symbols that can be transformed to a register by resolve_to_register
|
|
|
|
# index resolves with resolve_index.
|
2015-07-27 11:13:39 +02:00
|
|
|
def self.set_slot source , from , to , index
|
2015-06-30 08:43:50 +02:00
|
|
|
from = resolve_to_register from
|
2015-07-27 11:13:39 +02:00
|
|
|
index = resolve_index( to , index)
|
2015-06-30 08:43:50 +02:00
|
|
|
to = resolve_to_register to
|
2015-07-27 11:13:39 +02:00
|
|
|
SetSlot.new( source, from , to , index)
|
2015-06-30 08:43:50 +02:00
|
|
|
end
|
|
|
|
|
2014-10-03 10:07:18 +02:00
|
|
|
end
|