Let's Make Robots!

Programming AVR in Assembly or Machine Language

The question I'm going to ask you is a very simple one- How can I program (AVR in general) my Atmega 328P in Machine or Assembly Language? I know it is possible as all microcontrollers, no matter which language they are running convert high level language to low level languages and utimately Machine language. That's the job of the compiler. I want to run assembly or machine language because-

  1. It is relatively new for me. I have done programming in C and hope it repeat my success in Arduino language as well but I also want to learn assembly or machine in my quest to get a deeper understanding of computer systems and what better medium to learn it for than my favorite microprocessor.
  2. I have heard that it is tad faster. However, that applies to computers but maybe I may find something to make my code faster in this domain. For example- say the person who coded a for loop for AVR would have done his coding in machine or assembly. If I am able to get that coding and I know either machine or assembly, I may be able to find bugs in his code and make it faster. This is what hacking was in its original form and this is what I want to do.
  3. The outcomes of this job are relatively infinte and out of my scope to mention them here.

That's why I request the LMR community to help me and bombard me with information please!! :)

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
kingart3's picture

Good luck with your assembly language programming Vishu.

I spent 12 years once working in assembly on a project.  When you first start, you thing that you MUST be doing something wrong, because it seems to take a lot more lines of code.  In general I think its about 10 lines of assembly to every 1 line of a higher level language.  Programmers seem to average about 1 mistake every 10 lines of code ...so.... you usually make 10x more mistakes in assembly language.

That said it can be a bit faster, but is well worth learning, since you come away with a much better understanding of what the computer and the compiler are doing.

Good luck and have fun, let us know what you think of assembly language.

bdk6's picture

For all things AVR the Atmel website is your friend.  While there, download Atlem Studio.  It is a complete IDE for the AVR chips as well as the Atmel ARM chips.  Quite nice and powerful.  It has an assembler and simulator and debugger.  You can test your code without loading it into a real chip.  Also has a C compiler.  You will also want to download the datasheet for the chip you are using (ATMega 328?).  It has all the relevant information including a list of the assembly language instructions.  They also have a document that lists all the assembly language instructions in detail.  Get that too.  They have TONS of application notes with lots of example code in assembly language.  The datasheet is like 300 pages, but don't worry.  Mostly you can read the parts of interest at the moment.  Start with the part near the front that describes the AVR architecture.  As always, start simple:  blink an LED.  Then go from there.  Be patient.  Assembly is often tedious, but it is incredibly powerful and fun.  AVR assembly is MUCH nicer than most to use.  It is a good one to start with.  avrfreaks.net is a good resource, but they often aren't friendly to newbies.

Maxhirez's picture
You might be interested in this: http://arduino.cc/forum/index.php/topic,37130.msg274496.html#msg274496 What are you using as an ISP now?
birdmun's picture

a simple search will tell you as much as any of us can.