19
\$\begingroup\$

So I'm wanting to learn Assembly first on an MP, then move onto C (since it seems like that's what most of them use).

I'm wanting to get into Embedded Programming, I really love low level C stuff (Kernels/Modules for Linux is mainly what I've done), but I love the idea of being able to program even lower level than that (Microcontrollers/Microprocessors).

I know about Arduino, and that's great and all, but I can't find many resources for using Assembly with them. Atmel AVRs seem to be very popular (and cheap), but when it comes to the actual hardware portion (hooking them up on a breadboard, etc.), I'm not finding much information.

Any suggestions/information or resources that you guys/gals know about please let me know.

Edit: Another thing: It seems like all the Microprocessor books I read (Usually AVRs) talk about the microprocessor itself, and programming it. But I have yet to see a book that actually talks about installing all the components yourself (microprocessor, memory, power, etc.). If I could find something that walks me through that I'd be in business. (I want to learn from the ground up.) Not to mention I have no idea how you would communicate between them.

\$\endgroup\$
6
  • 3
    \$\begingroup\$ I hate to send you elsewhere, but if you're interested in AVRs you need to know about AVRfreaks.net. \$\endgroup\$ Commented Mar 30, 2011 at 19:16
  • \$\begingroup\$ Ya Im leaning towards AVR...mainly because theirs SO much info about them, and they are ALOT cheaper than the TI-MPS430... \$\endgroup\$
    – user3073
    Commented Mar 30, 2011 at 21:37
  • 2
    \$\begingroup\$ AVR is popular with hobbyists, but I'm not sure where you're getting your cost data. Both families have some offerings that are less than 1 USD and others pushing 20 USD. \$\endgroup\$ Commented Mar 30, 2011 at 22:12
  • 1
    \$\begingroup\$ My advice is don't pick MSP430 if you're a beginner. The official tools are good, but the free support you'll find online doesn't match up to PIC/AVR \$\endgroup\$ Commented Mar 31, 2011 at 9:01
  • 1
    \$\begingroup\$ This is ancient at this point, but it should be noted that Arduino is AVR. Arduino is just a development platform that uses the AVR hardware. \$\endgroup\$
    – sherrellbc
    Commented Jul 24, 2014 at 18:17

11 Answers 11

15
\$\begingroup\$

I learned on a 68HC11 in college. They are very simple to work with but honestly most low powered microcontrollers will be similar (AVR, 8051, PIC, MSP430). The biggest thing that will add complexity to ASM programming for microcontrollers is the number and type of supported memory addressing modes. You should avoid more complicated devices at first such as higher end ARM processors.

I'd probably recommend the MSP430 as a good starting point. Maybe write a program in C and learn by replacing various functions with inline assembly. Start simple, x + y = z, etc.

After you've replaced a function or algorithm with assembly, compare and contrast how you coded it and what the C compiler generated. This is probably one of the better ways to learn assembly in my opinion and at the same time learn about how a compiler works which is incredibly valuable as an embedded programmer. Just make sure you turn off optimizations in the C compiler at first or you'll likely be very confused by the compiler's generated code. Gradually turn on optimizations and note what the compiler does.

RISC vs CISC

RISC means 'Reduced Instruction Set Computing' it doesn't refer to a particular instruction set but just a design strategy that says that the CPU has a minimal instruction set. Few instructions that each do something basic. The is no stringently technical definition of what it takes 'to be RISC'. On the other hand CISC architectures have lots of instructions but each 'does more'.

The purposed advantages of RISC are that your CPU design needs fewer transistors which means less power usage (big for microcontrollers), cheaper to make and higher clock rates leading to greater performance. Lower power usage and cheaper manufacturing are generally true, greater performance hasn't really lived up to the goal as a result of design improvements in CISC architectures.

Almost all CPU cores are RISC or 'middle ground' designs today. Even with the most famous (or infamous) CISC architecture, x86. Modern x86 CPUs are internally RISC like cores with a decoder bolted on the front end that breaks down x86 instructions to multiple RISC like instructions. I think Intel calls these 'micro-ops'.

