修正后无效不变? [英] Invalid constant after fixup?

查看:125
本文介绍了修正后无效不变?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于某些原因,当我尝试编译code这一点,编译器说 syscall.s:72:修正后无效常数(0x172)

For some reason, when I try to compile this bit of code, the compiler says syscall.s:72:invalid constant (0x172) after fixup:

.globl _mach_msg_trap$MACH
_mach_msg_trap$MACH:
    stmfd sp!, {r4,r7}
    mov r7, #370 /* this is line 72 */
    svc 0
    ldmfd sp!, {r4, r7}
    bx lr

我不知道为什么它这样做。当我把小恒进 R7 ,它工作正常。但具有较高的数字,它吐出这个错误。做我的临时固定它 MOV R7,#300 添加R7,#70 ,达到所需的影响。仍然不知道,虽然导致了错误。

I don't know why it's doing it. When I put a smaller constant into r7, it works fine. But with higher numbers, it spits out this error. I've temporary fixed it by doing mov r7, #300 and add r7, #70, which achieves the desired effect. Still not sure what caused the error though.

推荐答案

ARM指令只能够装载立即值的有限范围内MOV。问题是,该值必须连接在mov指令本身$ C $光盘。由于所有的ARM指令都是32位宽,原指令集最多的ARMv5一共只有8 + 4位不得不EN code立即数。与第一个8位,能够加载任何8位值INT在0-255的范围,4位是右旋转的2 30 0至步骤

The ARM Instruction is only able to load a limited range of immediate values with mov. The problem is that the value has to be encoded in the mov instruction itself. As all ARM Instructions are 32-bit wide, the original instruction-set up to ARMv5 only had a total of 8+4 bits to encode immediates. With the first 8-bit being able to load any 8-bit value int in the range of 0-255 and the 4 bit being a right rotate in steps of 2 between 0 and 30.

所以,你可以加载像值:

So you can load values like:

#0
#122
#121 ror #24 = 30976
#230 ror #12 = 241172480

不过,#370没有与此方案可加载,它需要像#185 ROR#31 这是不可能的。

有两种方法可以让你立即值加载。

There are two ways to get your immediate value loaded.


  1. 你怎么已经在多个步骤构建价值解决它。

  2. 将与LDR从内存中加载值: LDR R7,=#370 然后汇编器会创建一个常量池和负载从那里通过PC相对值寻址。

  1. How you already solved it by constructing the value in multiple steps.
  2. By loading the value from memory with ldr: ldr r7,=#370 The assembler then will create a constant-pool and load the value from there via pc-relative addressing.

通常你应该preFER构建常数高达2指示,如果多数民众赞成不可能(或值必须重新定位)使用LDR。

Usually you should prefer to construct constants with up to 2 instructions, if thats not possible (or the value has to be relocatable) use ldr.

与ARMv7的开始,你也可以使用 MOVW 来在寄存器的下半部分加载任何16位的值,而归零上半部和 MOVT 来加载其他16位值的上半部分不接触的下半部分。

Starting with ARMv7 you can also use movw to load any 16 bit value in the lower half of a register while zeroing the top-half and movt to load another 16bit value to the upper half without touching the lower half.

这篇关于修正后无效不变?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