Beginner assembly book suggestion?

Hallo!
I hope this is the right section to post my question :slight_smile: if I am wrong.. then sorry!! :disappointed_relieved:

I am very new to microcontrollers and so far I really like it :smiley: after some forum reading and a bit googling I got interested into assembly programming! There is quet a few books about assembly out there and I thought maybe some of you can recomend me something?!

Here is something you should know before sugesting :slight_smile: I have basic understanding of programming with C and C++.
I am not interedted into become a fulltime programmer, this is just a hobby.. so any book that gives quick results is more likely to keep me into this, then any hardcore "Assembly A-Z".
If you know any book that uses Arduino or Atmel in his examples, that would be awesome!!

Thanks :slight_smile:

Why?

I have basic understanding of programming with C and C++.

I'd concentrate on getting this to a level a good deal higher than "basic" before bothering with assembler.

This is due to the direct port access question?
You can do that in C and it will generate atomic access's in assembler..

You could download AVR Studio 4 (to 5-beta-2) from the Atmel site. I think it's free.

You will need an In Circuit Serial Programmer like Atmel's AVRISP mkII or the USBtiny ISP.

Then you can start learning AVR assembler. Start with the instruction set manual:

You won't need to memorize every instruction but you should try to get a feel for what instructions you have available.

EDIT: Oh, and read the AVR Assembler User's Guide:

@AWOL
I am not a programmer and I will never be... I just got interested into assembly language and wanna play around with it as long as I have fun.

@Senso
Not really.. the problem with the speed and stability got me interested into that, and I was surprised to see how much different the result can be, just by using different language. Learning about assembly is not much different then reading any book.. it not so much about learning assembly, its more about reading about something that I find fascinating :slight_smile:

@johnwasser
Thanks for getting this links for me :slight_smile: I will definitely look into that!
Still, as explained above, I am looking for a book.. something I can read in the sun and maybe later try at home :slight_smile:

Does anybody really use assembler anymore for complex programs?
It seems that its easier and cheaper to use higher language and compensate for the slow code with faster hardware...

It as jitter due to what the IDE arduino adds to your code when compiling, put one cli(); in setup() and see it the jitters doesnt go away, you can learn C and leave the bloated C++, but if you really want, then read this:
http://avrbeginners.net/

mortos360:
Does anybody really use assembler anymore for complex programs?
It seems that its easier and cheaper to use higher language and compensate for the slow code with faster hardware...

Even operating system kernels are, by and large, written in C these days. Ditto for the Arduino bootloader, where squeezing it into a tight space was a priority.

It is certainly interesting learning assembler, I wouldn't discourage it as a means of knowing more about how things work.

However these days it's not so much that you get slower code out of C. They wouldn't be using it to write kernels and device drivers if C wasn't compiled up pretty well. Modern C compilers do extensive optimization, quite possibly better than you or I might.

For example, by simply maintaining a table of what registers are in use and what aren't, a compiler can optimize away loading/storing variables into RAM, by remembering that a variable is already in register 22 (say). It also detects thing like calculations done inside loops that can be moved outside, can change multiplies into shifts, and so on.

I think the only time people use assembler these days is for highly time-critical code. And they may not be trying to save time either. For example, you might write:

for (i = 0; i < 200; i++)
  {
  int b = 0;
  }

The compiler might look at that and say "well that didn't achieve anything, he never used the variable b. I'll just optimize that away". But if some piece of hardware needs an exact time delay, optimizing things away might not be what you want.

As for C++ being bloated, well I think modern compilers are good at that too. For example a while back I compared sorting a vector of integers. One way was using the Quicksort supplied with standard C, and the other way was using the Standard Template Library (STL), using a vector container, and using the STL inbuilt sort.

The STL sort (which heavily used C++) was 3 times faster than the C version.

I guess you will need to know more then just assembler if you really wanna do this stuff for real. :grin:

So if I get this right, then nobody is buying assembler books since you get all you need online? :frowning:

To be perfectly honest, I doubt there is a big market for them.

Here is just the book you want, in PDF form:

Beginners Introduction to the Assembly Language of ATMEL-AVR-Microprocessors
by Gerhard Schmidt

http://www.avr-asm-download.de/beginner_en.pdf

Just print it out (78 pages) and take it with you or load it on a Kindle or other eBook reader.

re: the myth of hand-coded assembler vs. C. I fought this at my company, where we have traditionally used a proprietary, assembler-level language to program in. I took an example piece of code written in our source, re-coded it (expressing the logic as similarly as possible) in C and compiled (Visual Studio). When optimized for size, the C code compiled smaller, and still benchmarked faster. When optimized for speed, it was faster still, and only slightly larger.

There were people who had shunned C after looking at the resulting disassembly and noticing that every reference to a local var moved the var from the stack to a register and then back again. They hadn't even taken the time to understand the difference between a debug build and a release build.

johnwasser:
Here is just the book you want, in PDF form:

Beginners Introduction to the Assembly Language of ATMEL-AVR-Microprocessors
by Gerhard Schmidt

Nice book, thanks for the link. I stick to what I say about assembler not being a particularly faster or easier to use language. However the book is interesting, covers other stuff like interrupts, flash memory, ports etc. Very useful.

Probably the most useful reason for learning assembler is to understand the disassembly generated by:

avr-objdump -S some_file.elf

I look at those quite often to see whether the compiler did what I think it did (eg. optimizations). For example, in another thread today something worked that shouldn't have (access an array in progmem without using the progmem functions). But that was because of compiler optimizations.

@johnwasser
Thanks for the book!! :smiley:
Looks like exactly what i was looking for.

Also thanks to the rest of you who provided me some content!!