Finally I have a XC1 dev. board in hand, fired up the XDE and created/run some simple XC/C programs.
Now I want to add some functions written in assembler to my programs. I'd like to have my assembler code in its own module rather than use any kind of inline assembler. I would prefer to be able to do all this from within the XDE.
So the first question is, how?
Can anyone point to info could get me started down this road?
Creating ASM modules for XC/C project in XDE?
-
- Respected Member
- Posts: 296
- Joined: Thu Dec 10, 2009 10:33 pm
-
- XCore Addict
- Posts: 169
- Joined: Fri Jan 08, 2010 12:13 am
You can treat assembly exactly the same as a C or XC file (just it is a .S file!) - there shouldn't be any difference.
Paul
On two occasions I have been asked, 'Pray, Mr. Babbage, if you put into the machine wrong figures, will the right answers come out?' I am not able rightly to apprehend the kind of confusion of ideas that could provoke such a question.
On two occasions I have been asked, 'Pray, Mr. Babbage, if you put into the machine wrong figures, will the right answers come out?' I am not able rightly to apprehend the kind of confusion of ideas that could provoke such a question.
-
- Respected Member
- Posts: 296
- Joined: Thu Dec 10, 2009 10:33 pm
OK. Thank you Paul.
So I followed the time honoured technique of compiling some xc functions from the command line with the -S switch so as to be able to see how parameters are passed and results returned by xc.
This gives me the following assembler output for example:
Sure enough I can put that in an XC project as a .s file and everything builds and runs fine.
But holy moly, do I really need all those directives when I start creating my own assembler files? That's a lot of work to define a function or just an int.
So I followed the time honoured technique of compiling some xc functions from the command line with the -S switch so as to be able to see how parameters are passed and results returned by xc.
This gives me the following assembler output for example:
Code: Select all
.file "funcs_c_to_asm.s"
.text
.cc_top func_4.function,func_4
.globl func_4,"f{si}(si,si)"
.align 2
.type func_4,@function
func_4:
entsp 4
stw r0, sp[3]
stw r1, sp[2]
ldw r2, sp[3]
mul r2, r2, r1
stw r2, sp[0]
stw r2, sp[1]
.LBB5_1: # return
ldw r0, sp[1]
retsp 4
.cc_bottom func_4.function
.globl func_4.nstackwords
.linkset func_4.nstackwords,4
.globl func_4.maxthreads
.linkset func_4.maxthreads,1
.globl func_4.maxtimers
.linkset func_4.maxtimers,0
.globl func_4.maxchanends
.linkset func_4.maxchanends,0
.linkset func_4.locnochandec, 1
.linkset func_4.locnoside, 1
.section .dp.bss,"awd",@nobits
.cc_top x.data,x
.globl x,"si"
.align 4
.type x,@object
.size x,4
x:
.space 4
.cc_bottom x.data
.ident "GCC: (GNU) 4.2.1 (LLVM build) XMOS 10.4.2 (build 1752)"
But holy moly, do I really need all those directives when I start creating my own assembler files? That's a lot of work to define a function or just an int.
-
- Respected Member
- Posts: 318
- Joined: Tue Dec 15, 2009 12:46 am
You will need most of these directives. Section 21.2 (Assembly Programming for the XMOS ABI) of the Tools User Guide gives a brief overview of what is required (and why).
-
- Respected Member
- Posts: 296
- Joined: Thu Dec 10, 2009 10:33 pm
OK.
Luckily most of it is self explanatory.
I already found out that the linker or whoever will complain if it needs something that is missing. For example by adding threads to the code it complains that whateverFunction.nstackwords is not defined. Fair enough it needs to know that to build a stacks for the threads.
I just worry about having some directive missing (or wrong) that is going to cause the program to mysteriously fail at run time.
Now I can get on with exercising some instructions...
Thanks.
Luckily most of it is self explanatory.
I already found out that the linker or whoever will complain if it needs something that is missing. For example by adding threads to the code it complains that whateverFunction.nstackwords is not defined. Fair enough it needs to know that to build a stacks for the threads.
I just worry about having some directive missing (or wrong) that is going to cause the program to mysteriously fail at run time.
Now I can get on with exercising some instructions...
Thanks.