chapter  7
15 Pages

The fetch-execute sequence

Example I Beginning very modestly, all we want to do is to place a number in the accumulator, say 15H (&15). In a real program this simple instruction would probably be followed by many others, but ignoring that for the moment, the program would look like this: Program 1 Load the accumulator with a number 2 The number to be loaded (15H or &15) 3 Next instruction Before looking up the codes in the instruction set, we write out the program in mnemonics, a short-hand representation, designed to be reasonably recognisable, of the program we are writing. Machine code mnemonics were first shown in Chapter 1 in the 'Print "ABCD"' program. For this program, the mnemonic would look like this:

(Z80) LD A, 15H (6502) LDA #&15 This would be read as 'load the accumulator with the hexadecimal number 15H'. The next task is to look in the instruction set and find the opcode for loading the accumulator with a number. This opcode becomes the first instruction in the program. The second item of code is the number itself.