Provide a partial analysis of the program below by including
Provide a partial analysis of the program below by including the following two items:
1. A flowchart of the code, starting with address TOP, that executes while the button remains pushed.
2. A complete timing analysis of the code referenced in item 1, including a statement of the number of
instruction cycles and the time in seconds needed for this code to execute once. Compare this theoretical
time with the observed time needed for the LED to toggle from off to on or from on to off with the button
pushed.
Table I
Light flasher program
;light flasher DMK 12/21/2013
list P=PIC16F84
;equates
count0 equ H’0C’
count1 equ H’0D’
porta equ H’05’
portb equ H’06’
status equ H’03’
trisa equ H’05’
trisb equ H’06’
org H’0’
;beginning of program
goto start
start clrf porta
clrf portb
bsf status,5
movlw 0
movwf trisa ;all Port A bits outputs
movlw 2
movwf trisb ;Port B bit 1 an input
bcf status,5
;beginning of first loop
top movlw H’0E’
movwf count0
inner1 movlw H’0C3’
movwf count1
loop1 decfsz count1,1
goto loop1
decfsz count0,1
goto inner1
movlw H’1’
xorwf porta,1 ;toggle the LED
btfss portb,1 ;test the pushbutton
goto top ;jump to first loop if button pressed
;beginning of second loop
movlw H’0E’ ;continue with second loop if button released
movwf count0
inner2 movlw H’0C3’
movwf count1
loop2 decfsz count1,1
goto loop2
decfsz count0,1
Solution
count0 equ H’0C’
count1 equ H’0D’
porta equ H’05’
portb equ H’06’
status equ H’03’
trisa equ H’05’
trisb equ H’06’
org H’0’
;beginning of program
goto start
start clrf porta
clrf portb
bsf status,5
movlw 0
movwf trisa ;all Port A bits outputs
movlw 2
movwf trisb ;Port B bit 1 an input
bcf status,5
;beginning of first loop
top movlw H’0E’
movwf count0
inner1 movlw H’0C3’
movwf count1
loop1 decfsz count1,1
goto loop1
decfsz count0,1
goto inner1
movlw H’1’
xorwf porta,1 ;toggle the LED
btfss portb,1 ;test the pushbutton
goto top ;jump to first loop if button pressed
;beginning of second loop
movlw H’0E’ ;continue with second loop if button released
movwf count0
inner2 movlw H’0C3’
movwf count1
loop2 decfsz count1,1
goto loop2
decfsz count0,1


