CHAPTER 4 PROGRAM MEMORY (ROM)
24
4.2 PROGRAM MEMORY USAGE
Program memory has the following two main functions:
(1) Storage of the program
(2) Storage of constant data
The program is made up of the instructions which operate the CPU (Central Processing Unit). The CPU executes
sequential processing according to the instructions stored in the program. In other words, the CPU reads each
instruction in the order stored by the program in program memory and executes it.
Since all instructions are 16-bit long words, each instruction is stored in a single location in program memory.
Constant data, such as display output patterns, are set beforehand. The MOVT instruction is used to transfer data
from program memory to the data buffer (DBF) in data memory. Reading the constant data in program memory is
called table reference.
Program memory is read-only (ROM: Read Only Memory) and therefore cannot be changed by any instructions.
4.2.1 Flow of the Program
The program is usually stored in program memory starting from memory location 0000H and executed sequentially
one memory location at a time. However, if for some reason a different kind of program is to be executed, it will
be necessary to change the flow of the program. In this case, the branch instruction (BR instruction) is used.
If the same section of program code is going to appear in a number of places, reproducing the code each time
it needs to be used will decrease the efficiency of the program. In this case, this section of program code should
be stored in only one place in memory. Then, by using the CALL instruction, this piece of code can be executed
or read as many times as needed within the program. Such a piece of code is called a subroutine. As opposed to
a subroutine, code used during normal operation is called the main routine.
For cases completely unrelated to the flow of the program (in which a section of code is to be executed when
a certain condition arises), the interrupt function is used. Whenever a condition arises that is unrelated to the flow
of the program, the interrupt function can be used to branch the program to a prechosen memory location (called
a vector address).
Items (1) to (5) explain branching of the program using the interrupt function and CPU instructions.
(1) Vector Address
Table 4-1 shows the address to which the program is branched (vector address) when a reset or interrupt
occurs.