COSMAC 1802 Store Instructions

Introduction to the COSMAC 1802 Store Instructions

The COSMAC 1802 Store Instructions allow us to store data to memory from the accumulator. We’ll discuss the different types of store instructions, and how they operate. You only have two store instructions, the STR (Store), and STXD (Store and Decrement). You can, however, place data into registers using the PHI (Put High), and PLO (Put Low) instructions.

We can use these instructions to store data that we will need later in or program. Additionally, we can store data to devices that might display or record this data. Examples include GPIO Lights, LED Displays, or LCD Displays. You can also use these instructions to send data through the UART, or to pull data from the processor “Stack”. Technically, the 1802 does not have a stack. We can emulate one though through the use of it’s instruction set.

Store Instruction (STR)

Remember, the COSMAC uses a lot of indirect addressing. The COSMAC has 16 “scratchpad” registers. We can load a memory location into one of these 16 registers. The STR Command will store data that is currently in the “D” Register. We also know this as the “Accumulator” When we execute a STR command and specify a register, the data does not go to that register. The COSMAC sends data to the memory location that register specifies.

If you haven’t yet done so, please check out the post on the COSMAC 1802 Load instructions. That post will explain how you can get data into the accumulator that you wish to store.

Let’s look at an example of the STR Command:

MYDATA:     EQU     8200H

            ORG         8000H
            LOAD        RC, MYDATA
            LDI         55H
            STR         RC

We set up some aliases at first, but then we set the origin at 8000H. We’ll load RC with the memory location of MYDATA. Therefore, register RC will contain 8200H. After that, we load the value of 55 (Hex) into the accumulator. Finally, we store the value of 55H to the address that is in RC.

This means that if we go to memory location 8200H on the COSMAC, we will see the value of 55.

Store Via X and Decrement (STXD)

The Store Via X and Decrement command (STXD) will first look at the X designator. If you wish to change where the X register points, simply use the SEX (Set X) command. This will tell the processor which register to look at. After that, the processor looks at this register to see what memory location to write to.

Finally, the STXD will decrement the register. Most commonly, you will use this command in STACK Operations. We store values to the stack from the top down. When we load from the stack, we will use the LDXA instruction. This will load from the stack, and advance (increment) the memory location in the register that X designates.

Alternatives to Standard COSMAC 1802 Store Instructions

There is no STXA command. If you wish to store and advance, use the INC (Increment) command after the STR. Additionally, there is no STX command to store via X. If you wish to have this functionality, simply store to the same register that X designates.

Summary of the COSMAC 1802 Store Instructions

In short, there are 2 store commands. STR, and STXD. Both of these instructions store data that is in the accumulator. The STR will store data to a memory location contained in the register you point to. STXD writes to a memory location contained n the register designated by X. It also decrements the register designated by X.

You can also store single bytes of data to registers with the PLO (Put Low), and PHI (Put High) instructions. In a way, if all of your registers are not already in use, you could use them as memory locations to some degree.

For more information, visit the COSMAC Category Page!

— Ricky Bryce

Leave a comment

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