8-bit AVR: single instruction to put a value of 1, ~1(-2/0xfe) or 4 into one of the registers not eligible for immediate operands (r0...r15)?

40 views Asked by At

With 8-bit AVR, immediate operands can be used with r16 to r32, including ldi r16, 4.

I want to control loops to run 4 and 8 times, respectively, and can't afford one more instruction for both for compatibility reasons, let alone a push/pop pair.

Is there a way to get a value of 1 or -2 (~1) into r0 with a single single-word instruction?
0 is easy enough: clr r0. With carry set, sbc r0, r0 gets -1.

Failing that, what about 4, 8, 16 to 31, 224 to 239?

Please include suggestions depending on carry flag set.

0

There are 0 answers