Assigments

Technical questions regarding the XTC tools and programming with XMOS.
daleonpz
Member++
Posts: 26
Joined: Thu Nov 04, 2010 1:18 pm

Assigments

Post by daleonpz »

i cant understand some assigments such as:

= Assignment Binary right-to-left
+= -= *= /= Arithmetic assignment
%= &= ^= |= Arithmetic assignment
<<= >>= Arithmetic assignment

I am not pretty sure of what happen when you write:

count += 3;

it means that count is incrementing until it will be equal to 3?, if it's true, what happens when the assigment is for example *= or <<=.

I do really need some help with this, i'll highly appreciate it.


User avatar
lilltroll
XCore Expert
Posts: 956
Joined: Fri Dec 11, 2009 3:53 am
Location: Sweden, Eskilstuna

Post by lilltroll »

count += 3;

is

count = count+3;

In ANSI C it's possible to assign an operator that way.

To negate the value you can write:

count*=-1; e.g. count= -1 * count ;

Modulus:
count%=5; e.g. count = count%5;

It's even possible to write things as:
++count%=5;
Probably not the most confused programmer anymore on the XCORE forum.
User avatar
segher
XCore Expert
Posts: 844
Joined: Sun Jul 11, 2010 1:31 am

Post by segher »

lilltroll wrote:It's even possible to write things as:
++count%=5;
That's invalid, you're modifying the same object (namely count) more than once
without intervening sequence point.
daleonpz
Member++
Posts: 26
Joined: Thu Nov 04, 2010 1:18 pm

Post by daleonpz »

thank you.

now i have another question, what's the exactly mean of "@" in the code? I just know that you can only use @ with buffered ports.

for example in this case

Code: Select all

out buffered port:1 toggle = XS1_PORT_1B;
in port inClock = XS1_PORT_1C;
clock clk = XS1_CLKBLK_1;
int main(void) {
int count;
configure_clock_src(clk, inClock);
configure_out_port_no_ready(toggle, clk, 0);
start_clock(clk);
toggle <: 0 @ count; // read port counter
while (1) {
count += 3;
toggle @ count <: 1; // timed output
count += 2;
toggle @ count <: 0; // timed output
}
}
I've read that in general is:
p @ t <: x

I bet that the value of "p" will change to "x" when "t" cycles of clock will have passed. However, I didnt get the following sintaxis

toggle <: 0 @ count

what does it mean?.

sorry for being noob..xD
User avatar
Bianco
XCore Expert
Posts: 754
Joined: Thu Dec 10, 2009 6:56 pm

Post by Bianco »

toggle <: 0 @ count

Each port has a 16-bit timer.
The time at which the value 0 is assigned to port toggle is stored in the variable count.
User avatar
waluigi
Member++
Posts: 22
Joined: Sun Nov 07, 2010 6:33 pm

Post by waluigi »

lilltroll wrote:It's even possible to write things as:
++count%=5;
I like this one

u < 255 ?m[ u+1 ][v ]|=
4,m[u+1][ v]&48?W+1][v]&15]]):0:0;W][ v]& 15] ])

Courtesy of http://www.ioccc.org/main.html