rubyx/lib/asm/arm/instruction_tools.rb

25 lines
842 B
Ruby
Raw Normal View History

module Asm
module Arm
2014-04-16 11:45:36 +02:00
module InstructionTools
def reg_ref(arg)
2014-04-16 11:03:39 +02:00
if (not arg.is_a?(Asm::RegisterArgNode))
raise Asm::AssemblyError.new('argument must be a register', arg)
end
ref =
{'r0' => 0, 'r1' => 1, 'r2' => 2, 'r3' => 3, 'r4' => 4, 'r5' => 5,
'r6' => 6, 'r7' => 7, 'r8' => 8, 'r9' => 9, 'r10' => 10, 'r11' => 11,
'r12' => 12, 'r13' => 13, 'r14' => 14, 'r15' => 15, 'a1' => 0, 'a2' => 1,
'a3' => 2, 'a4' => 3, 'v1' => 4, 'v2' => 5, 'v3' => 6, 'v4' => 7, 'v5' => 8,
'v6' => 9, 'rfp' => 9, 'sl' => 10, 'fp' => 11, 'ip' => 12, 'sp' => 13,
'lr' => 14, 'pc' => 15}[arg.name.downcase]
if (not ref)
raise Asm::AssemblyError.new('unknown register %s' % arg.name.downcase, arg)
end
ref
end
end
end
end