Who uses assembler?
Just what is assembler?
Assembler or assembly language is defined on The Other Wiki as:
- An assembly language is a low-level programming language for computers, microprocessors, microcontrollers, and other programmable devices. It implements a symbolic representation of the machine codes and other constants needed to program a given CPU architecture.
As we all know, Other Wiki often takes delight in over-explaining things. So in simple terms:
- Assembly language is when you speak the natural language of the processor, every instruction that you write is directly converted into an instruction for the processor to execute.
There is no high-level stuff. Character strings and data arrays do not exist, it is just data. Object oriented is alien. Even such cosy comforts as array bounds checking cease to exist. As does the array itself. An array in assembler is what you program it to be.
Seriously, who codes in assembler these days?
While it is true that programming in assembler throws portability out of the window, it isn't as terrible as it seems, for there are only a few processors in common use. In addition to which, there are many similarities - the same x86 program will work on a variety of Intel x86 processors, and even clones like the AMD processors. Likewise, an ARM compiled executable for ARMLinux will work on a range of devices.
Now, if you want to write a word processor, or Yet Another Cute Twitter Feed App, then for God's sake use a high level language.
If, on the other hand, you want to get your hands dirty - assembler is almost essential. Getting your hands dirty includes hand-optimising image structures and plotting code to make a game as fast as possible, writing a specialist device driver to talk to a specific piece of hardware, or porting something to work with new hardware.
- An example of the latter - I'd like to try getting RISC OS running on my PVR "just because". I think, as an ARM926 platform, the kernel will more or less "just work". What won't work, and what is liable to fall over is anything that accesses hardware. I would need to rip out the HAL and write my own veneers between what RISC OS expects to see and what is real. And that, dear friends, is something only feasible in assembler.
There is another group entirely. Embedded controllers.
Allow me to introduce you to the Olimex SAM3-H256 based upon the Atmel ATSAM3S4BA-AU. The chip itself is €11, dropping to around €7 for bulk orders. It offers...
- An ARM Cortex-M3 running at 64MHz (Thumb2 instruction set, 16/32 bit instructions, three stage pipeline, hardware divide, single cycle 32 bit multiply)
- Memory protection unit
- 256KiB embedded Flash (128 bit wide access)
- 48KiB embedded SRAM
- 16KiB ROM with bootloader routines
- Watchdog and power monitoring
- USB 2 (up to 12mbit/sec)
- 2 USARTs capable of supporting ISO7816 (smartcard access), IrDA (infrared), RS-485 (traditional serial), SPI (basic SD card access), etc.
- 2 2-wire UARTs (basic serial)
- I2C compatible interface, I2S, high speed SDIO/SD/MMC interface
- Three channel 16 bit timer/counter, can capture, compare waveform, and work in PWM mode. Also 2 bit Gray Counter (bidirectional) for stepper motor control.
- 32 bit real time clock with calendar.
- 10 channel ADC (analogue to digital) with programmable gain.
- 2 12 bit DAC outputs
- Analogue comparator
- 32 bit CRC calculation unit (so can do CRCs in hardware)
- Up to 47 digital I/O lines with interrupt capabilities (edge or level trigger), debounce and glitch filter.
- Interrupt controller capable of up to 30 maskable interrupts with 16 levels of priority.
Not bad for a tenner. Or, get this, mounted on a little board with I/O sockets - you'd get a few centimes change from €20! It almost makes me want to build an interface board so I can turn our old analogue washing machine into something clever. All it needs is a way to have the high voltage equipment signal to and be controlled by the microprocessor (optosensors and relays) and the rest is just software... your washing cycles can be whatever your imagination devises.
There is, no doubt, a C compiler, however assembly language allows you ultimate flexibility.
Who will take to assembler?
- If your idea of "programming" is checking what clashes with Coronation Street, you must be really really bored to be reading this far. I would like to welcome you to the concept of hardcore computer programming, however I probably shouldn't as nobody in the pub ever wants to talk about the merits of interrupt handling. That sort of thing is a real conversation killer. I speak from experience. Plus, pubs charge more than a beer to serve up a flat budget lemonade because people that don't drink alcohol (and talk about "interrupts") just aren't manly enough. And then they wonder why their clientelle drift away...
- If your life in coding started with Pascal and ended with Delphi, or perhaps VisualBasic - you may find assembler to be a bit of a struggle. Pascal-like languages go to lengths to protect you from yourself and enforce regimental behaviour. VisualBasic is more relaxed, but it goes to even greater lengths to "hide the complicated stuff". After all, in VB you can create a functioning program by designing "how it will look" before double-clicking on objects (icons, buttons, etc) and attaching code to events that are possible (like this-button-clicked-upon).
- If your life in coding is C and C++, then you're halfway there. Discard all the pompous posturing of C++ (in fact, dump C++ entirely) and look at some of C's grottier corners. There lacks something getting dangerously close to talking to the machine on its own terms.
- If you grew up in the '80s with inferior dialects of BASIC that required lots of
POKEcommands... chances are you were programming in assembler, only you were doing it the insanely hard way (by working out the hex codes of instructions and their parameters and then pushing this into memory byte by byte).
As an assembler coder you can lord it over other programmers. No, seriously, it's part of the assembly programmer's charter, or something. You have little concern for semicolons or whether an array counts from zero or one. You are talking to the computer on its own terms. Therefore you will become the programmer elite. Almost anybody can write a functional C program. Anybody's grandmother can do it with VisualBasic. But it takes a certain type of person to tackle the computer by its rules. Consider this like the bullfighting of the computer world... only you don't need to dress up in a stupid homoerotic outfit (but you can if you want, just don't tell anybody - though you might find dressing up as Zorro fits the mindset better).
Hehe... If you've just read that last paragraph and you're scratching your head, welcome to ARMwiki. The aim is to be:
- At times surreal (we'll settle for "weird")
This is because there are plenty of datasheets and boring dry tutorials. Hell, I've sat through enough rubbish lessons in my time it's a wonder I bothered at all. I would like to give you somewhere to come that will provide the necessary information, spark your imagination, and most of all be enjoyable. Programming in assembly language can be presented in an intensely boring manner. Imagine it being taught by a despectacled man in his late fifties with a tweed suit and a handkerchief poking out of one pocket a man who always talks in a monotone and never shows any sense of emotion and never pauses between sentences and speaks in one continuous run-on sentence but not in a cool Ally McBeal sort of way but the sort of way that makes you wish you could kick back and play Angry Birds on your phone and not care if you flunk the lesson but you can't as your parents would unleash seven kinds of hell upon your spitroasted carcass...
Now imagine. A bloke of indeteriminate age. Bad hair that isn't so much greasy as a side effect of sticking fingers in the electric socket, perhaps. Boundless enthusiasm. Thinks 17 year old girls are "cute" because he's not yet figured out he isn't 17. Has a tendency towards blowing up stuff. Never ever wears a suit. Sometimes wears a lab coat for the hell of it.
That'll be me in a decade. And that'll be the sort of lunatic who you'd appreciate teaching you computer stuff.
Still here? Okay, that's it for the mad intro. Hit the BACK button and carry on reading!