assembly - ARMv7 模拟器的 internal_relocation 错误
问题描述
我正在尝试将下面的 c 代码翻译成程序集以进行分配
int sqrtIter(int a, int xi, int cnt, int k, int t)
{
for (int i=0; i<cnt; i++)
{
int step = ((xi*xi-a)*xi)>>k;
if (step > t)
step = t;
else if(step< -t)
step = -t;
xi = xi - step;
}
return xi;
}
int x = sqrtIter(168, 1, 100, 10, 2); // Output: 13
这是我的汇编代码
.global _start
a: .word 168
xi: .word 1
cnt: .word 100
k: .word 10
t: .word 2
x: .space 4
_start:
//use R0 for i set R0 to 0
MOV R0, #0
//load cnt into R1
LDR R1, =cnt
//use R2 for step int
LDR R2, #0
//load xi into R3
LDR R3, =xi
//load a into R4
LDR R4, =a
//load k into R5
LDR R5, =k
//load t into R6
LDR R6, =t
LOOP:
CMP R0, R1 //i-cnt
BGE END //branch to end if i>=n
//R7 for (xi*xi)(step is R7)
MUL R7, R3, R3
//reuse R7 to -a
SUB R7, R7, R4
//multiply by xi again
MUL R7, R7, R3
//right shift R7 by k
ASR R7, R7, R5
//if statement
CMP R7, R6
//if step >t step = t
MOVGT R7, R6
//else if step <-t step = -t
//R8 for negative t
MVN R8, R7
ADD R8, R8, #1
CMP R7, R8
MOVLT R7, R8
// xi = xi-step R3-R7
SUB R3, R3, R7
//i++
ADD R1, #1
B LOOP
END:
//store result to x
LDR R9, =x
STR R3, [R9]
但我收到此错误
组装:arm-altera-eabi-as -mfloat-abi=soft -march=armv7-a -mcpu=cortex-a9 -mfpu=neon-fp16 --gdwarf2 -o /tmp/asm02m1B8.so /tmp/asm02m1B8.s
/tmp/asm02m1B8.s:汇编程序消息:
/tmp/asm02m1B8.s:15:错误:internal_relocation(类型:OFFSET_IMM)未修复编译失败。
我不知道为什么?
解决方案
推荐阅读
- scala - 如何使用类名和函数名作为字符串调用 Scala 函数
- spring-boot - 使用 ITextRenderer 在 PDF 文件中渲染 Unicode (Hex) 字符
- python - 离散凸包
- android - React Native 中需要未知模块“499”错误
- c++ - 对象之前的预期')'。类没有命名类型
- python - Python 2.7:Access 数据库表和 CSV 文件比较
- javascript - 使用 HTML/Js 访问 SQL 数据库
- php - 在 Yii2 中使用 $_SERVER['SERVER_NAME'] 检测环境是否正确
- json - 在 laravel 5.6 中使用 json 从数据库中删除所需的带有 if 条件的 attr
- r - 你能帮我理解 GLM 模型中的 weights_column 参数,例如在 H2o 中吗?