gas vs. the AVR instruction set

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

The AVR designers, observing that you don't need to have both "add immediate" AND "subtract immediate" instructions, because you can always just use a negative value with one to get the effect of the other, opted for the most awkward choice. I'm all for showing off, but it doesn't seem that the gnu tools are playing at the same level.

The following code fragment seems to be a fairly straightforward part of an attempt to add the base address of an array to an integer index:

subi r30, lo8(-Leds)

,but avr gcc complains:

../ledRefresh.s:253: Error: can't resolve `0' {.bss section} - `Leds' {.bss section}

I've tried the few other obvious variants, and they all lead to the same response. Is there a way to get the negative of a symbol with the gnu tools?

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

What happens if you omit the - (minus) sign?

JW

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

Well, of course, if I omit the minus sign, the compiler stops complaining. But it doesn't perform the desired action. The "Leds" symbol in the example mapped to 0x102 in the AVR's address space, and a "subi r30, lo8(Leds)" instruction comes out as "subi r30, 2".

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

I was testing whether you defined the Leds symbol at all... ;-) Sorry.

The following did assemble:

  .text
  subi r30, lo8(-(Leds)) 
  .section .bss
Leds:
  .skip 1,0

This is how gcc does it, too - putting the address into brackets. Don't ask me, why. (Ask those who think the GNU documentation is adequate).

JW

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

Levenkay wrote:
Is there a way to get the negative of a symbol with the gnu tools?
The variation below works as well. I have a vague recollection of seeing this form in assembly code generated by gcc.
subi r30, lo8(0-Leds)

Don Kinzer
ZBasic Microcontrollers
http://www.zbasic.net

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

Belated thanks for the advice; the "lo8(-(addrSymbol))" form worked well!