428 44 An introduction to assembly language Machine code and the assembler The heart of any computer, the part that actually does all the processing, is the central processor unit (CPU). It is important to realise that no matter what language is typed in at a computer’s keyboard (sometimes called the source language ), the only language that the CPU understands is machine code . Of course, the exact form of the machine code depends upon the source language and also upon the type of CPU, but generally speaking any machine code instruction would look something like this:
1010100110000001 This hardly looks like an intelligible instruction, and even rewriting it as two pairs of hexadecimal digits hardly makes it look any better: A9 81 However, to the BBC Microcomputer’s 6512 microprocessor, A9 means ‘load the accumulator’, and the whole of the above instruction means ‘load the accumulator with hexadecimal 81’. (The accumulator is one of six registers which reside in the 6512 microprocessor.) The ‘A9’ part is known as the ‘operation code’ or opcode for short, and the 81 is the ‘operand’. A few more hex machine code instructions with their meanings are:
A2 64 ‘load the X register with &64’ A0 00 ‘load the Y register with zero’ 20 F4 FF ‘jump to the subroutine at location &FFF4’ You will probably agree that whilst it would be possible to write programs using opcodes like those shown above, it would be extremely tedious. What’s more, since the 6512 only carries out one instruction at a time, a sequence of instructions like that shown above would have to be ‘poked’ into contiguous locations in RAM. As a final indignity, if you spent a long time writing a machine code program which turned out not to work, it would be extremely difficult to trace the errors – unlike BASIC, machine code does not generate error messages automatically.
Fortunately, the BBC Microcomputer contains a program which will generate machine code instructions for you. It’s available as part of the BBC BASIC language, and is known as the assembler. The language that the assembler understands is simply known as assembly language , or 6502 assembly