ASM within C code in a PPC405 of VIRTEX II Pro

Jul 12, 2007 7 Replies

Hello,



I would like to know how to put ASM instructions in a C code.



With a G5 you can do that kind of functions:



asm long MyFunct(int a, int b, *pt) { fralloc



mr r6, a //r6 has a mr r7,b //r7 has b stbu r6,1(pt)



frfree blr }



Can I can the same thing in a PPC405 ?



Tanks !



You can use inline assembly with the tools provided by Xilinx since they are basically GCC. You have to use the GCC inline assembly format because inline assembly is compiler, not processor specific. Although, the assembly commands are processor specific. IBM DeveloperWorks has two good articles on assembly programming for the PowerPC family of processors. You can find the instruction set reference doc on both the Xilinx and IBM sites.

---Matthew Hicks

Ok ! If i want to call an ASM function with a C code, for example: in main.c:

int a=11; int b=12; int result;

result = add(a,b);

in add.asm:

*add(int a, int b)
  • r1 r2 add: addi r1,r2 mr r0,r1 blr

It works ? Tk !!!

When i try that, I have that kind of error messages:

Error: unsupported relocation against

buh ?

Where is the documentation that shows the details of the calling sequence between C and assy functions - I have never been able to find that. Stuff like how arguments are put into registers/stack, what registers must be preserved, etc.?

thanks,

-Jeff

I think this might be what you're looking for:

formatting link

(note it's generic PowerPC; it may reference stuff the embedded 405 doesn't support).

ken

This is a generic standard called the Application Binary Interface (ABI) that gcc holds to. You can read about this or find more links to other ABI references at IBM DeveloperWorks.

---Matthew Hicks

Thanks very much

I have another question:

I build my main in C code and I want to call a function in ASM.

In my C code, I put this: extern int Add(int a, int b); In my ASM: Add: #code

But when I compile, I have that error message: undefined reference to `Add'

To my mind, I miss something in the prologue of my assembly code.

That's right ?

Join the Discussion

Have something to add? Share your thoughts — no account required.

Didn't find your answer?

Ask the community — no account required