You are on page 1of 14

Bit-oriented & control transfer

instructions

Prepared by : Maher Al -Omari


Bit set file : BSF F,b

Syntax:
Syntax: [[ label
label ]] BSF
BSF f,b
f,b
Operands:
Operands: 00 ≤≤ ff ≤≤ 127
127
00 ≥≥ bb ≤≤ 77
Operation:
Operation: 11 → (f<b>)
→ (f<b>)
Status Affected:
Status Affected: None
None

Prepared by : Maher Al -Omari


BSF
BSF 03, 66
03,
BSF
BSF 03, 55
03,
BSF :EXAMPLE

BSF
BSF STATUS, RP1
STATUS, RP1
BSF
BSF STATUS, RP0
STATUS, RP0

Prepared by : Maher Al -Omari


Bit clear file : BCF f,b

Syntax: [[ label
Syntax: label ]] BCF
BCF f,b
f,b
Operands:
Operands: 00 ≤≤ ff ≤≤ 127
127
00 ≥≥ bb ≤≤ 77
Operation:
Operation: 00 → (f<b>)
→ (f<b>)
Status Affected:
Status Affected: None
None

Prepared by : Maher Al -Omari


BCF :EXAMPLE

BCF PORTA,
BCF PORTA, 00
BCF PORTA,
BCF PORTA, 55

BCF 05,
BCF 05, 00
BCF 05,
BCF 05, 55

0 0

Prepared by : Maher Al -Omari


Example :

1 1 1
0 0 0

BSF
BSF 0X05, 00
0X05,
BSF
BSF 0X05, 11
0X05,
BSF
BSF 0X05, 22
0X05,
BCF
BCF 0X05, 22
0X05,
BCF
BCF 0X05, 11
0X05,
BCF
BCF 0X05, 00
0X05,
Prepared by : Maher Al -Omari
Bit Test
Bit Test file
file and
and Skip
Skip ifif Set
Set
BTFSS F,b
BTFSS F,b

Syntax:
Syntax: BTFSS f,b
BTFSS f,b
Operands:
Operands: 00 ≤≤ ff ≤≤ 127
127 ,, 00 ≤≤ bb ≤≤ 77
Operation:
Operation: skip ifif (f<b>)
skip (f<b>) == 11
Status Affected:
Status Affected: None None
Description:IfIfbit
Description: bit‘b’
‘b’in
inregister
register ‘f’
‘f’is
is‘0’,
‘0’,the
thenext
next
instructionis
instruction isexecuted.
executed.IfIfbit
bit‘b’
‘b’is
is‘1’,
‘1’,then
thenthe
thenext
next
instructionis
instruction isdiscarded
discardedandandaaNOP
NOPis isexecuted
executed
instead,making
instead, makingthis
thisaatwo-cycle
two-cycleinstruction.
instruction.

Prepared by : Maher Al -Omari


BTFSS ::example
BTFSS example

MOVLW
MOVLW 0X0F
0X0F
BTFSS
BTFSS PORTA,4
PORTA,4
ANDWF
ANDWF PORTB
PORTB
IORWF
IORWF PORTC
PORTC

Prepared by : Maher Al -Omari


Bit Test
Bit Test file
file and
and Skip
Skip ifif clear
clear
BTFSC F,b
BTFSC F,b

Syntax:
Syntax: [[ label
label ]] BTFSC
BTFSC f,b f,b
Operands:
Operands: 00 ≤≤ ff ≤≤ 127
127 ,, 00 ≤≤ bb ≤≤ 77
Operation:
Operation: skip ifif (f<b>)
skip (f<b>) == 00
Status Affected:
Status Affected: None
None

Prepared by : Maher Al -Omari


BTFSC ::example
BTFSC example

MOVLW
MOVLW 0X0F
0X0F
BTFSC
BTFSC PORTA,7
PORTA,7
ANDWF
ANDWF PORTB
PORTB
IORWF
IORWF PORTC
PORTC

Prepared by : Maher Al -Omari


GOTO kk
GOTO Unconditional Branch
Unconditional Branch

Syntax: [ label ] GOTO k


PC
Operands: 0 ≤ k ≤ 2047 12 0
Operation: PCLATH
4 3

Status Affected: None


Description: k is loaded into PC bits <10:0>. The upper bits of PC are
loaded from PCLATH<4:3>.
GOTO is a two-cycle instruction.

١١ Prepared by : Maher Al -Omari


INCFSZ Increment f, Skip if 0

Syntax: [ label ] INCFSZ f,d


Operands: 0 ≤ f ≤ 127 d =[0,1]
Operation: (f) + 1 > (destination), skip if result = 0
Status Affected: None
Description:
The contents of register ‘f’ are incremented.
If ‘d’ is ‘0’, the result is placed in the W register.
If ‘d’ is ‘1’, the result is placed back in register ‘f’.
If the result is ‘1’, the next instruction is executed.
if the result is ‘0’, a NOP is executed instead, making it a two-cycle
instruction.

١٢ Prepared by : Maher Al -Omari


DECFSZ Decrement f, Skip if 0

Syntax: [ label ] DECFSZ f,d


Operands: 0 ≤ f ≤ 127 d = [0,1]
Operation: (f) - 1 > (destination); skip if result = 0
Status Affected: None
Description:
The contents of register ‘f’ are decremented.
If ‘d’ is ‘0’, the result is placed in the W register.
If ‘d’ is ‘1’, the result is placed back in register ‘f’.
If the result is ‘1’, the next instruction is executed.
If the result is ‘0’, then a NOP is executed instead, making it a two-cycle
instruction.

١٣ Prepared by : Maher Al -Omari


Example
Example

delay
delay MOVLW
MOVLW 0xFF;;
0xFF
MOVWF
MOVWF Count
Count
down
down DECFSZ
DECFSZ Count
Count
down‫؛؛‬
GOTO down
GOTO

when combined with the instruction


goto they can be used to program
loops or iterations in which the number
of iterations is controlled by the value
located in the register f.
١٤ Prepared by : Maher Al -Omari

You might also like