How can ARM's MOV instruction work with a large number as the second operand?

前端 未结 7 2007
陌清茗
陌清茗 2020-12-28 17:23

I just begin to study ARM assembly language, and am not clear about how to use MOV to transfer an immediate number into a register.

From both the ARM reference manual

7条回答
  •  无人及你
    2020-12-28 17:42

    Remember that the ARM can perform a certain set of manipulations on the immediate value as part of the barrel shifter that is incorporated into the ARM's opcodes.

    This little article has one of the clearest explanations of some of the tricks that an ARM assembler can use to fit a large immediate number into the small available space of an ARM instruction:

    • http://www.davespace.co.uk/arm/introduction-to-arm/immediates.html

    The article discusses the trick likely used in your specific example of generating a MVN opcode to load the bitwise complement of the immediate value.

    These kinds of manipulation can't be done with all immediate values, but the ARM assemblers are supposedly pretty smart about it (and C compilers certainly are). If no shift/complement tricks can be performed, the value will generally be loaded from a PC-relative location or maybe by 'building up' the value from several instructions.

提交回复
热议问题