[英]Array asm function in C
How do I return values of this array asm function in C? 如何在C中返回此数组asm函数的值? I'm not sure how to use sprintf in this case.
我不确定在这种情况下如何使用sprintf。
I need to show in the display some values before and after the array function. 我需要在显示中显示数组函数之前和之后的一些值。
//*****************************************************************************
//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 part of the code: 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.
It looks like you're unfamiliar with how to access array elements. 您似乎不熟悉如何访问数组元素。 Also, the result32 value is not being used, so no need to print it.
另外,由于没有使用result32值,因此无需打印它。 I think this is what you intended:
我认为这就是您的意图:
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]);
PS - I would recommend reading this book: 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 附注-我建议阅读这本书: 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 + C语言+编程+语言
The writing style is rather dry, but it helped me understand C 30 years ago and it's just as valid today. 写作风格相当枯燥,但是它在30年前帮助我理解了C,并且在今天仍然有效。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.