
Site Search
SECTION III-1: MOVWF Instruction in the PIC micro-controller
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.
MOVWF Instruction:-
The access bank of the file register is the default bank upon powering up the PIC18. 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 special function registers SFRs or a location in the general purpose register region. For example: The "MOVWF PORTA" instruction will move the contents of WREG into the SFR register called PORTA.
The following program first loads the WREG register with value 55H, then moves this value around to various SFRs of PORT B, C and D.
MOVLW 55H | ;WREG = 55H |
---|---|
MOVWF PORTB | ;copy WREG to PORT B (Port B = 55H) |
MOVWF PORTC | ;copy WREG to PORT C (Port C = 55H) |
MOVWF PORTD | ;copy WREG to PORT D (Port D = 55H |
PORTB, PORTC, and PORTD are part of the special function registers in the file register as shown in figure below. They can be connected to the I / O pins of the PIC micro-controller.
Special Function Registers of the PIC18 Family |
---|
![]() |
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 general purpose register GPR region in the file register:
MOVLW 99H | ;WREG = 99H |
---|---|
MOVWF 0H | ;move (copy) WREG contents to location 0h |
MOVWF 1H | ;move (copy) WREG contents to location 1h |
MOVWF 2H | ;move (copy) WREG contents to location 2h |
MOVWF 3H | ;move (copy) WREG contents to location 3h |
MOVWF 3H | ;move (copy) WREG contents to location 4h |
The chart indicates the contents of addresses 0 - 4 after execution of the code
Address | Data |
---|---|
000 | 99 |
001 | 99 |
002 | 99 |
003 | 99 |
004 | 99 |
State the contents of file register RAM locations after the following program | |
---|---|
MOVLW 99H | ;load WREG with value 99H |
MOVWF 12H | |
MOVLW 85H | ;load WREG with value 85H |
MOVWF 13H | |
MOVLW 3FH | ;load WREG with value 3FH |
MOVWF 14H | |
MOVLW 63H | ;load WREG with value 63H |
MOVWF 15H | |
MOVLW 12H | ;load WREG with value 12H |
MOVWF 16H | |
After the execution of MOVWF 12H filereg RAM location 12H has value 99H | |
After the execution of MOVWF 13H filereg RAM location 13H has value 85H | |
After the execution of MOVWF 14H filereg RAM location 14H has value 3FH | |
After the execution of MOVWF 15H filereg RAM location 15H has value 63H | |
After the execution of MOVWF 12H filereg RAM location 16H has value 12H |
As shown in the chart below:
Address | Data |
---|---|
012 | 99 |
013 | 85 |
014 | 3F |
015 | 63 |
016 | 12 |