Memory and Addressing

There are several different types of memory in a micro. One is Program memory. This is where the program is located. Another is Data memory. This is where data, that might be used by the program, is located. The difference between the two is that Program memory is write protected , or read only, and can't be altered by the program. Data memory, on the other hand, can be changed by the program as necessary. Two terms are used when talking about memory. Reading is getting a value from memory and Writing is putting a value into memory.

There are three buses (not the kind you ride in) associated with the memory subsystem. One is the address bus, the second is the data bus, and the third is the control bus. It's not important for you to know exactly how all this works, because its inside the chip, so you can't see it anyhow. But conceptually, it's good to know that all three are connected to the memory subsystem. Its also good to know the function of each to better understand what's happening. The address bus is 16 bits wide. It acts to select one of the unique memory locations. The control bus determines whether this will be a read or a write. In the case of an instruction fetch, the control bus is set up for a read operation. Data is read or written through the data bus, which is 8 bits wide. This is why all registers and memory are 8 bits wide, it's the width of the data bus. A bus is just a group of connections that all share a common function. Instead of speaking of each bit or connection in the address separately, for example, all 16 are taken together and referred to simply as the address bus. The same is true for the control and data buses.

A byte is the most used number in a micro because each memory location or register is one byte wide. Memory has to be thought of as a sort of file cabinet with each location in it being a folder in the cabinet. In a file cabinet, you go through the tabs on the folders until you find the right one. To get to each memory location, a different method is used. Instead, a unique address is assigned to each location. In most micros this address is a word or 16 bits, or 4 digit hex. This allows for a maximum of 65536 (take my word for that right now) unique addresses or memory locations that can be accessed. These addresses are usually referred to by a 4 digit hex number. Memory usually starts at address 0000h and could go up to FFFFh (remember hex?). To access these locations, a 16 bit address is presented to memory and the byte at that location is either read or written.

The Program Counter is what holds this address when the micro is executing instructions. The reason instructions are read sequentially, is because the program counter automatically increments after fetching the current instruction. It does this even before the current instruction is acted upon. The sequence is that the program counter's contents are placed on the memory address bus and the instruction is fetched from memory through the data bus, and immediately the program counter is incremented by 1. Then the micro looks at the instruction and starts processing it. If the instruction is not some kind of jump or call, the instruction is completed and the program counter is presented to the memory address bus again and the next instruction is fetched, the program counter is incremented and the process starts over. This is referred to, in computer jargon, as fetch and execute.

In the case of reading or writing data, the process is a little different. As I've stated earlier, there are three different areas of memory. One is the program memory, which we've just discussed, and data can be read from this memory in similar fashion to the fetch. But data can be read or written in two other areas. One is the data memory. Here, the same process is used as in program memory, but with a different register holding the 16 bit address. The other memory area is what's called on-board memory. This is a block of 128 bytes. Part of this block is used for the registers. The rest can be used for whatever is needed. In the next lesson we will see this in more detail. On-board memory refers to memory that is actually part of the micro itself.

Until now, I've referred to the micro as if it was a single chip inside one package. But actually there are several pieces inside the one package. The micro is one of these pieces. Another is the program and data memories. Originally micros had no program or data memory within them. A micro, as I've been describing it to you, was actually made up of several chips, each in their own packages, all wired together. But the chip we will be using has all this, and more, inside one package. This makes creating something useful, a lot easier, as we will see later..

Last, but definitely not least, there is one more piece of memory inside the micro. It's called the special funcion registers. These registers hold configuration information for the micro, and control many aspects of the operation of the micro. It is where the Program Counter, accumulator, and the register used for multiplication and division are located. It is another 128 byte block who's addresses continue where the on-board memory addresses ended. These two areas make up a 256 byte block of memory where data can be read or written. We will see later how all this works.

In the next lesson we start looking at the micro we will be using. It is really called a microcontroller instead of a microprocessor. This is because it not only has the microprocessor chip inside, but the program and data memories, and the special function registers. In earlier days, this would have required many chips, all carefully interconnected with each other, to make a microcontroller. But, lucky for us, all this is already interconnected and inside one package ready for us to use. There is even a battery inside to keep all the data stored inside, protected from loss due to power loss. What will they think of next!!

My home page is .

On to lesson 5.