Conditional Execution using Bit Test btfsc Explain what is t

Conditional Execution using Bit Test (btfsc).

Explain what is the operation of the following code? What is the output of the code?

INCLUDE \"P18F242.INC\"
CBLOCK 0x0
    loc,out
    ENDC
   org 0
   goto main
   org 0x0200
main
   ;movlw   0
   movlw   1
   movwf   loc
Ltop
   btfsc loc, 0
   goto loc_lsb_is_1
   movlw   4
   movwf   out
   movlw   2
   movwf   out
   movlw   3
   movwf   out
loc_lsb_is_1
   movlw   1
   movwf   out
   movlw   6
   movwf   out
   movlw   5
   movwf   out
   movlw   8
   movwf   out
   goto   Ltop
end

Solution

INCLUDE \"P18F242.INC\" # include the header file
CBLOCK 0x0 # specifies the first address or first free RAM location
    loc,out # variables
    ENDC # indicates the end of the list of variables
   org 0 # tells the assembler where the program is to reside in memory
   goto main # directs the microcontroller to beginning of the program
   org 0x0200   # tells the assembler where the main is to reside in memory
main
   ;movlw   0 # put 0 in register w
   movlw   1 # put 1 in register w
   movwf   loc # put 1 from the register to loc variable
Ltop
   btfsc loc, 0 # skip of loc is not 0
   goto loc_lsb_is_1 # jumps to label loc_lsb_is_1
   movlw   4
   movwf   out # put 4 from the register to out variable
   movlw   2
   movwf   out # put 2 from the register to out variable
   movlw   3
   movwf   out # put 3 from the register to out variable
loc_lsb_is_1   
   movlw   1
   movwf   out
   movlw   6
   movwf   out
   movlw   5
   movwf   out
   movlw   8
   movwf   out
   goto   Ltop # jumps to label ltop
end # end of main

Output

Here we have two variables loc and out. These variables are given various values. Based on the value of loc the value of out is assigned repeatedly.

Conditional Execution using Bit Test (btfsc). Explain what is the operation of the following code? What is the output of the code? INCLUDE \
Conditional Execution using Bit Test (btfsc). Explain what is the operation of the following code? What is the output of the code? INCLUDE \

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site