5.PIC Instruction Set Introduction
5.PIC Instruction Set Introduction
The instructions we have used so far are the literal (constant) value or K
and the WREG register. They also used the WREG register as their destination. We
saw simple examples of using MOVLW and ADDLW earlier in Section 2. 1. The
PIC allows direct access to other locations in the file register for ALU and other
operations. In this section we show the instructions using various locations of the
file register. This is one of the most important sections in the book for mastering
the topic of PIC Assembly language programming.
MOVWF instruction
As we discussed in the last section, the access bank of the file register is
the default bank upon powering up the PIC 18. The term file register must be
emphasized because the instructions have the letter F in their mnemonics. In
instructions such as MOVWF, the F stands for a location in the file register, while
W means WREG The MOVWF instruction tells the CPU to move (in reality,
copy) the source register of WREG to a destination in the file register (F). After
this instruction is executed, the location in the file register will have the same value
as register WREG The location in the file register can be one of the SFRs or a
location in the general purpose registers region. For example, the •'MQVWF
PORTA" instruction will move the contents of WREG into the SFR register called
PORTA. The following program first loads the WREG register with value SSH,
then moves this value around to various SFRs of ports B, C, and D:
PORTS, PORTC, and PORTO are part of the special function registers in
the file register, as was shown in Figure 2-4. They can be connected co the 1/0 pins
of the PIC microcontroller as we will see in Chapter 4. We can also move (copy)
the contents of WREG into any location in the general-purpose registers (RAM)
region of the file registers. The following program will put 99H into locations 0---4
of the GPR region in the file register:
48
Example 2-1
State the contents of file register RAM locations after the following program:
Solution:
After the execution ofM0VWF 12H fileReg RAM location 12H has value 99H;
After the execution ofM0VWF 13H fileReg RAM location 13H has value SSH;
After the execution ofM0VWF 14H fileReg RAM location 14H has value 3FH;
After the execution ofM0VWF 15H fileReg RAM location ISH has value 63H;
And so on, as shown in the chart.
Address Data
012 99
013 85
014 JF
Address Data
012 99
013 85
014 3F
015 63
016 12
Notice that you cannot move Uteral (immediate) values directly into
the general-purpose RAM locations in the PIC18. They must be moved there
vlaWREG
ADDWF fileReg' D
where fileReg is the file register location and D indicates the destination bit. The
D bit can be O or I. IfD = 0, it means that the destination is WREG IfD = I, then
the result will be placed in the file register.
The following will first put value 22H into GP RAM locations 5, 6, and 7,
then add them together and put the result in WREG:
005 22 005 22
006 22 006 22
007 22 007 22
Now look at the same program where the result is put into file register loca-
tion 7:
005 22 005 22
006 22 006 22
007 22 007 88