8
votes

I've got a decent amount of programming experience but it is all in high level languages. I recently picked up C and that project went really well and the learning experience was well worth it.

Now I want to take that one step further and learn assembly language but ideally I'd like to learn on an embedded platform as that's where I see some of my future projects lying. The question is, which is the best starting point or 'kit' for a beginner?

I'm looking for something that's reasonably easy to put together, can do 'real world' things and generally provide a good foundation that can be built on.

5

5 Answers

2
votes

AVR is not the best instruction set. I would save it for a second or third instruction set. But eventually you may end up there as the arduino is incredibly popular and has good support through the community (although asm is exception not the rule in that world).

right now you can get a msp430 board for $4.30, basically TI is eating the cost to give these things away. msp430 is a good instruction set to learn.

The armmite pro is not a bad, arduino sized, board but uses an arm instead of avr. arm and thumb are good instruction sets.

There are emulators for pretty much everything, if or if not, writing an emulator is a very good way to learn how things work. If nothing else I normally recommend writing a disassembler.

Also an instruction set with a C compiler is good in that you can write some C code, play with the optimization, and see what kind of assembler is output, and learn different things about assembler. At first learn some tricks for efficiency and performance, later you will be able to outperform the compiler, or at least be on par. all of the ones mentioned have some sort of C compiler, avr and msp have ways to get gcc working, arm and thumb are supported by the mainline compilers. Llvm is automatically a cross compiler so you do not have to compile a compiler to get started, the msp430 backend to llvm is experimental but should work or be close, the arm and thumb backends are fine (use -m32 in clang to avoid 64 bit integers on a 64 bit host).

The stellaris chips formerly luminary micro, now ti (texas instruments) are good, thumb/thumb2 only. The mbed is actually pretty good other than the blue leds (give me migraines) you dont need to commit to a sandbox, plug in the usb, it mounts like a file system, copy your .bin file to the flash, press the reset button and it runs your program.

sparkfun.com is your friend, developer tools, and there is a long list of micrcontroller based boards, from all the players. the msp430 board I mentioned is about $5 something there, the armmite pro, many flavors of arduino, I recommend the lilly pad, it is about the same price as the arduino pro, but already has the header soldered on to use with the little usb to serial thing which you will want to purchase as well. stellaris is not represented at sparkfun, but many sub $50 boards are.

The msp430 boards, armmite pro, arduino boards, stellaris, mbed and others need power which is usually through the usb cable or for some get the ftdi based usb to serial thing

If you go the emulator route, qemu has support for a number of instruction sets, arm/thumb. there are gameboy and nds emulators out there. the ideas nds emulator, in source form comes with arm cores for both the arm9 and arm7, I have not tried to extract and use them on their own though. If you want to go old school there are tons of 6502 and z80 emulators out there, and some compilers believe it or not, certainly assembler.

The last assembler I would learn is x86, horrible instruction set and with the variations and microcoding you are not going to outperform the compiler across the board, yes your computer at that moment, but all x86 computers it is not worth the time. Other instruction sets are more important to know (arm, thumb, thumb2, avr).

0
votes

For an AVR embedded platform you can use free WinAVR, which has integrated simulator so it will be easy to learn ASM even without real board. You can find an ASM tutorial here. Quick start up guide for AVR can be found here. For example, all Arduino CPU boards have AVR inside them, so you have a very wide choice.

0
votes

I'm somewhat partial to the 14-bit PIC instruction set (Microchip) for the low end and the ARM instruction set for the high end. Both are relatively simple, but powerful for what they can do. The PIC 18F series has a somewhat more powerful instruction set, but aesthetically I don't like it as much.

0
votes

Now I want to take that one step further and learn assembly language

Is that really a step further, or a step backward? Arguably it is a path to deeper understanding, put it is hardly a path to greater productivity.


There is no one "assembly language", each processor architecture has its own instruction set so learning an assembly language will equip you only to program that particular target (although it will also give you general skills in low level programming and understanding how the processor works). The code you generate will also be specific to one architecture so all your effort and investment in code will be far less portable than in a high level language. If ultimately the architecture you choose becomes obsolete (and there are many that have), you assembly skills for that architecture become largely redundant knowledge apart from the general skills it may provide (it will be faster to learn the a new instruction set and architecture).

Unless you are going to be doing a lot of assembler and become highly proficient at a particular instruction set (and have a strong justification for doing so), learning assembler at all has limited value. It is useful if you are implementing start-up code to initialise a processor and establishing the run-time environment for your C or C++ code, but that may be largely provided by the chip or tool vendor and you do not need a full undestanding of an architectire or instruction set to use or adapt such code.

