Inline Assembly help

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

Hi - I'm using Atmel Studio with a SAMD part, and I'm trying to put in a bit of inline assembly.  Here's what I'm trying to add:

 

__ASM(".set mivar, 0x1234");
extern int mivar;

 

I can't seem to get this to compile - it looks like it doesn't like the .set directive but I've tried several different variations and it chokes.

Any help would be appreciated.

Thanks,

Lee

Last Edited: Wed. Jan 17, 2018 - 07:49 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

You have posted this in the ASF forum - but what does this have to do with ASF?

 

Lee Draper wrote:
Here's what I'm trying to add:  

__ASM(".set mivar, 0x1234"); 

extern int mivar;

Why do you need inline assembler for that anyhow??

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

Why do you need inline assembler for that anyhow??

Indeed.  What is it you're trying to achieve with that line of code?

Greg Muth

Portland, OR, US

Atmel Studio 7.0 on Windows 10

Xplained/Pro/Mini Boards mostly

 

 

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

Sorry, I should have been a little more descriptive.  I've been trying to define and initialize a variable(s) to a location in Flash code space.  I'll be using this as a config space.  I'd like to do it completely within the C code if possible, without having to modify linker scripts etc.  

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

Lee Draper wrote:
I'd like to do it completely within the C code if possible, without having to modify linker scripts etc.  

Apart from it being difficult (IMO) that is also potentially dangerous. Since thr linker knows nothing about what you're doing in such a construct then it's possible that your code and the linker (script) could come into conflict.

 

I recommend going for the linker script solution:

  • Place your variable in a separate section
  • Set up that section in the linker script (this is where you set an address/range for it).

Why do you need to have your "config space" at a certain address? It would possibly make sense if it was in flash ROM, but a declared variable is (normally) in RAM.

 

If you want non-volatile storage to save configuration then perhaps have a look at the Non-Volatile Memory Controller chapter in the data sheet, and EEPROM Emulation in particular.

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

It's for a product that can be configured many different ways.  It's loaded with a default configuration, and later the .hex file is modified manually during assembly to reflect the different options.  It doesn't have to be a variable per say - I just need to be able to stuff default values into flash.  The values don't get changed during operation.  I can do this by modifying the linker script, but there are easier solutions with other compilers.  For example, here's one that works on an 8051 part:

__code __at (0x600) BYTE testvalue = 0x25;

I'm just trying to find out if something similar can be done within the C code space with the GNU compiler.  So far I haven't been able to find any directive that works like the __code__ directive above.

I do already use the NVM.

Thanks again - 

 

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

So, it is for non-volatile storage.

 

I'm still voting for the EEPROM emulation.

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]