c - C 中的数组 asm 函数

标签 c assembly arm

如何在 C 中返回此数组 asm 函数的值?我不确定在这种情况下如何使用 sprintf。

我需要在数组函数之前和之后显示一些值。

//*****************************************************************************
//FUNCTION: InitXa
//DESCRIPTION: array X of size N with a constant value V, using pointers:
//PARAMETERS: r0 = *X
//            r1 = Size N
//            r2 = Value V
//RETURN: None
//*****************************************************************************

// local register definitions
#define        rXA        r0        // register to hold address of X
#define        rN    r1    // register to hold value of N
#define        rV    r2    // register to hold value of V

__asm void InitXa (uint32 *X, uint32 N, uint32 V)
{
    STR rN, [rXA]     ; Store the value at first address of array.
    SUBS rV, #1       ; decrement the count 
loop
    STR rN,[rXA],#4   ; Store the value and increment the pointer
    SUBS rV,rV,#1     ; decrement the count
    BNE loop          ; branch until the count is 0
    BX lr             ; return to caller
}

C部分代码:

uint32 X = {10, 2, 3};
uint32 N = 10;
uint32 V = 3;
uint32 result32;

sprintf (str, "%d", result32);    //  **display the first few values of the array before     initialization on the top line of the OLED.**

InitXa (X, N, V); 

sprintf (str, "%d", result32); //**Use the second line to display values after** initialization.

最佳答案

您似乎不熟悉如何访问数组元素。另外,result32 值没有被使用,所以不需要打印它。我认为这就是您的意图:

printf("Before calling asm function: %d, %d, %d \n", X[0], X[1], X[2]);

InitXa (X, N, V); 

printf("After calling asm function: %d, %d, %d \n", X[0], X[1], X[2]);

附注- 我推荐阅读这本书: http://www.amazon.com/The-Programming-Language-Brian-Kernighan/dp/0131101633/ref=sr_1_2?ie=UTF8&qid=1391790669&sr=8-2&keywords=k%26r+the+c+programming+language

写作风格相当枯燥,但它帮助我在 30 年前理解 C,今天仍然有效。

关于c - C 中的数组 asm 函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21617305/

相关文章:

c++ - 从汇编程序写入返回值时发生意外页面错误

database - Berkeley DB Intel - ARM 可移植性

arm - 在 M0+ 设备上除以零异常

python - 使用 Pythons ctypes 从 libc 调用 uname

c - 如果位数大于 10,则不起作用

assembly - 有没有官方文件证明JL和JNGE的工作原理是一样的?

c - 为什么 GCC 使用 Mov 而不是 Push In 函数调用?

更改虚拟页面权限

python - 为脚本设置临时环境变量

arm - ARM Cortex-A8 流水线是 13 级还是 14 级?