3. The 6800x Processor

The processor we are programming is one of Motorola's 68000 series. Be it a 68008 or a 68060 (if you are lucky) all of them have the same basic instruction set, although some of the more powerful processors have additional instructions. Partly because we have to cater for those on an original QL but mostly because I don't have a clue about these additional instructions, we will be dealing with the basic instruction set - there is enough there to keep us happy for a while. Inside the processor there are a few different parts, but we are only concerned with the registers - the rest just does the work and puts the results somewhere, setting a few flags along the way. Talking of flags, we will also take a look at the status register - a very important part of programming.

3.1. Registers

Registers are where numbers get loaded into, manipulated and written out from. Some instructions operate directly on memory locations, but to all intents and purposes, memory is just another register but outside of the processor and a lot slower. The 68000 - which is the term I shall use from now on to describe the entire family of processors - has different types of registers - data, address, status and program counter. Data held in registers and in memory is held in High Order format. This simply means that the numbers are stored in a similar manner to the way in which we would expect them to be - the 'rightmost' end holds the most significant bit and the 'leftmost' the lowest - just the way we write numbers down.

3.2. Data Registers

There are 8 data registers named D0 to D7 and these can be used to perform manipulations on the numbers that are held in them. Each register can hold 32 bits of information. (A bit is a single binary digit - basically a one or a zero). What these bits actually represent depends on the program running at the time. Data registers are normally used for manipulating data in the form of bytes, words and long words - these being 8, 16 and 32 bits long respectively.

3.3. Address Registers

There are 9 address registers named A0 to A7. A7 is sometimes known as the stack pointer or SP register. What about the other address register then ? The ninth address register is a duplicate of A7 and is the SSP or Supervisor Stack Pointer. When coding the chip, you only have access to 8 address registers at any one time - you are either using the SP or SSP version of A7 but never both at the same time.

Address registers are normally used to hold memory addresses, stack pointers etc and cannot be used for byte sized manipulations.

3.4. Status Register

The status register holds a list of flags to tell the processor what is happening or has happened internally. The status register is a 16 bit register in two 8 bit halves. The user byte is held in bits 0 to 7 ( the lowest end) and the system byte is held in the upper half or bits 8 to 15. The layout is as follows.

3.4.1. The System Byte

Bit 15 14 13 12 11 10 9 8
     T     S        I I I 
  • Bit 15, 'T' is the trace flag - this defines whether the processor is in 'single step' mode or running normally. If set to 1, the processor is tracing and if 0, is running normally. In trace mode the processor ' stops' after each instruction has been executed and jumps to the Trace exception routine. Exceptions are covered later in the series.

  • Bit 13, 'S' is the supervisor flag - this defines whether the code being executed is running in user or supervisor mode. If set, the processor is in supervisor mode otherwise it is in user mode.

  • Bits 10, 9 and 8, 'III' is the interrupt mask and represents a value between 0 and 7 and indicates which of the seven interrupt levels are enabled. The other bits are not used. :

3.4.2. The User Byte

Bit 7 6 5 4 3 2 1 0
          X N Z V C

The user byte contains the 5 condition code flags which are set or reset by certain instructions and then used by arithmetic or comparison instructions. The are used to tell later parts of a program what happened recently. The program can adjust its operations to suit. The flags are :

  • Bit 4, 'X' is the extended flag. Which is very similar to the 'C' flag bit but is affected by fewer instructions than 'C' is. This is used when carrying out very large sized arithmetic instructions - such as 64 bit adds, for example. When affected it is set exactly like the 'C' flag.

  • Bit 3, 'N' is the negative flag. It gets set to 1 if the last instruction created a negative number.

  • Bit 2, 'Z' is the zero flag and is set to 1 if the last instruction generated a result of zero.

  • Bit 1, 'V' is the overflow flag and is set to 1 if the last instruction generated an overflow during 2's complement arithmetic. See later for details.

  • Bit 0, 'C' is the carry or borrow flag. And is used when a subtraction operation is carried out - be it an actual subtraction or an implied one.

The flags are used by the branch on condition (Bcc) instructions, the Decrement and branch (DBcc) instructions or the Set (Scc) instructions. These will be explained later.

3.5. The Program Counter

The program counter does just that, it keeps track of where exactly the processor is within a program. The program counter always points to the address in memory of the next instruction to be executed. The program counter can of course be changed by a JMP (jump) instruction or a BRA (branch) but it is always ready with the next instruction to be executed.