AVR-AS question

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

If I have a symbol in my code like this:

motor_stepping:
.byte 0x08, 0x04, 0x02, 0x01

How do I tell the assembler that I want to stick its address into X? I can't find an opcode to do this and there seems to be no documentation whatsoever on avr-as. Thanks.

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

subsonix wrote:
How do I tell the assembler that I want to stick its address into X?

ldi r26, lo8(motor_stepping)
ldi r27, hi8(motor_stepping)

You could also create a macro:

.macro ldx _var
  ldi  r26, lo8(\_var)
  ldi  r27, hi8(\_var)
.endm

Then, it could be used thusly:

  ldx  motor_stepping

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

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

Thanks, it works! Where is this documented? I'd love to RTFM but I can't find it :(

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

subsonix wrote:
Where is this documented?

See section 9.5.4 of avr-libc-user-manual.pdf. With 32-bit quantities, the operators are hhi8() and hlo8() are useful for extracting the bytes of the high word. You may be able to find documentation for these by searching the Internet.

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

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

Same documentation online at:

http://www.nongnu.org/avr-libc/u...

(see bottom of page)

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

Actually, it doesn't work.

This is what the assembler puts out:

B0E0 LDI R27, hi8(motor_stepping)
A0E0 LDI R26, lo8(motor_stepping)

If I'm not mistaken, those opcodes store zeroes and my label is not at zero.

I'm trying to put the value stored there out on PORTB. Is this correct?

LD R17, X
OUT PORTB, R17

Thanks again.

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

OK, here's my updated and still broken code:

move_motor:
 LDI R31, hi8(motor_stepping)
 LDI R30, lo8(motor_stepping)
 INC R30
 LD R19, Z
 OUT PORTB, R19
RET

motor_stepping:
.byte 0x40, 0x40, 0x20, 0x10


check_tach:
 RET

What I want it to do is fetch 0x40 from the table and put it on PORTB. I noticed that in the binary code, the assembler claims it's writing 0xE0E0, but in reality, 0x02E1 is in its place. Is the linker doing this? I put the INC R30 there as a debugging measure. Presumably, if R30 is being written in the line above with a constant value, R30 should end up being that value +1, but instead, I get constantly changing values on PORTB, as if nothing was being written to R30 at all.

On another note, are there any decent assemblers for linux that use Atmel's syntax? I downloaded tavrasm, but it doesn't support the new generation of AVRs. I also tried avra, but it doesn't produce binaries.

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

subsonix wrote:
What I want it to do is fetch 0x40 from the table and put it on PORTB.
Since the data table is in Flash, not RAM, you need to use LPM to read data from it rather than LD.

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

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

I tried LD, LPM, LDS and the result is still the same.

Quote:
LDI R31, hi8(pm(motor_stepping))
LDI R30, lo8(pm(motor_stepping))

doesn't work.

Quote:

LDI R31, hi8(motor_stepping)
LDI R30, lo8(motor_stepping)

doesn't either.

What I was saying in my other post is that these two lines do not seem to move ANY value into R30 or R31, because when I increment R30 and put it on the port, it's a constantly increasing value. These two LDI commands seem to do nothing.

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

> If I'm not mistaken, those opcodes store zeroes and
> my label is not at zero.

Wait: let me guess... you've only feeding us pieces of a large
puzzle, but my crystal ball just tells me that you were trying
to use the relocatable object file, rather than passing it through
the linker.

Jörg Wunsch

Please don't send me PMs, use email if you want to approach me personally.