One often suggested argument for using assembler is performance, but in general an optimising compiler will generate code nearly as or nearly as efficient as an expert assembly programmer, and most often more efficient than a less than proficient one. You see the compiler is essentially an expert system as far as the target instruction set and architecture is concerned. It generally knows every available instruction and thier execution times, every register, every addressing mode, and understands the pipelining, caching, and branch prediction mechanisms etc. On a moderatley complex processor the compilers expertise will outgun all but the most dedicated full-time assembler programmers, and on simple processors there is far less to be gained either way.

One area where assembler may be useful is in utilising aspects of some processors that the compiler or its library may not touch. It is common for example to use assembler on DSP processors, but even there the use of optimised DSP libraries (generally themselves written in assembler), or compiler extensions or language idioms that the compiler recognizes and can optimise make this largely unnecessary, and learning a DSP instruction set with SIMD and parallel-execution capabilities is a significant investment.

The last time I needed used assembler other than C runtime start-up code, was when porting code from one ARM defice to a new one with a VFP co-processor; although the recompiled library made use of the VFP, the sqrt() function was implemented using a convergance algorithm rather than the hardware sqrt instruction. One function, one or two lines of assembly; I certainly did not need to learn the ARM instruction set to get that far.

The only assemby languages I have learned in detail are Z80 and 8051. That was a long time ago, and I hve forgotton it all, and the knowledge is now largely obsolete. However the general skills learned do allow me to tweak systems and do board bring-up as already described, but as some one who recruits aother embedded systems developers, I would not pay that much attention to a candidated assembly skills.

I think with assembly language you either need tourist/phrase-book level knowledge to just get by when you need to, or speak-it-like-a-native so that your skills have real value, anything in-between has little value.

That said, if you must, or feel the need, I suggest as ARM Cortex M3 device. Unlikely to become obsolete any time soon (devices from multiple licensee vendors), and sufficiently complex and nodern to give you a good grounding for other architectures.

0
votes

More important than learning an assembler, learn at least two. There is a wide variety in existing architectures, and knowing several assemblies looks like a good way to avoid making over-generalized assumptions.

Many assembly courses use MIPS. The MIPS instruction set is simple, and the high-end PIC microcontrollers (from Microchip) use it. MIPS processors are commonly found in home routers. OpenWRT is a replacement firmware for many such home routers, based on Linux. An OpenWRT-compatible router costs 50$ and is a cheap and easy way to enter the world of embedded systems.

Many mobile platforms, in particular mobile phones, use ARM processors (actually, all smartphones and tablets use an ARM derivative, but I read that about 15% of the cheap, non-smart phones still use something else, usually a MIPS). The ARM platform is a bit complex; there are several instruction sets (original 26-bit ARM, 32-bit ARM, Thumb, Thumb-2), and several call conventions (ATPCS, AAPCS...). ARM-based development kits can be bought from several vendors, e.g. Gumstix. There are a few ARM-based routers on which OpenWRT runs, but they are much less common than MIPS-based routers.

The automobile and airplane industries seem to be quite fond of PowerPC processors for their embedded systems. Also, the current major game consoles all use the PowerPC architecture (PS3, Xbox 360, Wii). For a PowerPC development platform, I recommend buying an old Mac, e.g. on Ebay or from a refurbished computer dealer. There are pointers from Low End Mac; look for a machine with a G3 or a G4. I bought a G3-based "clamshell" iBook for 60$ on Ebay; with NetBSD on it, this is a perfect PowerPC-based development platform.

The x86 CPU, as found in any PC, should be studied as well, if only because it is so prevalent. The machine your are using, bet it a PC or a post-2005 Mac, is your development platform, so that's cheap (you already have the hardware). The instruction set is "inelegant". Do not learn it as your first assembly, but have a look at it for your second or third. Every other year or so, x86 processor develop a new set of additional instructions, so now they have hundreds of those, which can be quite overwhelming; I recommend beginning with the instructions for the original 80386.

Some other architectures have been used and are still used for embedded products, e.g. the 68000, but they are rarer. Note that I talk here about the "big" embedded products. There are also smaller systems with architectures such as AVR, pre-MIPS PIC, 80C51... It depends on whether, when you say "embedded", you think "home router" or "programmable toaster".

Anyway, I also recommend using QEMU. QEMU is a software emulator. It is able to run a fully functional virtual ARM or MIPS-based machine, complete with operating system (e.g. a Debian Linux), on a basic PC. It will not help you for timing-related optimization, but it makes development and correction testing much easier.