ATTiny85 why won't adiw instruction work?

Go To Last Post
19 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I am setting a midpoint of a ADC read and watching the ADC to see if it goes above that midpoint. If so a 16 bit counter is incremented once. (Then I wait for a zero and exit blah, blah, blah.)
When I assembly it I get a error message at the adiw instruction "error: syntax error, unexpected INTEGER, expecting REGISTER or REGDEF". What does that mean and where am I screwing up?

;
IS_A_ONE:
	adiw r24:23,1		;increment the frequency counter
A_ONE_LOOP:
	rcall READ_ADC
	lds TEMP, 0x0064	;get stored MSD midpoint from RAM
	cp TEMP, LIMITH
	brsh A_ONE_LOOP		;wait for LIMITH to go below midpoint (=0)
	ret
;

BADBAUD

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

From the instruction set manual:

Quote:
ADIW Rd+1:Rd,K d ∈ {24,26,28,30}, 0 ≤ K ≤ 63

This indicates that the odd, high register is listed first (like r25:r24). This in turn means the instruction only works for certain pairings (25/24 and 27/26, but not 25/26).

whoops - it helps to actually read the thing. corrected error in which pairs are legal.

Chuck Baird

"I wish I were dumber so I could be more certain about my opinions. It looks fun." -- Scott Adams

http://www.cbaird.org

Last Edited: Tue. Jan 31, 2012 - 08:36 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Also a case of coder blindness. We all get that fromn time to time.

   adiw r24:r23,1      ;increment the frequency counter

Notice the "r" on the second register in the pair.

As of January 15, 2018, Site fix-up work has begun! Now do your part and report any bugs or deficiencies here

No guarantees, but if we don't report problems they won't get much of  a chance to be fixed! Details/discussions at link given just above.

 

"Some questions have no answers."[C Baird] "There comes a point where the spoon-feeding has to stop and the independent thinking has to start." [C Lawson] "There are always ways to disagree, without being disagreeable."[E Weddington] "Words represent concepts. Use the wrong words, communicate the wrong concept." [J Morin] "Persistence only goes so far if you set yourself up for failure." [Kartman]

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Good catch, eagle eye!

So, the legal forms for the first operand are
r31:r30, r29:r28, r27:r26, and r25:r24.

Chuck Baird

"I wish I were dumber so I could be more certain about my opinions. It looks fun." -- Scott Adams

http://www.cbaird.org

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

did not check, but is the instruction itself available in the AtTiny85?
At the end of the datasheet there is a overview of what instructions are available.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I have used this very same instruction in other ATTiny85 projects with no problem. Tried swapping register positions, tried removing the second "r". Still getting the same error. I am opening AVR studio 4 by double clicking on the .aps file, could this be causing it?

BADBAUD

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

[code] ADIW r24:r23,1

This version produces a different error message "invalid register".

BADBAUD

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:

When I assembly it I get a error message at the adiw instruction "error: syntax error, unexpected INTEGER, expecting REGISTER or REGDEF". What does that mean and where am I screwing up?

Just take a step back. Which line does the error message identify? Allthe focus is on the ADIW line but maybe it's one of the .equ's used in one of the other lines?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

badbaud wrote:

ADIW r24:r23,1

This version produces a different error message "invalid register".


Please read the first answer of Chuck more carefully,
ADIW can only operate with r25:r24, r27:r26, r29:r28 and r31:r30, but not with r24:r23.

/Martin.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Ok, I'm not using the Z pointer for anything so i can use 30 and 31 as general purpose registers?

BADBAUD

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

In asm you can use any of the 32 registers as you choose. That's one of the few advantages of Asm over C.

(though there are some rules that will affect selection such as LDI(etc.) only operating on R16..R31 and R0/R1 being trashed if you want to use MUL etc)

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:

ADIW can only operate with ...

Which makes this even more interesting:

Quote:

I have used this very same instruction in other ATTiny85 projects with no problem.

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

clawson wrote:
In asm you can use any of the 32 registers as you choose. That's one of the few advantages of Asm over C.

(though there are some rules that will affect selection such as LDI(etc.) only operating on R16..R31 and R0/R1 being trashed if you want to use MUL etc)

Carefull. we're trying to get the OP to use the correct register pair for the ADIW instruction, which will only use specific register pairs.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I'm always using a simplified ADIW syntax - adiw R24,1. R24/26/28/30 are valid for ADIW instruction, and yes TinyX5 supports it.

Warning: Grumpy Old Chuff. Reading this post may severely damage your mental health.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

@OP - as MBedder says, that's an alternate syntax. It still has the same restrictions in register pairs that are affected. So ADIW R24,1 generates the same opcode (and operates on the same registers) as ADIW R25:R24,1 but is another way to code it.

I know this may be obvious to some, but just so the point is clear.

That syntax is not listed in the AVR Instruction Set manual, at least the version I have handy. That's not to say that the AVR assembler won't accept it, although it may not. Other assemblers obviously do, since MBedder says it's his standard coding style. There are assembler differences that will come into play when talking about "legal" code styles.

Chuck Baird

"I wish I were dumber so I could be more certain about my opinions. It looks fun." -- Scott Adams

http://www.cbaird.org

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

And I from a recent thread believe that in avr-gcc assembly, the ADIW R24, 1 works, but the ADIW 25:24, 1 does not.

Regards,
Steve A.

The Board helps those that help themselves.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Since I use both AS (GCC) and AVRASM2 (Atmel), I always use a "simplified" syntax which works in both assemblers.

Warning: Grumpy Old Chuff. Reading this post may severely damage your mental health.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Koshchi wrote:
And I from a recent thread believe that in avr-gcc assembly, the ADIW R24, 1 works, but the ADIW 25:24, 1 does not.
For assembler with avr-as, register names like R24 can be specified in upper or lower case. Morever, avr-as supports plain 24 as register name:
adiw 24, 1

This is unambiguous because each operand flavour has it's own mnemonic, e.g. to move 1 into r24 you use LDI and not MOV. Moreover, avr-as allows simple expressions like

adiw 23+1, 1

This can be handy when writing compatibility macros to factor out instruction set differences:

.macro	wmov  r_dest, r_src
#if defined (__AVR_HAVE_MOVW__)
    movw \r_dest,   \r_src
#else
    mov \r_dest,    \r_src
    mov \r_dest+1,  \r_src+1
#endif
.endm

With that macro you can write

wmov 24, 22

for every AVR device. libgcc uses this, and there the 24 and 22 come from a macros, too, i.e. there are no hard coded register names (or register numbers) in the assembler code.

avrfreaks does not support Opera. Profile inactive.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thanks everybody, the additional info helps. I had used different register pairs in previous code projects and by happenstance had used a pair that was acceptable. This project uses all of the registers available plus some SRAM and the EEPROM.

BADBAUD