1802 Introduction

        .cr     1802        To load the 1802 cross overlay
        .cr     1804        To load the 1804 cross overlay
        .cr     1805        To load the 1805 cross overlay

This is an old one, one which has been on my wish list for a long, long time. And yet it proved to be not even a very difficult cross assembler to make.
The CDP1802 was, to my knowledge, the first commercially available CMOS processor. It had a wide operating voltage range and had by far the lowest power consumption of all the available competitors. It also had good radiation protection, so it could be used in the space industry. According to Wikipedia the 1802 found its way into the Hubble space telescope for instance.

The CDP1802 got some younger brothers. The CDP1804 had 22 extra instructions and on board RAM, ROM and a timer. The CDP1805 had another 10 extra instructions, but no internal ROM. And finally the CDP1806 was identical to the CDP1805, but had no internal RAM.

The most popular computer with a 1802 of the time was the COSMAC Elf, which came in many shapes and sizes. There is still an active COSMAC community around these days.

Personally I have never built something around an 1802 thus far. I do own a couple of those chips, so I might get tempted to build a COSMAC Elf some day. Furthermore I do own a Mephisto II Chess computer, which is powered by an 1802. It can run on 4 AA batteries, although I have no idea how long they will last.

COSMAC Elf COSMAC Elf from Popular Electronics

I have written 3 separate cross overlays. One for the 1802, one for the 1804 and one for the 1805 and 1806. The only difference being the extended instruction set for the 1804 and an even further extended instruction set for the 1805 and 1806. The 1806 is identical to the 1805, except for the fact that the 1806 has no internal RAM.

Programming Model

All variations of the 1802 share the same programming model. They all have sixteen 16-bit registers. Each of these registers can be used as program pointer, data pointer, stack pointer, or general purpose data storage registers.
An accumulator takes care of the calculations. And a couple of 4-bit pointer registers select which registers are used for special tasks. CDP1802 programming model

The Accumulator

The Accumulator is used in the traditional way during calculations, where it can be the source and destination of the values. It is also used to move data around memory and other registers.

Sixteen registers

The 1802 has sixteen 16-bit registers. They are used for data storage, program pointer, data pointer, DMA pointer, interrupt pointer, or stack pointer.
After reset R0 is selected as program pointer, starting your program from address 0. If you want to make use of DMA you'll have to change to another register as program pointer, because DMA can only use R0 as memory pointer.
R1 is dedicated as interrupt pointer. If you don't use interrupts you can use R1 for any other purpose.
R2 is dedicated as stack pointer and is better not used for other purposes.
All other registers are free to be used as you please. However there are some conventions for the use of R3 to R6 in subroutine calling. The 1802 doesn't have a dedicated subroutine instruction, so you'll have to build that yourself. R3 is then normally used as program counter, R4 as pointer to the subroutine, R5 is used as return address and R6 is used as a stack pointer.
This leaves the registers R7 to RF free for general purpose storage.

Control registers

The 4-bit X register determines which one of the 16 registers is used as data pointer registers. The selected 16-bit register will point to the data to be accessed in memory. X is cleared by reset.
T is 8 bits wide but is not directly accessible. It holds X (high nibble) and P (low nibble) after an interrupt.
The 4-bits P register points to the program counter register. It selects which one of the 16 registers is used as program counter. P is cleared by reset.
The 4-bits I register holds the upper nibble of the currently executing instruction.
The 4-bits N register holds the lower nibble of the currently executing instruction.

Timing

Most instructions execute in 2 machine cycles. Some in 3. The 1804 and 1805 also have instructions which take up to 10 machine cycles.
Every machine cycle requires 8 clock cycles, which obviously results in a less than average performance of the processor. Most instructions take 16 clock cycles to execute. The 1804 and 1805 use slightly less clock cycles, making them just a little bit less slow.

Reserved Words

There are no reserved words. You can use any label name you choose, without causing any confusion to the SB-Assembler.

Overlay Initialization

Two things are set while initializing the 1802 overlay family every time the overlay is loaded by the .CR directive.

  • Big endian model is selected for 16-bit addresses and for the .DA and .DL directives. This means that words or long words are stored with their low byte first.
  • The maximum program counter value is set to $FFFF.

Differences Between Other Assemblers

There are some differences between the SB-Assembler and other assemblers for the 1802 family processor. These differences require you to adapt existing source files before they can be assembled by the SB-Assembler. This is not too difficult though, and is the (small) price you have to pay for having a very universal cross assembler.

  • The obvious differences in notation of directives common to all SB-Assembler crosses.
  • Don't forget that the SB-Assembler does not allow spaces in or between operands. Only Version 3 will allow one space after each comma separating operands in the operand field.
  • Register numbers are not predefined. You'll have to define the registers yourself using the .EQ directive.