rubyx/lib/asm/stack_builder.rb
2014-04-23 12:58:59 +03:00

46 lines
1.3 KiB
Ruby

module Asm
# ADDRESSING MODE 4
class StackBuilder
include Asm::InstructionTools
def initialize(pre_post, up_down, write, store_load)
@cond = 0b1110
@inst_class = Asm::Instruction::OPC_STACK
@pre_post_index = 0
@up_down = 0
@s = 0
@write_base = 0
@store_load = 0
@rn = 0
@operand = 0
@pre_post_index = pre_post
@up_down = up_down
@write_base = write
@store_load = store_load
end
attr_accessor :cond, :inst_class, :pre_post_index, :up_down,
:s, :write_base, :store_load, :rn, :operand
# Build representation for source value
def build_operand(arg)
if (arg.is_a?(Array))
@operand = 0
arg.each do |reg |
reg = reg_ref(reg)
@operand |= (1 << reg)
end
else
raise Asm::AssemblyError.new("invalid operand argument #{arg.inspect}")
end
end
def assemble(io, as)
val = operand | (rn << 16) | (store_load << 16+4) |
(write_base << 16+4+1) | (s << 16+4+1+1) | (up_down << 16+4+1+1+1) |
(pre_post_index << 16+4+1+1+1+1) | (inst_class << 16+4+1+1+1+1+2) |
(cond << 16+4+1+1+1+1+2+2)
io.write_uint32 val
end
end
end