As to which (RISC vs CISC) is easier to learn in assembly, I think its a toss up. Doing something with a RISC instruction set generally requires more lines of assembly than doing the same thing with a CISC instruction set. On the other hand CISC instruction sets are more complicated to learn due to the greater number of available instructions.

Most of the reason CISC gets a bad name is that x86 is by and far the most common example and is a bit of a mess to work with. I think thats mostly a result of the x86 instructions set being very old and having been expanded half a dozen or more times while maintaining backward compatibility. Even your 4.5Ghz core i7 can run in 286 mode (and does at boot).

As for ARM being a RISC architecture, I'd consider that moderately debatable. Its certainly a load-store architecture. The base instruction set is RISC like, but in recent revisions the instruction set has grown quite a bit to the point where I'd personally consider it more of a middle ground between RISC and CISC. The thumb instructions set is really the most 'RISCish' of the ARM instruction sets.

\$\endgroup\$
9
  • \$\begingroup\$ @Mark - ARMs are also RISC processors, the instruction set isn't that bad. It's actually quite nicely designed; there are some instructions for userspace vs. kernelspace differentiation and other complexities, but those can be ignored while you're starting out. \$\endgroup\$ Commented Mar 30, 2011 at 19:21
  • 2
    \$\begingroup\$ @reemrevnivek I was more trying to steer him away from the complexities of dealing with multiple processor modes and MMUs as he started into ASM which why I mentioned higher end ARMs. The initialization and setup of higher end ARM SoCs is also substantially more complex than something like an AVR/PIC/MSP430. \$\endgroup\$
    – Mark
    Commented Mar 30, 2011 at 19:33
  • 1
    \$\begingroup\$ @sauron I added to my answer re:RISC vs CISC. \$\endgroup\$
    – Mark
    Commented Mar 30, 2011 at 21:49
  • 1
    \$\begingroup\$ @sauron they are RISC, i don't know of any CISC cores in microcontrollers. \$\endgroup\$
    – Mark
    Commented Mar 31, 2011 at 20:23
  • 1
    \$\begingroup\$ @Mark 8051s are CISC \$\endgroup\$
    – volting
    Commented Jul 4, 2011 at 19:01
9
\$\begingroup\$

I think 8 bits PIC microcontrollers are the best choice because of the reduced number of instructions.

The side effect of the reduced number of instructions is that you have to reinvent the wheel compared with other microcontrollers with more instructions.

But after learn with PIC, you can migrate to other microcontrollers and see whats fits better for you.

\$\endgroup\$
1
  • 1
    \$\begingroup\$ I wouldn't totally disagree as this is what I am exploring now, but 8, 16, and 32 bit cores have totally different asm strategies. \$\endgroup\$ Commented Feb 22, 2013 at 6:45
8
\$\begingroup\$

Similar to Mark's suggestion of the 68HC11, The instruction set of the Freescale 68HCS08 family is a slimmed-down version of the Motorola 6809, which I thought had one of the cleanest 8-bit instructions sets of its time. You can get a development board with switches, LED's, 3-axis accelerometer and piezo buzzer for $79 here.

\$\endgroup\$
4
  • \$\begingroup\$ The reduced number of registers the S08 has versus the HC11 can make things a little more difficult up front, as you'll need to figure out the stack do to much of anything (which was taught later in my lab with HC11s (or was it 12's)). By extension, AVRs are really nice because you have a whopping 32 registers to play with before worrying about the stack. \$\endgroup\$
    – Nick T
    Commented Mar 31, 2011 at 3:01
  • \$\begingroup\$ Actually I like the simplicity of the single accumulator, even though it can be a bottleneck. Instead of using the stack for temp variables, to start with I find it simpler to use the 144 bytes of direct page variables which are accessible with shorter instructions (the other 112 bytes of direct page are used for I/O registers). Using the stack (which allows for reentrant and recursive routines) can be learned later. \$\endgroup\$
    – tcrosley
    Commented Mar 31, 2011 at 5:15
  • \$\begingroup\$ Wasn't the HC(S)08 derived from the HC05? \$\endgroup\$
    – Johan.A
    Commented Aug 8, 2013 at 8:42
  • \$\begingroup\$ @Johan.A Yes, you are absolutely right. The HCS08 is an enhanced version of the HC05. I should have mentioned that. I think the derivation is something like 6800 -> 6801 -> 6805 -> HC(S)08. I wrote a lot of assembly code for the 6805. I compared the HCS08 to the 6809 to tie in with the other comments re the 68HC11 (which is roughly a microcontroller version of the 6809). \$\endgroup\$
    – tcrosley
    Commented Aug 8, 2013 at 14:41
