Here are four examples using the teensy3.0 with the arduino IDE:
Why does the first work and why do all the other versions produce errors. I am mystified by this
puzzle. Is this a bug or just me missing the obvious.
I am leaning towards believing it is a bug. I would like to use the inline asm in a project
I am working on but currently I cannot get it to work reliably.
This compiles.
/////////////////////////////////////////////
void setup()
{
long testout = 0;
long testin = long(&CMP0_MUXCR);
Serial.print(String(testout)); //PRINT LINE A.
Serial.flush();
asm(
"ldr %[addro],=%[addrn] \n\t"
:[addro] "=r" (testout)
:[addrn] "r" (testin)
);
testout += 1;
}
void loop()
{
delay(100);
}
//////////////////////////////////////////////////
I add a line of code to write to serial and it fails.
This does not compile:
(fails with: "DELETEME.cpp.text.setup+0x48): undefined reference to `r1'"
/////////////////////////////////////////////
void setup()
{
Serial.begin(9600);
long testout = 0;
long testin = long(&CMP0_MUXCR);
Serial.print(String(testout)); //PRINT LINE A.
Serial.flush();
asm(
"ldr %[addro],=%[addrn] \n\t"
:[addro] "=r" (testout)
:[addrn] "r" (testin)
);
testout += 1;
Serial.print(String(testout)); //COPY OF PRINT LINE A.
}
void loop()
{
delay(100);
}
//////////////////////////////////////////////////
Here I remove all references to Serial and declare on variable as
volatile and it fails.
This also does not compile:
(Fails with: "DELETEME.cpp.text.setup+0x18): undefined reference to `r3'"
/////////////////////////////////////////////
void setup()
{
volatile long testout = 0; //NOW declared as volatile
long testin = long(&CMP0_MUXCR);
asm(
"ldr %[addro],=%[addrn] \n\t"
:[addro] "=r" (testout)
:[addrn] "r" (testin)
);
}
void loop()
{
delay(100);
}
//////////////////////////////////////////////////
Here we remove the output variable so it has input only,
and it fails. This last is the most bizarre instance.
This also does not compile:
(Fails with: "DELETEME.cpp.text.setup+0x14): undefined reference to `r3'"
/////////////////////////////////////////////
void setup()
{
long testin = long(&CMP0_MUXCR);
asm(
"ldr r1,=%[addrn] \n\t"
:
:[addrn] "r" (testin)
:"r1"
);
}
void loop()
{
delay(100);
}
//////////////////////////////////////////////////
Why does the first work and why do all the other versions produce errors. I am mystified by this
puzzle. Is this a bug or just me missing the obvious.
I am leaning towards believing it is a bug. I would like to use the inline asm in a project
I am working on but currently I cannot get it to work reliably.
This compiles.
/////////////////////////////////////////////
void setup()
{
long testout = 0;
long testin = long(&CMP0_MUXCR);
Serial.print(String(testout)); //PRINT LINE A.
Serial.flush();
asm(
"ldr %[addro],=%[addrn] \n\t"
:[addro] "=r" (testout)
:[addrn] "r" (testin)
);
testout += 1;
}
void loop()
{
delay(100);
}
//////////////////////////////////////////////////
I add a line of code to write to serial and it fails.
This does not compile:
(fails with: "DELETEME.cpp.text.setup+0x48): undefined reference to `r1'"
/////////////////////////////////////////////
void setup()
{
Serial.begin(9600);
long testout = 0;
long testin = long(&CMP0_MUXCR);
Serial.print(String(testout)); //PRINT LINE A.
Serial.flush();
asm(
"ldr %[addro],=%[addrn] \n\t"
:[addro] "=r" (testout)
:[addrn] "r" (testin)
);
testout += 1;
Serial.print(String(testout)); //COPY OF PRINT LINE A.
}
void loop()
{
delay(100);
}
//////////////////////////////////////////////////
Here I remove all references to Serial and declare on variable as
volatile and it fails.
This also does not compile:
(Fails with: "DELETEME.cpp.text.setup+0x18): undefined reference to `r3'"
/////////////////////////////////////////////
void setup()
{
volatile long testout = 0; //NOW declared as volatile
long testin = long(&CMP0_MUXCR);
asm(
"ldr %[addro],=%[addrn] \n\t"
:[addro] "=r" (testout)
:[addrn] "r" (testin)
);
}
void loop()
{
delay(100);
}
//////////////////////////////////////////////////
Here we remove the output variable so it has input only,
and it fails. This last is the most bizarre instance.
This also does not compile:
(Fails with: "DELETEME.cpp.text.setup+0x14): undefined reference to `r3'"
/////////////////////////////////////////////
void setup()
{
long testin = long(&CMP0_MUXCR);
asm(
"ldr r1,=%[addrn] \n\t"
:
:[addrn] "r" (testin)
:"r1"
);
}
void loop()
{
delay(100);
}
//////////////////////////////////////////////////