ARM Immediate Values的导入方法

You can’t fit an arbitrary 32-bit value into a 32-bit instruction word. ARM data processing instructions have 12 bits of space for values in their instruction word. This is arranged as a four-bit rotate value and an eight-bit immediate value:

Immediate values.

The 4-bit rotate value stored in bits 11-8 is multiplied by two giving a range of 0-30 in steps of two.

Using this scheme we can express immediate constants such as:

  • 0x000000FF
  • 0x00000FF0
  • 0xFF000000
  • 0xF000000F

But immediate constants such as:

  • 0x000001FE
  • 0xF000F000
  • 0x55550000

...are not possible.

An assembler will convert big values to the rotated form. Impossible values will cause an error.

Some assemblers will use other tricks such as using MVN instead of MOV to form the bitwise complement of the required constant. For example the impossible instruction MOV r0,#0xFFFFFFFF could be assembled as MVN r0,#0.

Remarks

The impact of this is that some constants are “ARM friendly”. Some are not. Study of the numbers you’re using can sometimes reveal scope for optimisation.

Loading Wide Values

You can form constants wider than those available in a single instruction by using a sequence of instructions to build up the constant. For example:

MOV r2, #0x55           ; R2 = 0x00000055
ORR r2, r2, r2, LSL #8  ; R2 = 0x00005555
ORR r2, r2, r2, LSL #16 ; R2 = 0x55555555

...or load the value from memory:

LDR r2, =0x55555555

The pseudo-instruction LDR Rx,=const tries to form the constant in a single instruction, if possible, otherwise it will generate an LDR.

LTORG用于声明一个数据缓冲池,(也称为文字池)的开始。在使用伪指令LDR时,常常需要在适当的地方加入LTORG声明数据缓冲池,LDR加载的数据暂时放于数据缓冲池。

语法 LTORG

使用说明:

当程序中使用LDR之类的指令时,数据缓冲池的使用可能越界。为防止越界发生,可使用LTONG伪操作定义数据缓冲池。通常大的代码段可以使用多个数据缓冲池。ARM汇编编译器一般把数据缓冲池放在代码段的最后面,即下一代码段开始之前,或者END伪操作之前。LTORG伪操作通常放在无条件跳转指令之后,或者子程序返回指令之后,这样处理器就不会错误的将数据缓冲池中的数据当作指令来执行。

    LDR伪指令在汇编时,如果立即数可以用<shifter_operand>表示的话就替换为MOV或MVN指令;如果不能用其表示则需要将该立即数放到一个文字池中,并生成一条将该文字池内容加载到目标寄存器的LDR指令。而使用LDR指令必须保证文字池在其可以访问的地址范围之内,对于ARM指令集来说就是4KB,所以必须在LDR指令前后4KB的范围内用LTORG显式地在代码段中添加一个文字池。

LTORG是在此指令出现的地方放一个文本池(literal pool). 在ARM汇编中常用到

    ldr   r0, =instruction     将地址instruction载入r0.

此时编译器将ldr尽可能的转变成mov或mvn指令。

如果转变不成, 将产生一个ldr指令, 通过pc相对地址从一块保存常数的内存区读出instruction的值。此内存区既是文本池。一般的, 文本池放在END指令之后的地方。但是, 如果偏移地址大于4k空间, ldr指令会出错(因为ldr的相对偏移地址为12-bit的值). 此时使用LTORG放到会出错的ldr指令附近, 以解决此问题。编译器会收集没有分配的ldr的值放到此文本池中。


  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值