Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write the rest of the instructions to execute the loop 5 times, assume Wait1 is

ID: 3786248 • Letter: W

Question

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.  

Explanation / Answer

(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.