16.317 Microprocessor Systems Design I Instructor: Dr. Michael Geiger Fall 2013 Lecture 27: PIC instruction set.

Presentation on theme: "16.317 Microprocessor Systems Design I Instructor: Dr. Michael Geiger Fall 2013 Lecture 27: PIC instruction set."— Presentation transcript:

1 16.317 Microprocessor Systems Design I Instructor: Dr. Michael Geiger Fall 2013 Lecture 27: PIC instruction set

2 Lecture outline Announcements/reminders  HW 6 to be posted; due date TBD  Exam regrade requests due today Today’s lecture: PIC instructions 7/3/2015 Microprocessors I: Lecture 27 2

3 3 PIC16F684 Instructions 35 instructions Each instruction is 14 bits Byte-oriented OPCODE f, F(W)  Source f: name of a SFR or a RAM variable  Destination F(W): F if the destination is to be the same as the source register W if the destination is to be the working register Bit-oriented OPCODE f, b  Bit address b (0≤b≤7) Literal and control OPCODE k  Literal value k 7/3/2015

4 RAM variables Memory variable: symbolic name to refer to space in memory (GPRs)  Usable space on 16F684: 0x20–0x7F (Bank 0), 0xA0 – 0xBF (Bank 1)  Once declared, use symbolic name, not address Example PIC syntax (cblock/endc): cblock 0x20; cblock directive needs starting ; address var1; var1 = byte at 0x20 var2; var2 = byte at 0x21 var3; var3 = byte at 0x22 endc; End of variable block 7/3/2015 Microprocessors I: Lecture 27 4

6 Microprocessors I: Lecture 27 6 Clear/Move Examples: clrf TEMP1;Clear variable TEMP1 movlw 5;load 5 into W movwf TEMP1;move W into TEMP1 movwf TEMP1, F ;Incorrect Syntax movf TEMP1, W;move TEMP1 into W ; movf TEMP1, TEMP2;Incorrect Syntax swapf TEMP1, F ;Swap 4-bit nibbles of TEMP1 swapf TEMP1, W ;Move TEMP1 to W, swap nibbles, leave TEMP1 unchanged clrw ; Clear W register clrf f ; Clear f register movlw k; move literal value k to W movwf f; move W to f movf f, F(W); move f to F or W swapf f, F(W); swap nibbles of f, putting result in F or W STATUS bits: clrw, clrf, movf: Z movlw, movwf, swapf: none 7/3/2015

7 Microprocessors I: Lecture 27 7 Single Bit Manipulation Examples: bcfPORTB, 0;Clear bit 0 off PORTB bsfSTATUS, C;Set the Carry bit bcfSTATUS, RP1; bsfSTATUS, RP0;Select Bank 1 bcf f,b Operation: Clear bit b of register f, where b=0 to 7 bsf f,b Operation: Set bit b of register f, where b=0 to 7 STATUS bits: none 7/3/2015

8 Example Show the values of all changed registers after the following sequence cblock0x30 x y endc clrw movwfx movlw0xFE movwfy swapfy, F bcfy, 3 bsfx, 3 movfy, W 7/3/2015 Microprocessors I: Lecture 27 8

9 Example solution clrw  W = 0x00 movwfx  x = W = 0x00 movlw0xFE  W = 0xFE movwfy  y = W = 0xFE swapfy, F  Swap nibbles of y  y = 0xEF bcfy, 3  Clear bit 3 of y = 1110 1111 2  y = 1110 0111 2 = 0xE7 bsfx, 3  Set bit 3 of x  x = 0000 1000 2 = 0x08 movfy, W  W = y = 0xE7 7/3/2015 Microprocessors I: Lecture 27 9

12 Example Show the values of all changed registers after the following sequence cblock0x20 varA varB varC endc clrfvarA clrfvarB clrfvarC incfvarA, W sublw0x0F addwfvarB, F decfvarB, F comfvarB, W subwfvarC, F 7/3/2015 Microprocessors I: Lecture 27 12

13 Example solution clrfvarA  varA = 0 clrfvarB  varB = 0 clrfvarC  varC = 0 incfvarA, W  W = varA + 1 = 1 sublw0x0F  W = 0x0F – W = 0x0F – 1 = 0x0E addwfvarB, F  varB = varB + W = 0x0E decfvarB, F  varB = varB – 1 = 0x0D comfvarB, W  W= ~varB = ~0x0D = 0xF2 subwfvarC, F  varC = varC – W = 0x0E 7/3/2015 Microprocessors I: Lecture 27 13

14 Final notes Next time:  Continue PIC instruction set Reminders:  HW 6 to be posted; due date TBD  Exam regrade requests due today 7/3/2015 Microprocessors I: Lecture 27 14