Assembler for AVR

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

Hello, I really hope I am not opening something already discussed.

I am looking for an assembler for AVR that could be ran on raspberry. I'd be fine with gnu binutils but avr-ld crashes when I use --oformat binary.

I want assembler because I like assembly. I don't want no IDE/studio because raspberry. I want binary output format because not every time I want to use tools like avrdude that can read hex to write my code/data, it's easier for me in binary. If you know about something please let me know, if not, no probs ;)

This topic has a solution.
Last Edited: Tue. Feb 20, 2018 - 10:45 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Why must you use -oformat binary?  Surely you can generate an .elf, and then avr-objcopy to -O binary.

"Experience is what enables you to recognise a mistake the second time you make it."

"Good judgement comes from experience.  Experience comes from bad judgement."

"Wisdom is always wont to arrive late, and to be a little approximate on first possession."

"When you hear hoofbeats, think horses, not unicorns."

"Fast.  Cheap.  Good.  Pick two."

"Read a lot.  Write a lot."

"We see a lot of arses on handlebars around here." - [J Ekdahl]

 

This reply has been marked as the solution. 
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

Aside from gnu binutils, TAVRASM and AVRA are two basic (atmel-compatible) command-line assemblers that I would not think would be a problem to get working on RPI.

 

What tools are you using that make use of the binary file format?  I usually don't find use for anything other than the .elf file, except for programming the target CPU...

 

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

Unfortunately avr-as generates relocation for references to all labels, so I cant use objcopy I would just get bogus code.

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

Hmm ok will try those out! Thanks.

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

> avr-ld crashes when I use --oformat binary
 

The recommended way is to build an .elf, and from that elf generate the needed binaries like .bin, .ihex, etc. using avr-objcopy. Also notice that there are programmers like avrdude that understand .elf so there is no need to convert to binary.
 

When you use avr-as, you'll get link-able object code. This can be linked+located using ld.
 
Also notice that it's way easier to use the avr-gcc driver program to assemble and link your code. For example, to get main.elf from your .S file is as easy as
 
avr-gcc -mmcu=atmega8 main.S -o main.elf
 
This will 1) call the C preprocessor on your asm input, 2) assemble the result to an object file, 3) adds library code as needed, start-up code and vector-table for ATmega8 and 4) links+locates the result to produce main.elf.

avrfreaks does not support Opera. Profile inactive.

Last Edited: Tue. Feb 20, 2018 - 09:21 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

Yup TAVRASM seems to be what I was looking for :) Thanks!

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

Unfortunately avr-as generates relocation for references to all labels, so I cant use objcopy I would just get bogus code.

Show us.

"Experience is what enables you to recognise a mistake the second time you make it."

"Good judgement comes from experience.  Experience comes from bad judgement."

"Wisdom is always wont to arrive late, and to be a little approximate on first possession."

"When you hear hoofbeats, think horses, not unicorns."

"Fast.  Cheap.  Good.  Pick two."

"Read a lot.  Write a lot."

"We see a lot of arses on handlebars around here." - [J Ekdahl]

 

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

> avr-as generates relocation for references to all labels, so I cant use objcopy I would just get bogus code.
 
Yes, of course. The assembler does NOT generate executable code but object files (with "placeholders" so that the code can be combined with other modules to compose complex projects or even combine assembly with C / C++ or pre-built library code).

avrfreaks does not support Opera. Profile inactive.

Last Edited: Tue. Feb 20, 2018 - 11:49 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Pyjong wrote:
avr-as generates relocation for references to all labels

and #6 tells you how to deal with that.

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0
C:\SysGCC\avr\bin>type foo.S
#include <avr/io.h>

        lds     r24, 0x4c
        lds     r25, 0x41
        lds     r26, 0x50

C:\SysGCC\avr\bin>avr-gcc -mmcu=atmega16 -nostartfiles foo.S -o foo.elf

C:\SysGCC\avr\bin>avr-objcopy -O binary -j .text foo.elf foo.bin

produces:

Exactly how simple do you want it anyway?

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

Ah I see.. you mean I can link into elf and THEN objcopy. Yeah I guess that works too :)

I'm still gonna go with tavrasm and have gnu as fallback, I like how simple that assembler is.

Thanks everyone!

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

Pyjong wrote:
. you mean I can link into elf and THEN objcopy. Yeah I guess that works too
What are you talking about? That is the way the tools are SUPPOSED to be used!