> Could someone please send me a sample of how to call assembly code in
> C with passing in a variable x and returning a variable y. I have
> some assembly code that I need to call in my C program but I'm not
> sure how to do it. Also, how do you store arrays in assembly.
Hi Dewayne,
Just compile a C-function with the API form you want, eg.
int my_function(int val)
{
return 2*val;
}
and compile it to assembler, eg. gcc -S my_function.c.
Then copy the .s file and edit it to contain your code
(there's lots of assembler junk you can remove, you can
figure out whats safe to detlete by iteratively deleting
code and trying to build/link a program that uses the function).
The ARM Procedure Calling Standard (APCS) defines the
way arguments are passed to and from functions, so you
can search for that on the web.
> Also, how do you store arrays in assembly.
Can you explain? Why not pass a pointer and length to your
assembly code, eg.
int vector_sum(int *vec, int len);
then vec[] can be a statically allocated array,
stack array, malloc'ed array, etc.
Try not to use assembly code unless its for optimization.
DaveMessage
Re: [lpc2000] Assembly call in C
2006-05-16 by David Hawkins
Attachments
- No local attachments were found for this message.