2014-04-14 17:09:56 +02:00
|
|
|
module Asm
|
|
|
|
module Arm
|
|
|
|
# ADDRESSING MODE 4
|
2014-04-20 23:07:33 +02:00
|
|
|
class StackBuilder
|
2014-04-14 20:52:16 +02:00
|
|
|
include Asm::Arm::InstructionTools
|
2014-04-14 17:09:56 +02:00
|
|
|
|
2014-04-20 23:07:33 +02:00
|
|
|
def initialize(pre_post, up_down, write, store_load)
|
2014-04-14 17:09:56 +02:00
|
|
|
@cond = 0b1110
|
2014-04-14 20:52:16 +02:00
|
|
|
@inst_class = Asm::Arm::Instruction::OPC_STACK
|
2014-04-14 17:09:56 +02:00
|
|
|
@pre_post_index = 0
|
|
|
|
@up_down = 0
|
|
|
|
@s = 0
|
|
|
|
@write_base = 0
|
|
|
|
@store_load = 0
|
|
|
|
@rn = 0
|
|
|
|
@operand = 0
|
2014-04-20 23:07:33 +02:00
|
|
|
@pre_post_index = pre_post
|
|
|
|
@up_down = up_down
|
|
|
|
@write_base = write
|
|
|
|
@store_load = store_load
|
2014-04-14 17:09:56 +02:00
|
|
|
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)
|
2014-04-20 22:48:04 +02:00
|
|
|
if (arg.is_a?(Array))
|
2014-04-14 17:09:56 +02:00
|
|
|
@operand = 0
|
2014-04-20 22:48:04 +02:00
|
|
|
arg.each do |sym , reg |
|
|
|
|
#allow an array of reg (strings), or the [:reg , name] produced by the instruction functions
|
|
|
|
reg = sym == :reg ? reg : sym
|
|
|
|
reg = reg_ref(reg)
|
2014-04-14 17:09:56 +02:00
|
|
|
@operand |= (1 << reg)
|
|
|
|
end
|
|
|
|
else
|
2014-04-20 22:48:04 +02:00
|
|
|
raise Asm::AssemblyError.new(Asm::ERRSTR_INVALID_ARG + " " + arg.inspect , arg)
|
2014-04-14 17:09:56 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-04-21 19:51:13 +02:00
|
|
|
def assemble(io, as)
|
2014-04-14 17:09:56 +02:00
|
|
|
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
|
|
|
|
end
|