0% found this document useful (0 votes)
20 views7 pages

5.PIC Instruction Set Introduction

This section discusses the use of instructions with the default access bank in PIC Assembly language, emphasizing the MOVWF instruction for moving data from the WREG register to various locations in the file register. It explains how to manipulate special function registers and general-purpose registers, providing examples of loading values and performing arithmetic operations. Additionally, it highlights the importance of using WREG as an intermediary for moving immediate values into RAM locations.

Uploaded by

Mohd Anas
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views7 pages

5.PIC Instruction Set Introduction

This section discusses the use of instructions with the default access bank in PIC Assembly language, emphasizing the MOVWF instruction for moving data from the WREG register to various locations in the file register. It explains how to manipulate special function registers and general-purpose registers, providing examples of loading values and performing arithmetic operations. Additionally, it highlights the importance of using WREG as an intermediary for moving immediate values into RAM locations.

Uploaded by

Mohd Anas
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

SECTION 2.

3: USING INSTRUCTIONS WITH THE DEFAULT


ACCESS BANK

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:

MOVLW SSH ;WREG .. SSH


MOVWF PORTB ; copy WREG to Port B ( Port B - SSH)
MOVWF PORTC ;copy WREG to Port C (Por t C - SSH)
MOVWF PORTO ; copy WRBG to Por t D ( i'ort D - SSH )

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:

MOVLW 99H ;WREG • 99H


MOVWF OH ;mo ve ( copy ) WRBO cont e nts t o l oca t i o n Oh
MOVWF lH ; move (c op y ) WREG contents to l o c at i on lh
MOVWF 2H
MOVWF 3H
Address Data
MOVWF 4H
000 99
001 99
The chart indicates the contents of addresses 0---4
002 99
after execution of the code.
003 99
004 99

48

Example 2-1
State the contents of file register RAM locations after the following program:

MOVLW 99H ; l o ad WREG with value 99H


MOVWF 12H
MOVLW 85H ; load WREG with value 85H
MOVWF 13H
MOVLW JFH ; load WREG with value JPH
MOVWF UH
MOVLW 63H ; load WREG with value 63H
MQV\tl'F 15H
MOVLW 12H ;load WREG with value 12H
MOVWP 16H

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

More instructions involving the WREG and the access


bank
There is a group of logic and arithmetic instructions that involve both the
WREG and a location in the file register. The ADDWF instruction is one of them.
The ADDWF instruction adds together the contents of WREG and a file register
location. The file register location can be one of the SFRs or a general-purpose
register. The destination for the result can be the WREG or the file register. The
following fonnat indicates the destination:

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.

CHAPTER 2: PIC ARCHITECTURE & ASSEMBLY LANGUAGE 49

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:

MOVLW 22H ;WREG • 22H


MOVWF SH ;move (copy) WRBG contents to location SH
MOVWF 6H ;move (copy) WREG contents to location 6H
MOVWF 78 ;move (copy) WREG contents to location 7H
ADDWF SH, 0 ;add W and loc 5, result in WREG (W • 44H)
ADDWF 6H, 0 ;add W and loc 6, result in WREG (W z 66H)
ADDWF 7H, 0 ; add W and loc 7, result in WREG (W .. 88H)

Address Data Address Data

005 22 005 22
006 22 006 22
007 22 007 22

GPR after the ex;ecution up to GPR after the execution up to


"MOVWF 7H" "ADOWF 7H, O"
WREG-22H WREG c 88H

Now look at the same program where the result is put into file register loca-
tion 7:

MOVLW 228 ;WREG • 22H


MOVWF SH ;move (copy) WREG contents to location SH
MOVWF 6H ;move (copy) NREG contents to location 6H
MOVWF 7H ;move (copy) NREG contents to location 7H
ADDWF 5, 0 ;add W and loc 5, result in WREG (N ,. HH)
ADDWF 6, 0 ;add W and loc 6, result in WREG (W • 66H)
ADDWF 7, l ;add W and loc 7, result in location 7H
;now location 7 has 88H and WREG • 66H

Address Data Address Data

005 22 005 22
006 22 006 22
007 22 007 88

You might also like