Program Memory

chapter 3



BrainIO has two main memory: The program memory and the data memory.

3.1 Why do we need a program memory?
Program memory typically refers to flash memory when it is used to hold the program (instructions). It could be a rom or a ram. A rom would usually be found in most von neumann architecture. They are not rewriteable, meaning the programs are not renewable. BrainIO runs high level programs or instructions which are modifiable and needs to be stored on the chip during execution. So, we need a rewritable memory or ram that would stores these instructions that needs to be executed. If we have a need to write a new software program, we can also erase it and write the new instructions. So this is the main reason we need a the program memory which is a programmable ram or Flash memory.

3.2 Program Memory
The program memory is a separate memory that stores the program instruction. Both the address and data are 16-bit wide. The brainIO program memory stores two types of data: executable instruction and data. The decode unit determines if the output of the program memory is an instruction or data. Instructions are executed while data are stored in the data register. These data are usually constants which are not modifiable during execution.

The data register is not latched. This means it stores information for only one clock cycle. Therefore, the data are immediately followed by the instruction that wants to execute it. They also contain long data which cannot be contained in the instruction such as ram address and ram data. At the beginning of the program, informations such as variables, port directions and control data are stored as data.



3.3 Program Memory Pinout
The output from this memory is the data_out which contains the instruction or data. The program memory operates in two modes: read and write mode. During the write mode or load operation which is used to load the program instruction into the ram, the we is set high, this turns off the output_enable signal and the load_addr and in_data is used to load data into the ram. When the we is low, this is used for a read instruction, the program memory fetches the read address from the program counter regsiter in the register unit.Here, it is referred to as PC that is program counter.


3.4 program_memory.vhd
First let us add the title

Next we include the IEEE standard libraries on line 29 down to 31 .

We will start with our entity , lets call it programMemory. Within it, would be a generic that will consist of the memory address width and data width. Here, we have a 16 x 16 ram. Next is the port which we will use to declare the ports of the program memory given in the diagram above. In as much as the generic data size are adjustable, BrainIO was designed to decode specifically a 16-bit data. The address size can be adjusted alongside the output of the program counter.

We declare the signals. Here, only one signal. A single port ram of type ram_type which is an array, whose address size is 2 ^ addr_width, which is 2^16.

If the WE signal is enabled, then we are loading instruction else we are fetching them from the ram. The LOAD_ADDR and IN_DATA are the address and data to be written, while the DATA_OUT is the ram output.

3.5 program_memory.h
The program memory address comes from the program counter register which is part of the register unit. Also the output of the program memory which is the instruction needs to call the decode() function which is part of the decode unit. So we included the register.h and decode.h files to be able to access items in these units.

Our program memory will have one output which is the INSTRUCTION, stored in its progmem pm struct.

We declare two functions which are the read and write. For the write operation, we will need the data to be written and its address as arguments. For the read operation, the program memory will get the address from the program counter register which is part of the register unit, therefore it takes no argument when called.

3.6 program_memory.c
Let us include our header file on line 2. Next we define our ram. Here, I have used a 1024 size array. Finally, the previous_instr which I will describe shortly.

Lets define the program memory write function.

For the read operation, the address to be read is the program counter called PC_DATA which is part of the register struct called registers reg_data. Our current instruction will be moved to the previous_instr variable and take up the new instruction from the instructions variable. This new instruction will now be stored in the program memory struct as pm. INSTRUCTION. If the previous instruction and the new instruction are not both equal to zero then we decode the new instruction.



Alu split_bit()