5
\$\begingroup\$

The msp430 instruction set is a good one for learning assembler on. Avoid x86. Arm is another good one but has a lot more instructions and options and may not be best suited as a first instruction set. Thumb is a subset of the arm instruction set and not bad, on github I have both a thumb emulator (thumbulator) and an msp430 emulator (not tested as much as the thumb one) that are barebones, just the processor and memory and little more, so you can get good visibility into what is going on. An alternative would be qemu for example where the visibility is there but much harder to get at, likewise with a qemu like solution it takes a lot more work before you figure out if you have anything working.
goto mspgcc4.sf.net to build a toolchain, and/or a stock binutils (./configure --target=msp430 --prefix=/something) in combination with a stock llvm. Once you are ready for hardware an msp430 development board costs under 5 dollars. For arm/thumb tools just get the lite version from codesourcery. A cortex-m3 (thumb/thumb2) board is about 12 bucks right now. I would avoid x86 and avr and others as a first instruction set, you will want to learn others to be well rounded. The old/original pic instruction set is something worth looking at as well. You could write a simulator yourself in an afternoon for it as well as learn the assembler. I wouldnt learn it first necessarily, it does teach some interesting things, but at the same time doesnt scale and isnt necessarily representative of common features you find in most instruction sets. The msp430 gave me the feel of the pdp11 which is the first instruction set I really learned, both have well rounded, mostly orthogonal features. Both the msp430 and microchip pic instruction sets are documented at wikipedia, at least as a reference, to get the whole picture get the datasheets/manuals from the vendors which will describe each register and addressing mode, reset/boot, etc.

\$\endgroup\$
1
  • \$\begingroup\$ for assembler only you only need binutils, at least for arm/thumb or msp430, and you can build the assembler and linker. If you want a C compiler from which you can examine the assembler output as a learning tool, then you need mspgcc4 or codesourcery or just use llvm for both. \$\endgroup\$
    – old_timer
    Commented Mar 31, 2011 at 3:11
5
\$\begingroup\$

I too learned on a 68HC11 in college. Rather they suggest this over any other MPU/MCU, I just wanted to point out the the development board we used had a monitor program on it. So from a dumb terminal we could step through the code and examine the registers... I'd suggest when you know which processor fits your requirements you also check into what development boards are available with a monitor program.

\$\endgroup\$
3
  • \$\begingroup\$ The monitor program sounds like it'd be very helpful. What book did u use to learn this? if you mind me asking.... \$\endgroup\$
    – user3073
    Commented Mar 31, 2011 at 16:58
  • \$\begingroup\$ I too had experience with the 68HC11 and the "Monitoring Program" is known as the Buffalo Monitor. Basically, it's just a program that is stored in ROM that communicates serially to your PC. You type into a terminal and the program interprets your requests and gives you back information. You can dump memory to the screen, change memory values, step through instructions, etc. The board we used was this one. This controller is simple to learn with but is very dated. \$\endgroup\$
    – sherrellbc
    Commented Jul 24, 2014 at 18:25
  • \$\begingroup\$ ... The book we used was this if you are interested. I would suggest going with a more modern controller like AVR; their development board can be found here. \$\endgroup\$
    – sherrellbc
    Commented Jul 24, 2014 at 18:27
5
\$\begingroup\$

I teach both PIC (14-bit core) and ARM assembly. The PIC class I tell that once they have mastered the uglyness of that architecture they can take on anything else. The ARM (not the Thumb/Cortex!) is a very nice architecture to learn assembly. We use an LPC2148 board.


2019-12-29 update

