Docsity

PIC Architecture: Instruction Set and Move Instructions, Slides of Microcomputers

Partial preview of the text

Download PIC Architecture: Instruction Set and Move Instructions and more Slides Microcomputers in PDF only on Docsity!

PIC Architecture

Instruction Set

PICs-Instruction Set

  • Have Covered Instruction Set Basics
    • Accumulator Architecture
    • Direct addressing
    • Indirect addressing
  • Now lets look at the instructions

More on MOVE

  • Initialization of a variable
    • movlw Bโ€™11100000โ€™
    • movwf TRIST
    • Initialize the PORTB data direction register
  • Assembler MACRO
    • MOVLF Bโ€™11100000โ€™,TRISB
    • Assembled into the two instructions above

The movff instruction

  • movff PORTB, PORTB_COPY
    • movff - a two-word instruction
    • Thus source and destination have 12-bit addresses
      • Source โ€“ instruction bits + BSR
      • Destination โ€“ instruction 2nd^ byte
    • Moves data from a 1-byte source to a 1-byte destination.
    • For instruction memory as efficient as the regular move instruction.

The movf instruction

  • Move the value and set the status register bits appropriately
  • Affects N and Z bits

Move summary

  • movlw k - load literal value
  • movwf MYVAR - move value but do not affect status bits
  • movff V1,V2 - move data at source address to data at destination address
  • movf f,F/W - move value and affect status bits - What does movf COUNT,F do?

Load BSR register & other

  • movlb 2
    • Load the value of 2 into the BSR register
  • clrf TEMP โ€“ Load 0x00 into variable TEMP
  • setf TEMP โ€“ Load 0xff into variable TEMP
  • swapf f - swap nibbles of f

Single operand instructions

  • Single bit instructions
    • bsf PORTB,0 - Set the lsb of PORTB
    • bcf PORTB,1 - clear bit 1 of PORTB
    • btg PORTB,2 - toggle bit 2 of PORTB
  • Rotate instructions illustrated on next slide
    • rlcf rlncf rrcf rrncf
    • cf rotate including carry bit
    • ncf rotate without carry bit

Logical instructions

  • andlw Bโ€™00001111โ€™ And WREG with value
  • andwf f,F/W - AND WREG with f putting result back in F or WREG
  • iorlw k -Inclusive OR literal value and WREG
  • iorwf f,F/W โ€“ inclusive OR WREG with f and put result into f or WREG
  • xorlw k, xorwf f,F/W - Exclusive OR

Arithmetic

  • addlw k, addwf f,F/W
  • addwfc f,F/W - Add WREG, F and carry bit
  • daw โ€“ Decimal adjust sum of pack BCD
  • subwf, sublw
  • subwfb f,F/W - subtract with borrow

Branches

  • Needed for program flow control
  • Tests on status register
    • bc, bnc, bz, bnz, bn, bnn, bov, bnov
    • Use the c, x, n, and ov bits of the status register
  • bra โ€“ branch always

Conditional Skip instructions

  • Ten further instructions that test for a condition and skip over the next instruction if the condition is met. - Next instruction is typically a branch or rcall - Very useful at end of a loop - Loop code โ€ฆ. - decfsz count,F ;Decrement and skip if zero - bra top_of_loop

Other โ€“ Subroutine, interrupt

  • rcall label - call subroutine (within 512 instr)
  • call label โ€“ call subroutine (anywhere)
  • call label, FAST - call subroutine, copy state to shadow registers
  • return โ€“ return form subroutine
  • return FAST - return and restore from shadow registers
  • return k - return and put value k in WREG

cont

  • retfie - return from interrupt and re-enable
  • retfie FAST โ€“ return, re-enable- restore
  • push - Push addr of next instruction onto stack
  • pop - discard address on top of stack
  • clrwdt - clear watchdog timer
  • sleep - Go into standby mode
  • reset - software controlled reset
  • nop