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

You are given the following short PIC 16F1829 assembly function: How many possib

ID: 3573779 • Letter: Y

Question

You are given the following short PIC 16F1829 assembly function: How many possible return values does this function have? Give an example of a value stored in PORTC that would cause the function to return each of those possible values. Is it possible for the function to execute each of the 4 retlw instructions? If so, explain how, and if not, explain how you would modify the function to make each of those four instructions reachable. Explain what effect each of the following pieces of code would have on I/O port A. Assume you are using the original version of the function F, not your (potentially) modified version from part (b).

Explanation / Answer

F:            movf     PORTC,W             ; move the data of PORTC to register w
                andlw    B ‘00000001’       ;binary 1
                addwf   PCL, F                    ;(add 15 to PCL)
                retlw     B ‘11110000’     ;(240)
                retlw     B ‘00111100’       ;(60)
                retlw     B ‘00001111’       ;(15)
                retlw     B ‘11111111’       ;(255)

Explanation of function

MOVF PORTC, W

Moves the data of PORTC to register w

andlw statement perform logical and operation with binary value 1 and content of w register

addwf statement add the hexadecimal value F i.e.15 in decimal and 00001111 in binary to PCL register i.e. program counter

retlw statement return the corresponding binary statement on which control is transferred on the basis of PCL

How many possible return values does this function have? Give an example of a value stored in PORTC that would cause the function to return each of those possible values.

Ans: There are possible 15 return statements in the function due to the PCL value is F that is equivalent to 15 in decimal. We need to put the b ‘00000001’ value to PORTC to execute the present retlw statement of a function.

Is it possible for the function to execute each of the retlw instruction? If so explain how and if not how would you modify the function to make each of these four instructions reachable.

Ans: It is not possible to execute all the retlw statement given in function. We can modify the function by changing the value of addwf PCL, F statement by replacing F

F:            movf     PORTC,W            
                andlw    B ‘00000001’      
                addwf   PCL,B’00000001’                              
                retlw     B ‘11110000’    
                retlw     B ‘00111100’      
                retlw     B ‘00001111’      
                retlw     B ‘11111111’      

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote