Creating ASM modules for XC/C project in XDE?

Technical questions regarding the XTC tools and programming with XMOS.
Heater
Respected Member
Posts: 296
Joined: Thu Dec 10, 2009 10:33 pm

Creating ASM modules for XC/C project in XDE?

Post by Heater »

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?


User avatar
paul
XCore Addict
Posts: 169
Joined: Fri Jan 08, 2010 12:13 am

Post by paul »

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.
Heater
Respected Member
Posts: 296
Joined: Thu Dec 10, 2009 10:33 pm

Post by Heater »

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:

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)"
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.
richard
Respected Member
Posts: 318
Joined: Tue Dec 15, 2009 12:46 am

Post by richard »

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).
Heater
Respected Member
Posts: 296
Joined: Thu Dec 10, 2009 10:33 pm

Post by Heater »

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.