SSU ES 310 - Chapter 5 Instruction to Data Copy

Unformatted text preview:

Chapter 5 Instruction to Data Copy 2 21 14 Data Copy Move and Set Clear Operations The data copy operations are classified as o Loading 8 bit data directly in WREG o Copying data between WREG and data file register including I O ports o Copying data from one data file register to another data file register o Clearing or setting all data bits in data file register o Exchanging low order four bits nibble with high order four bits in data file register Frequently Used Registers in ALU Memory and I O Ports for Data Copy o o o o o Literal to W W F F F F Program memory Swapping lower order with the higher order Addressing Modes o A way of specifying of an operand n Direct addressing o n The operand is a part of the instruction Indirect addressing o An address is specified in a register and the MPU looks up the address in that register MOV Copy Operations Instructions o MOVLW o MOVWF o MOVF o MOVFF 8 bit F a F d a Fs Fd Examples o MOVLW 0xF2 Load F2H in WREG o MOVWF REG1 0 Copy WREG in REG1 o MOVF REG1 1 Copy REG1 in REG1 check for flag o MOVF REG1 0 Copy REG1 into WREG o MOVFF REG1 REG2 Copy REG1 into REG2 d 0 or omitted then WREG a 0 or omitted then data reg is from Access Bank SET CLR Instructions Instructions o CLRF F a o SETF F a o SWAP F d a Examples o CLRF REG1 0 Clear REG1 located in access bank o SETF REG1 0 Set all bits in REG1 o SWAP REG1 1 0 Exchange low and high nibbles in REG1 save in REG1 Using File Select Registers FSRs as Pointers to Data Registers Indirect addressing o Memory pointer is a register that holds the address of a data register n n o Three registers FSR0 FSR1 and FSR2 n n o This is called indirect addressing Easy to move copy an entire block Each FSR has a High and Low byte associated with an index Used as memory pointers to data registers Each can be used in five different formats operands n n n n n INDF0 POSTINC0 POSTDEC0 PREINC0 PLUSW0 Use FSR0 as pointer index Use FSR0 as pointer and increment FSR0 Use FSR0 as pointer and decrement SR0 Increment FSR0 first and use as pointer Add W to FSR0 and use as pointer LFSR FSR1 120 LOAD 12 BIT ADDRESS 120h INTO FSR1 Indirect Addressing Example 0x0 0x0 Initially FSR values are 0 and status of registers are given as above LFSR FSR1 0x0120 load the LFSR FSR2 0x0150 MOVFF POSTINC1 POSTINC2 Load the content of FSR1 FSR2 and increment FSR1 FSR2 Indirect Addressing Example 1 Examples MOVFF INDF0 INDF1 ADDWF POSTINC0 1 COPY BYTE FROM REGISTERS SHOWN BY FSR0 TO FSR1 NO CHANGE IN FSR ADD BYTE FROM REGISTERS SHOWN BY FSR0 AND W REG FSR0 IS INCREMENTED Hence we will have A3 in register 0x151 after the MOVFF instruction Note that the pointer indexes are not changing FSR0 FSR1 A3 Indirect Addressing Example 2 Examples MOVFF INDF0 INDF1 ADDWF POSTINC0 1 COPY BYTE FROM REGISTERS SHOWN BY FSR0 TO FSR1 NO CHANGE IN FSR ADD BYTE FROM REGISTERS SHOWN BY FSR0 AND W REG FSR0 IS INCREMENTED Assume W 2 after the ADD operation A3 2 A5 Reg 0x0121 then FSR 0x0122 FSR0 FSR1 0x0122 A5 A3 Initializing the RAM Application of Indirect Addressing What is this doing Using Table Pointers to Copy Data 8 bit data registers 21 bit 16 bit Using Table Pointers to Copy Data from Program Memory into Table Latch REFER TO PAGE 82 83 o TBLRD n o Copy from Program Memory into Table Latch and Increment Table Pointer TBLRD n Copy from Program Memory into Table Latch Using Table Pointer TBLRD n o o Copy from Program Memory into Table Latch and Decrement Table Pointer TBLRD n Increment Table Pointer first and then copy from Program Memory into Table Latch Using Table Pointers to Copy Data from Table Latch into Program Memory o TBLWT n o o Copy from Table Latch into Program Memory Using Table Pointer n TBL WT n Copy from Table Latch into Program Memory and Increment Table Pointer TBL WT o Copy from Table Latch into Program Memory and Decrement Table Pointer TBLWT n Increment Table Pointer first and then copy from Table Latch into Program Memory Copying Data from Program Memory to Table Latch 76 Using TBLRD Address 01251H 76 TABLAT 76 TBLPTR 01251H Copying Data from Table Latch to Program Memory Arithmetic Operations o The PIC18F MPU performs the following arithmetic operations n n n n n n Add Subtract Multiply Complement 1s and 2s Increment Decrement Addition Instructions o ADDLW 8 bit o ADDWF F d a Examples o o o o ADDWFC F d a o 1 Impacts all the flags 2 Result can be saved in W if d 0 3 ADDWFC is used for numbers 8 bit ADDLW 0xA2 Add A2H to WREG ADDWF REG1 0 Add WREG to REG1 and save the sum in W ADDWF REG1 1 Add WREG to REG1 and save the sum in REG1 ADDWFC REG2 0 Add WREG REG2 and Carry from previous operation and save the sum in WREG ADDWF Example WREG REG20 Carry 0 1 0 0 1 1 1 1 4FH 0 1 0 0 1 0 0 0 48H 1 1 1 0 0 1 0 1 1 1 97H 151d N 1 OV 1 Z 0 DC 1 C 0 ADDWF Example Assume we want to add 0x7292 and 0x1F91 REG10 91 REG11 1F REG20 92 REG21 72 Do 4 5 SE REG10 REG20 22 C 1 291d N 1 OV 1 Z 0 DC 1 C 1 page 122 ADDWFC REG11 REG21 C 0x72 0x1F 1 0x92 1 0 0 1 0 0 1 0 N OV Z DC C Subtraction Instructions o o SUBLW SUBWF 8 bit L WREG F d a Examples o o F WREG o o SUBFWB F d a o o SUBWFB F d a o SUBLW 0xA2 Subtract WREG from A2H SUBWF REG1 0 Subtract WREG from REG1 and save the result in W SUBWF REG1 1 Subtract WREG from REG1 and save the result in REG1 SUBFWB REG2 0 Subtract REG2 and Borrow from WREG and save the result in W SUBWFB REG2 0 Subtract WREG and Borrow from REG2 and save the result in W If the number is larger than 8 bit Example Assume W 7F and REG5 28 SUBWF Means 28 7F W REG5 Adding values larger than 8 bits Write a Program REG10 F2 REG11 29 REG12 87 REG13 35 Increment Decrement and Complement Operations Instructions o INCF F d a o DECF F d a o COMF F d a o NEGF F a Examples o INCF REG1 1 Increment REG1 and save result in REG1 o DECF REG2 0 Decrement REG2 and save result in W o COMF REG3 0 Complement REG3 and save result in W o NEGF REG1 0 Take 2s …


View Full Document

SSU ES 310 - Chapter 5 Instruction to Data Copy

Download Chapter 5 Instruction to Data Copy
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Chapter 5 Instruction to Data Copy and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Chapter 5 Instruction to Data Copy 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?