Moving and Transferring Data
The transfer of data within the microcontroller program is one of the most frequently used opera
-
tions. Making use of three kinds of MOV instructions, data can be transferred from registers to the
Accumulator and vice-versa as well as being able to move specific immediate data directly into the
Accumulator. One of the most important data transfer applications is to receive data from the input
ports and transfer data to the output ports.
Arithmetic Operations
The ability to perform certain arithmetic operations and data manipulation is a necessary feature
of most microcontroller applications. Within the Holtek microcontroller instruction set are a range
of add and subtract instruction mnemonics to enable the necessary arithmetic to be carried out.
Care must be taken to ensure correct handling of Carry and borrow data when results exceed 255
for addition and less than 0 for subtraction. The increment and decrement instructions INC, INCA,
DEC and DECA provide a simple means of increasing or decreasing by a value of one of the val
-
ues in the destination specified.
Logical and Rotate Operations
The standard logical operations such as AND, OR, XOR and CPL all have their own instruction
within the Holtek microcontroller instruction set. As with the case of most instructions involving
data manipulation, data must pass through the Accumulator which may involve additional pro
-
gramming steps. In all logical data operations, the zero flag may be set if the result of the operation
is zero. Another form of logical data manipulation comes from the rotate instructions such as RR,
RL, RRC and RLC which provide a simple means of rotating one bit right or left. Different rotate
instructions exist depending on program requirements. Rotate instructions are useful for serial
port programming applications where data can be rotated from an internal register into the Carry
bit from where it can be examined and the necessary serial bit set high or low. Another application
where rotate data operations are used is to implement multiplication and division calculations.
Branches and Control Transfer
Program branching takes the form of either jumps to specified locations using the JMP instruction
or to a subroutine using the CALL instruction. They differ in the sense that in the case of a subrou-
tine call, the program must return to the instruction immediately when the subroutine has been car-
ried out. This is done by placing a return instruction RET in the subroutine which will cause the
program to jump back to the address right after the CALL instruction. In the case of a JMP instruc
-
tion, the program simply jumps to the desired location. There is no requirement to jump back to the
original jumping off point as in the case of the CALL. One special and extremely useful set of
branch instructions are the conditional branches. Here a decision is first made regarding the condi
-
tion of a certain Data Memory or individual bits. Depending upon the conditions, the program will
continue with the next instruction or skip over it and jump to the following instruction. These instruc
-
tions are the key to decision making and branching within the program perhaps determined by the
condition of certain input switches or by the condition of internal data bits.
94
I/O Type MCU