COSMAC 1802 Load Instructions


Introduction to COSMAC 1802 Load Instructions

The COSMAC 1802 Load Instructions are probably the most important instructions to understand in the COSMAC. The main register of the 1802 (COSMAC) processor is the “D” register. Effectively, we know this as the “Accumulator”. We might load data into the accumulator and manipulate or compare the data. After that, we might store the value of the accumulator somewhere else in memory with a store instruction. We’ll discuss storing data in the next post.

In this post, we’ll take a look at these instructions, and how they work in the 1802 processor.

Load Immediate (LDI)

There are several types of load instructions. First, we can load an immediate value. That is to say, we specify a constant that we wish to load. The instruction for this is LDI (Load Immediate). Usually, we use this instruction if we want to perform math on a memory location. For example, we might load the value of 1 into the accumulator. After that, we can add or subtract this value to increment or decrement the value of a memory cell.

Here is an example of the LDI Instruction that loads the HEX value of 1.

LDI   01H

Load From Memory (LDN)

We use the LDN instruction to load data from a memory location on the 1802. We don’t specify the memory location directly, as you would in other processors. Instead, we specify the register that contains the memory location that we wish to load data from. Let’s say we want to load data from memory location $8200. We’ll just put together some simple logic to make this happen.

MYDATA  :     EQU   8200H
R5            EQU   5

              ORG   8000H
              LOAD  R5, MYMEMORY
              LDN   R5

In this case, we first declare some aliases. The first declaration, MYMEMORY simply allows us to use the name, MYMEMORY in our logic to reference memory location 8200H. Once you start working with many memory locations, these names are easier to remember than the actual memory location.

Next, we just declare that R5 represents the value of 5. This is to clarify in our program (for ourselves) that we are specifying a particular register, rather than a constant. These aliases are a direct substitution for the values they represent.

At this point, we use the ORG (originate) instruction to tell the assembler where our program will start in memory. The assembler needs to know this to generate the object code. Also, this ensures that as the processor jumps around in memory, it’s going to the correct memory locations.

After that, we have a LOAD instruction. This will load the value of MYMEMORY into register R5.

Finally, we use LDN R5. It’s important to realize, this does not load 8200H into the accumulator. It loads the data that’s contained in 8200H. In other words, the LDN instruction will go to R5 to find what memory location it needs to load data from.

Load and Advance (LDA)

Remember, the COSMAC is an array computer. Arrays are simply a group of memory locations. For example, we might have 6 memory locations that contain data we wish to send to a display. Also you might want to perform math function on an entire array of data, and store the result to another array.

We would want to load the first byte, then advance our pointer. After we perform operations on the first byte of data, we are set up to retrieve the next bye of data. In other words, it works a lot like the LDN instruction. It just adds 1 to the memory location contained in the register.

If we replace the LDN instruction in last example with an LDA, there would be one difference in the way it works: After the instruction executes, R5 will increment to 8201H.

Load Via X (LDX) using COSMAC 1802 Load Instructions

This instruction differs from the LDN instruction in one way: We don’t specify a register after the instruction. Instead, it uses the X designator to know where to load data from. This allows us to operate on different memory locations that different registers reference. We just specify the register with the Set X instruction (SEX). Let’s take a look at how we would load data from memory cell 8200H using the LDX Instruction:

MYDATA  :     EQU   8200H
R5            EQU   5

              ORG   8000H
              LOAD  R5, MYMEMORY
              SEX   R5
              LDX

As you can see, we load 8200H into R5. After that, we set the X designator to point to R5. At this point, all we need to specify is LDX. The processor knows that X is set to 5. Therefore, it will look up the memory location contained in R5. Then it will know what memory cell to get data from.

Load Via X and Advance (LDXA)

This instruction works just like the LDX instruction above. The exception is that it will advance R5. As I’ve said before, we might use this when accessing arrays that contain multiple bytes. After the instruction executes, R5 will contain 8201H.

GHI, and GLO (Get High Byte, and Get Low Byte)

Technically, these are not load instructions, because they don’t load from memory. These instructions can either get the high or low byte of a register (not data from a memory location in RAM). These commands simply bring a byte of data into the accumulator. You can use PHI and PLO (Put High, and Put Low), to store this data to another register.

Summary of COSMAC 1802 Load Instructions

In short, the COSMAC Load Instructions load data into the accumulator from either an immediate value or memory. Depending on the complexity of your program, you have different types of load instructions that allow you to save programming time and memory space in the 1802 processor.

For more information, visit the COSMAC Category Page!

— Ricky Bryce

Leave a comment

Your email address will not be published. Required fields are marked *