Inline assembly output problem

Technical questions regarding the XTC tools and programming with XMOS.
User avatar
YedongWeng
Member
Posts: 8
Joined: Mon Sep 03, 2012 3:40 pm

Inline assembly output problem

Post by YedongWeng »

Hi,
I want to output signal to "XS1_PORT_4F" by inline assembly.
The code as follows,and it's working.

Code: Select all

#include <xs1.h>

out port Led = XS1_PORT_4F;

int main(void)
{
	asm("out res[%0], %1"::"r"(XS1_PORT_4F),"r"(1));

	while(1);
	return 0;
}
And then,when i delete this line "out port Led = XS1_PORT_4F;",it's not working.
"out port Led = XS1_PORT_4F;" can be achieved by inline assembly?

Thanks in advance.


richard
Respected Member
Posts: 318
Joined: Tue Dec 15, 2009 12:46 am

Post by richard »

When you declare a port in XC as follows:
out port Led = XS1_PORT_4F;
The XC compiler does three things:

1) It creates a global called Led which is initialized with the resource ID XS1_PORT_4F.
2) It emits a constructor that configures the port at runtime before the start of main.
3) It emits a destructor that turns the port off after the program exits.

If you don't declare the port in XC you will need to do the configuration step (step 2) yourself. In this case the only configuration neccessary is to turn the port on. You can do this with the following assembly:

asm("setc res[%0], 0x8"::"r"(XS1_PORT_4F));

The various values you can give to the setc instruction are described in the XS1 Architecture manual