代码之家  ›  专栏  ›  技术社区  ›  HaggarTheHorrible

armassembly:如何在armassembly函数中传递和使用指针数组

  •  0
  • HaggarTheHorrible  · 技术社区  · 15 年前

    但是,我不知道如何从汇编函数中的指针数组中提取四个单独的指针。我的尝试失败了。

    这是我想做的一个例子。

    #include<stdio.h>
    
    void  _my_arm_asm(float32_t *);
    
    float32_t data_array[100][100];
    
    void main()
    {
           float32_t *ptr1, *ptr2, *ptr3, *ptr4;
    
            ptr1 = \\ data_array[value] + (some value);
            ptr2 = \\ data_array[value] + (some other value);
            ptr3 = \\ data_array[value] + (some other value);
            ptr4 = \\ data_array[value] + (some other value);
    
           float32_t *array_pointers[4];
           array_pointers[0] = ptr1;
           array_pointers[1] = ptr2;
           array_pointers[2] = ptr3;
           array_pointers[3] = ptr4;
    
           float32x4_t result;
    
           _my_arm_asm(array_pointers, &result);
    
            ....
            ....
            ....
           return 0;
    
    
    }
    
    
    
    .text
        .global _my_arm_asm
    
    _my_arm_asm:
                #r0: Pointer to my array of pointers
                #r1: Pointer to my result
    
            push   {r4-r11, lr}
    
            # How to access the array of pointers?
    
            # I previously tried this, is this the right way to do it?
    
            # mov r4, #0
            # vld4.32 {d0, d1, d2, d3}, [r0, r4]
            # add r4, r4, #1
            # vld4.32 {d4, d5, d6, d7}, [r0, r4] 
            # add r4, r4, #1
            # vld4.32 {d8, d9, d10, d11}, [r0, r4] 
            # add r4, r4, #1
            # vld4.32 {d12, d13, d14, d15}, [r0, r4] 
    
    
            ....
            ....
            ....
    
            pop    {r4-r11, pc}
    
    2 回复  |  直到 15 年前
        1
  •  4
  •   Michael Burr    15 年前

    通常,如果传递给函数的参数超过4个,则多余的参数将传递给堆栈。

    “ARM体系结构的过程调用标准”的第5章(基本过程调用标准)应该有确切的细节。表面上看它相当复杂(因为有很多关于对齐方式、参数大小等的细节),但我认为出于您的目的,它归结为函数get的第5个参数被推到了堆栈上。

    当然,正如您在问题中所建议的,您可以通过将4个指针打包到一个结构中并传递一个指向该结构的指针来避免所有这些—在您的汇编例程中,您只需将该结构指针加载到一个寄存器中,然后使用它来依次加载真正需要的指针。

    我认为手臂组件可能看起来像:

                     // r0 has the 1st parameter
    ldr r4, [r0]     // get array_pointers[0] into r4
    // ...
    
    ldr r5, [r0, #4] // get array_pointers[1] into r5
    // ...
    
    ldr r6, [r0, #8] // get array_pointers[2] into r6
    

        2
  •  3
  •   Igor Skochinsky    15 年前

    第五个和更多的参数(假设int大小的参数)在堆栈上传递。即,第五个参数可访问为[SP],第六个参数可访问为[SP,#4],依此类推。阅读 Procedure Call Standard for the ARM Architecture 详细的解释。
    也就是说,你不必使用汇编来利用霓虹灯。退房 NEON intrinsics 它允许您使用纯C代码执行所有操作。

    推荐文章