首页 > 解决方案 > 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)未修复编译失败。

我不知道为什么?

标签: assemblyarm

解决方案


推荐阅读