5095 views|1 replies

1379

Posts

0

Resources
The OP
 

Reading Common Instructions of PIC8-bit Microcontroller Assembly Language (Part 2) [Copy link]

The comments about instructions in this article will be slightly different from those in the previous instructions. The previous instructions are commented on to explain the specific functions of the instructions. This comment method is indeed easy for beginners to accept and understand. However, the comments of PIC product assembly language in actual applications are usually based on what the program is going to do (or the function of the instructions) rather than the direct function of the instructions. In view of the above reasons, the following instruction comments will change the previous comment method and use the function that the program should play as an annotation.
  10? Register half-byte swap instruction
  Instruction format: SWAPF f, d
  Description: SWAPF is the combination of Swap f. The meanings of the symbols f and d are the same as those mentioned above. The function of this instruction is to exchange the upper 4 bits and lower 4 bits of register f, that is, before the instruction is executed, if the 8-bit state of register f is D7, D6, D5, D4, D3, D2, D1, D0, the 8-bit state after execution becomes D3, D2, D1, D0, D7, D6, D5, D4, and the result is stored in W (d=0) or f (d=1).
  Example: Interrupt context protection is an important part of interrupt technology. Since there are no PUSH and POP instructions in the PIC16C×× instruction system, it can only be implemented using other instructions. Because the working register W and the status register STATUS are often used in the main program, the interrupt context protection often needs to protect the registers W and STATUS.
  The following is an example program for interrupt context protection of PIC16C7× series chips.
MOVWF W_TEMP; store the content of W
             in the temporary register W_TEMP
SWAPF STATUS, W; swap the content of STATUS and W
MOVWF STATUS_TEMP; store the content of STATUS
in the temporary register STATUS_TEMP
Interrupt service routine
...
SWAPF STATUS_TEMP, W; swap
            the content of STATUS_TEMP and W
MOVWF STATUS; restore STATUS to its original state
SWAPF W_TEMP, F; swap the content
SWAPF W_TEMP, W; restore W to its original state
  Note: The comments of each instruction in the above program are basically based on the purpose of the program, and the function of each instruction is almost not involved. This is what beginners should pay special attention to.
  11?Subroutine Call Instruction (Subroutine Call)
  Instruction format: CALL k; k is an immediate address.
  Description: The implementation methods of subroutine call are different for different chip models. The common point is that the return address ((PC) + 1) is first pushed onto the stack for protection, and then the entry address of the subroutine to be called is executed (similar to the MCS-51 instruction function).
Instruction format mode: HERE CALL DELAY; call delay subroutine
        ...
       DELAY MOVLW 0x80; delay subroutine
         RETLW 0
  Description: Before the call instruction is executed, PC = address HERE
  After the call instruction is executed, PC = address DELAY (label), stack pointer TOS = HERE + 1 (return address).
  Example: See the example of the next instruction
  12?Register content complement instruction
  Instruction format: COMF f, d
  Description: COMF is the abbreviation of Complement f. When d = 1, operation (f) → f; when d = 0, operation (f) → w.
  Function: After the contents of register f are inverted, they are sent to W (d=0) or f itself (d=1).
  Example: ORG 0x1FF
      GOTO MAIN
      ORG 0
  DELAY ...
  MAIN MOVLW 0; Main program starts
     TRTS 5; Set port RA to output
   BCF 5,0; Set port RA bit 0 to 0
  LOOP CALL DELAY; Flash delay
      COMF 5?; RA port inverts (on-off-
              on...control)
      GOTO LOOP; Loop
       ...
  Description: The above instructions are part of the program for a PIC16C54 LED light control experiment. The delay subroutine DELY is not listed, but it does not affect the reading of this instruction. The three instructions at the beginning of the main program in the program have been introduced. The CALL instruction that follows is to call the execution subroutine, and its entry address is the label DELAY. After the subroutine is executed, the LED light on-off...on-off...control instruction of COMF 5 is executed again. The following GOTO LOOP instruction is to achieve the purpose of cyclically lighting the LED.
  13? Bit-oriented operation instructions (4 in total, one more for PIC advanced products)
  In addition to one bit clear instruction, this type of instruction also has one register f bit b set 1 instruction and two other bit skip instructions (PIC advanced products have one more f bit b trigger conversion instruction).
  (1) Position 1 instruction. Instruction format BSF f, b
  Description: BSF is the abbreviation of Bit Set f. The meanings of F and b are the same as above. The function of this instruction is to set the b position of register f to 1.
  (2) Bit test, zero jump instruction. Instruction format BTFSC f, b
  Description: BTFSC is the abbreviation of Bit Test, Skip if Clear. The function of the instruction is to test the register f bit "b". If it is 0, skip the next instruction; if it is 1, execute sequentially, that is, when f(b)=0, do not execute the current instruction but execute the next instruction (jump), that is, replace it with a null instruction NOP, so this instruction takes 2 instruction cycles.
  (3) Bit test, 1 jump instruction. Instruction format BTFSS f, b
  Description: BTFSS is the abbreviation of Bit Test, Skip if Set. The logical function of this instruction is opposite to the previous one. If the bit test f(b)=1, the execution will skip, and if f(b)=0, the execution will be sequential.
  The PIC 8-bit microcontroller assembly language instructions introduced above are only part of the instructions. In addition, there are also instructions for circular left and right shifts; instructions for "adding" and "ANDing" W and register f, and instructions for entering sleep mode. Due to the limitation of newspaper layout, I will not introduce them one by one here, and will make additional explanations in the application test of the program in the future. ?
This post is from Microchip MCU

Latest reply

Thank you! I can study during the holidays.   Details Published on 2011-7-15 20:35
 

734

Posts

4

Resources
2
 
Thank you! I can study during the holidays.
This post is from Microchip MCU
 
 
 

Guess Your Favourite
Find a datasheet?

EEWorld Datasheet Technical Support

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号
快速回复 返回顶部 Return list