PIC mid-range microcontroller assembly instructions (5)

Source: Internet
Author: User

Bit operation instructions

BCF data register refers to locating 0

Syntax: bcf f, B

Operand: F is the low 7-bit address of the data register (0x00 ~ 0x7f)

B is the data bit number (0 ~ 7)

Execution time: one instruction cycle

Execution Process: Clear the B-bit of data register F to 0

Status flag impact: None

Note: This command can be used to clear 0 at any position of any data register. It is often used to set and clear the flag bit, or to set a pin to a low level.

Command example: BCF status, C; carry (borrow) Mark C clear 0

BCF portd, 7; portd's 7th-bit output low

BSF data register refers to location B set 1

Syntax: bsf f, B

Operand: F is the low 7-bit address of the data register (0x00 ~ 0x7f)

B is the data bit number (0 ~ 7)

Execution time: one instruction cycle

Execution Process: Enable B Position 1 of data register F

Status flag impact: None

Note: This command can be used to set 1 to any position in any data register. It is often used to set and clear flag spaces, or to set a pin to a high level.

Command example:

BSF intcon, gie; location 1 of intcon register, enable global interrupt

BSF portd, 6; portd 6th-bit output high

Btfsc determines the position in the data register. If it is 0, the next instruction is skipped.

Syntax: btfsc F, B

Operand: F is the low 7-bit address of the data register (0x00 ~ 0x7f)

B is the data bit number (0 ~ 7)

Execution time: one or two command cycles

Execution Process: If the B-bit of data register F is 0, the next instruction is skipped.

Status flag impact: None

Note: This command can be used to judge any one of the data registers by 0/1. If the data bit is 1, the program will execute the next command in sequence. This is a command cycle; if the data bit is 0, the first instruction following the instruction is skipped and executed from the Second instruction. At this time, two instruction cycles are used. This command is most commonly used to implement branch jump control by flag.

Command example:

Btfsc status, Z; Z mark of the Test Status Register

Goto zero; if z = 1, execute the command here

Goto notzero; if z = 0, execute the command here

Btfss determines the position of the data register. If the value is 1, the next instruction is skipped.

Syntax: btfss F, B

Operand: F is the low 7-bit address of the data register (0x00 ~ 0x7f)

B is the data bit number (0 ~ 7)

Execution time: one or two command cycles

Execution Process: If the B-bit of data register F is 1, the next instruction is skipped.

Status flag impact: None

Note: This command can be used to judge any digit in the data register by 0/1. If the data bit is 0, the program will execute the next instruction in sequence. This is a command cycle; if the data bit is 1, the first instruction following the instruction is skipped and executed from the Second instruction. At this time, two instruction cycles are used. This command is most commonly used to implement branch jump control by flag.

Command example:

Btfss portb, 7; test portb port, bit 7

Goto rb7_low; If rb7 = 0, run the command here.

Goto rb7_high; If rb7 = 1, execute the command here

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.