Load address of a label into a register (assembler)?

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

Hi guys,

First post, been lurking for a few months 8).

I've been experimenting with modifying exception.x in the INTC driver and I've hit a wall. I'm trying to load the address of a label into a register. Here's an example of one of my attempts:

_some_label:

.
.
ld.w rll,pc[_some_label-$]

Instead of loading the address of _some_label into r11 it loads the actual instruction bytes at that address. What's the syntax for doing this? I've done some googling but didn't come up with anything useful.

I'm using AVR32 Studio version 2.0.2 with the GNU toolchain and the target is an EVK1101.

Thanks in advance.

Letting the smoke out since 1978

 

 

 

 

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

The label is a constant, try to use MOV instruction instead:

MOV R11, LWRD(_some_label)
ORH R11, HWRD(_some_label)
(IAR compiler)

MOV R11, low(_some_label)
ORH R11, high(_some_label)
(other compiler??)

The reason for OR is because MOV doesn't support loading of 32bit constant, although MOV supports 32bit copy between registers.

The ld.w rll,pc[_some_label-$] will load the value PC is pointing to, plus the displacement within the brackets.

Common use for load with displacement is if you have the base address or a periperal (usart, spi etc), then use the displacement as an offset to specific registers in that device.

Read the instruction summary in the AVR32/UC3 architecture manual.

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

Thanks for the response. I had tried LWRD() and HWRD() prior to posting but the linker didn't like it. It didn't like low() or high() either so on a whim I tried lo() and hi() and lo and behold :lol: it worked! I've got my experiment working now that you pointed me in the right direction. Thanks!

Does anyone know where I can find a list of the assembler directives (is directives the right term here?) supported by AVR32 GCC asm?

Letting the smoke out since 1978

 

 

 

 

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

Thanks, but I've had that document since I started. It's an excellent reference on the avr32 instruction set. What I'm looking for is documentation on preprocessing directives (again, not sure if that's the right term) like lo() and hi(). Things like sizeof() in C but only for assembly.

Letting the smoke out since 1978

 

 

 

 

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

Ah, okay... I searched for such a documentation too. But I haven't found anything up to now...

s.zink