output on serial monitor:
x = 03 01 03
x = 04 01 02
x = 05 01 01
x = 06 01 00
x = 07 01 01 // counthigh = 1 when it's supposed to be 8, the "adiw %2, 7" has no effect
x = 08 01 00
...
I think you need to use +w (counthigh)to get it to know that it's a 16bit value.
I'm not sure what will happen with +r there; I actually get correct output when running your code on an Uno:
x = 03 01 03
x = 04 01 02
x = 05 01 01
x = 06 01 00
x = 07 01 08
Well what you're seeing is just a snippet from out of a larger program where I'm having to create a soft pwm and i need higher frequency than I can get using delaymicroseconds.
Yep. the object code looks OK too.
But since we're in the realm of undefined behavior, it's not horribly surprising that a 16u2 would behave differently. (I don't have a 16u2 core to test with, though.)
ok this is really strange. i compiled again and now it is working with the adiw instruction. Don't really know what's up, but i think i had a typo where there was a "clobber" register in the code that wasn't required. But i can't be sure.
Anyway, THANX i got it goin now.
With things like link-time optimization, I'd somewhat expect the exact behavior of an incorrect width asm argument specifier (+r vs +w) to change (perhaps randomly) depending on what registers were "in use" by the code that the linker ends up in-lining "near" the asm code.
and now i get:
"C:\Users\User\AppData\Local\Temp\cceV29QE.s: Assembler messages:
C:\Users\User\AppData\Local\Temp\cceV29QE.s:1538: Error: register r24, r26, r28 or r30 required"