I switched to Cortex, first to the LPC1114/820, later to the Arduino Due. The Arduino Due is cheap (from China), powerfull, can be used with C, C++, Assembler (and if you want Python), and if you realy want that you can use it with the Arduino IDE. I prefer my own build system and a free choice of an editor/IDE.

\$\endgroup\$
1
  • \$\begingroup\$ Hi Wouter, it's good to see you over here! \$\endgroup\$ Commented Jun 28, 2011 at 21:59
4
\$\begingroup\$

Are you sure you want to learn Assembly? Can you say why? It is quite a task, and is less and less relavent or useful now a days. This is from a person who has written in it and even hand assembled programs ( no assembler, linker, just a card with the instruction set ).

\$\endgroup\$
1
  • \$\begingroup\$ This isn't really an answer, as much as a comment. I'd also be hesitant to trust an embedded C programmer who was unwilling to trudge through bits of assembly now and then when trying to understand an oddity in the behavior of a project. \$\endgroup\$ Commented Sep 19, 2013 at 20:50
3
\$\begingroup\$

I learnt 16-bit PIC assembly with a dsPIC33F. The processor's assembly is quite C like, in that it supports pointers and three variable operations (A = B + C, for example), which makes learning and adapting to it much easier.

\$\endgroup\$
1
\$\begingroup\$

You are confusing microcontrollers and microprocessors here. AVR is a microcontroller line by Atmel, not a microprocessor. I suggest you first search on wikipedia to get a better understanding of what the differences are between these. Basically a microcontroller is a more or less complete system, whereas a microprocessor is only the cpu (hence a microcontroller has a microprocessor inside).

\$\endgroup\$
3
  • \$\begingroup\$ Ya I knew that, I dunno why i didn't put that. I meant like not many guides talk about actually connecting a MP and Memory (like flash or eeprom) etc... \$\endgroup\$
    – user3073
    Commented Mar 30, 2011 at 18:12
  • 2
    \$\begingroup\$ Since most microprocessors now have cache/memory and some I/O, it's a very blurry line. \$\endgroup\$
    – kenny
    Commented Mar 30, 2011 at 19:05
  • 1
    \$\begingroup\$ @Sauron - You sure you knew that? You used MP again; a microcontroller (which is the correct term for an AVR and 99% of the devices we discuss here) almost always has memory (both non-volatile, like EEPROM and Flash, and volatile SRAM) on-board. Learn to use the onboard stuff before you start venturing into peripherals. \$\endgroup\$ Commented Mar 30, 2011 at 19:19
1
\$\begingroup\$

At my university, we were taught hardware design/architecture alongside assembly language (the two go hand in hand, obviously) with the MIPS (or perhaps DLX) architecture. Since then, I've dabbled in PIC and AVR assembly a little bit at school/work, and they are all pretty similar. I think MIPS assembly was a great starting point, since the language is very simple, as is the processor architecture.

See also: this book. Not the best book in the world, but it's the standard computer design book for a lot of universities.

\$\endgroup\$
1
  • \$\begingroup\$ The Microchip PIC32 uses the MIPS architecture and it's fairly easy to mix MIPS assembler with C. \$\endgroup\$
    – tcrosley
    Commented Apr 16, 2016 at 22:35
0
\$\begingroup\$

my suggestion is any one who is going to start studying about microcontrollers and processors should read the book naming "code the hidden language of computer" if you study that almost you are expert with processors and for programming avr better use poney prog programmer and program from atmel studio6.1 from atmel official site

\$\endgroup\$
3
  • 1
    \$\begingroup\$ Please outline the key features of the book and the programmer, that would incline the OP to use exactly them. \$\endgroup\$
    – Vorac
    Commented Sep 19, 2013 at 15:00
  • \$\begingroup\$ it is about understanding a microcontroller how it is developed from digital systems and explains the assembly language \$\endgroup\$
    – avinash
    Commented Sep 27, 2013 at 3:14
  • \$\begingroup\$ go to this site j.mp/mpcinterest to get that book \$\endgroup\$
    – avinash
    Commented Sep 27, 2013 at 3:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.