We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
Hi,
i am working with c and assembly interworking. I am trying to pass the array from c to assembly, but i am getting the error. Please help me in finding the error. The code is as follows
#include <stdio.h>
#include<lpc214x.h>
#define size 5
void shift(int m, int arr[]);
main ()
{
int arr[]={1, 2, 3, 4, 5 };
shift(5, arr);
}
__inline void shift(int m, int arr[])
int a[5];
__asm
mov r2, #5
mov r0, arr
loop LDR a, [r0], #4
sub r2,#1
cmp r2, #0
BNE loop
Thanks and Regards
PVJ
hi prashant,
what is the error message that your are getting?
I think every thing is fine in your code except LDR a, [r0], #4 this instruction.
for LDR instruction the destination should be a variable like
int x;
ldr x,[r0],#4 is the correct way of usage...but in your code a is not normal variable it's pointer...
It's worth pointing out that it isn't recommended to use real register names in inline assembler. In the later versions of the compiler, the compiler will actually ignore them and reallocate them anyway. The correct practice in inline assembler, as Joseph has indicated above, is to declare int variables in the surrounding block and then use them. That works for variables but doesn't easily work for pointers. You need extra instructions to get the address of the array into a register before you can use it in a memory access instruction.
A good way to get a feel for how this kind of thing works would be to implement your routine in C, compile it and instruct the compiler to output assembler (rather than object code) which you can then view to see how the C compiler does it.
Chris