set cp?

Technical questions regarding the XTC tools and programming with XMOS.
MFlamer
Member++
Posts: 19
Joined: Wed Jan 14, 2015 2:17 am

set cp?

Post by MFlamer »

I apologize for bombarding this forum with what seem like silly questions, but I don't see alot of other conversations to follow on stackoverflow etc.

How do you set the cp register? A ldc instruction can only load a 16b literal, but any named symbol is going to have an address of more than 16b. It seems like the chicken before the egg problem. Is there an instruction to load a 32b constant at the pc and increment the pc (to skip the constant on the next fetch)? Thanks for being patient, I'll get up to speed pretty quick.....


MFlamer
Member++
Posts: 19
Joined: Wed Jan 14, 2015 2:17 am

Post by MFlamer »

OK, I get it. First, cp seems to get set automaticly to the section where I have my data anyway:

Code: Select all

.section .cp.rodata, "ac", @progbits
Second, I see that:

Code: Select all

ldap    r11,symb
will load a pc relative address up to 20b.
User avatar
segher
XCore Expert
Posts: 844
Joined: Sun Jul 11, 2010 1:31 am

Post by segher »

Right. And you can always play silly games like

Code: Select all

ldc r0,symb-0x10000
mkmsk r11,16
ladd r0,r11,r0,r11,r11
to load "symb" (in the range 0x10000..0x1ffff) into r11.
MFlamer
Member++
Posts: 19
Joined: Wed Jan 14, 2015 2:17 am

Post by MFlamer »

Cool, thanks.