Thought I’d kick off a series of thoughts about programming languages with a discussion on Assembly Language.
Say what ?
If you are new to programming maybe you will be thinking about Java, C#, C++, PHP, Ruby … but for me, my professional experience started with Aseembly Language.
Actually it started with machine code – first bit of real programming I did was on a PDP-8 entering program instructions on a set of (binary) switches in real machine code. Yup – that’s the way to do it – real programmers flipped switches and ate quiche.
Assembly language is slightly higher level than the raw 0’s and 1’s of machine code although there is a very close correspondence between the two. There is the immediacy of cause-and-effect: write an instruction to set a bit on an output port and you can see the instruction being executed. It’s a great learning tool – and I still thing that if you are going to learn programming, then learning assembly language is a good place to start. There is not too much semantic “fluff” between what you are asking the computer to do and the commands that you give it.
It’s not perfect – many assemblers I used had serious restrictions on how long a symbol name could be – maybe six characters. And some assemblers were very fussy about the layout of the instructions but in many ways these restrictions just forced you to think more carefully. Macro assemblers allowed you to parameterise a series of instructions but most of the time what you wrote was what you got.
Assembly language is still used today – microcontrollers (such as the Microchip Technology PIC devices) although may have cross-compilers for C and other languages have assemblers. And if you have an understanding of the underlying processor architecure and the instruction set, you can work out what is going on the dissasembly view of your debugger.
Assembly language is good for solving small tasks – and in the 1980s a lot of the tasks we were trying to solve were small compared with today (ah nostalgia’s not what it used to be – can’t even use proper solder these day… now there’s a programming tool). Because one line of program code was pretty much one instruction – you had to write a lot of code to get things done. But you can do anything that you can do in a higher level language. I even read a book (and tried the techniques) of writing object-oriented assembly code – close, but no cigar!
Of course, one claim for assembly code is that you can write very efficient programs – but let’s face it you can write some incredibly inefficient programs too. However by writing in the native language for the processor, you were very close to the machine architecture, and that meant fewer compromises that higher level langauges require for their “ideal machine”. Having said that, I was mortified when I found that for certain problems, an optimising C compiler could produce more efficient code that I could carefully hand craft.
You could do incredibly “bad” things too – re-writing code on the fly, interchanging data and program instructions. (Just wait until I get to PHP!)
So on balance I think that even if you are ultimately going to use a high level language, it won’t do any harm to learn some assembly language – who knows you may have some fun in the process.