Write the rest of the instructions to execute the loop 5 tim
Write the rest of the instructions to execute the loop 5 times, assume Wait1 is a good subroutine that adds in a 1 second delay and that the program continues at “KeepOn” and does whatever.
BANKSEL Z
MOVLW 0x05
MOVWF Z
Loop BANKSEL PORTA
BSF PORTA,5
CALL Wait1
BANKSEL PORTA
BCF PORTA,5
CALL Wait1
BANKSEL Z
KeepOn BANKSEL TRISC
…………. Rest of program
e.) Write instructions to ADD the 8 bits in the A variable to the B variable and store the result in the Z variable without changing A or B.
Solution
(1)
BANKSEL Z
MOVLW 0x05
MOVWF Z
Loop BANKSEL PORTA
BSF PORTA,5
CALL Wait1
BANKSEL PORTA
BCF PORTA,5
CALL Wait1
BANKSEL Z
KeepOn BANKSEL TRISC
sublw 0x01 -- decrement register w by 1.
iorlw 0x00 -- logical OR between register w and 0.
btfsc STATUS,Z -- check Z and skip the next instruction if its zero.
goto Loop
-------------------------------------------------------------------------------------------------
(2)
MOVLW A - move the contents of variable A to register W
ADDLW B - ADD the contents of register W with variable B and store the sum in variable B.
