MSP430 Microcontroller Quiz on “Functions and Subroutine”.
1. Which instruction is used to call functions?
a) MOV
b) GO
c) CALL
d) All of the mentioned
Answer: c
Clarification: CALL instruction is used for going to a particular address in MSP430. It actually causes the pointer to jump at a particular address and push the current address of the PC to the stack.
2. ret instruction is used for _________
a) determining the end of the program
b) for returning back from the subroutine to the main program
c) for transferring data from one place to another
d) none of the mentioned
Answer: b
Clarification: Ret instruction is basically used for returning back from a subroutine. It actually pops the top address from the stack and moves that address to its PC, so that it now returns to the main program and continue the execution normally.
3. According to conventions being followed, R12 to R15 are used for _________
a) parameter passing
b) preserved for call
c) all of the mentioned
d) none of the mentioned
Answer: a
Clarification: According to the conventions, R12 to R15 are used for parameter passing and hence are not preserved for the call.
4. We can store the temporary results across a call instruction with the help of which of the following registers
a) R1-R4
b) R4-R11
c) R12-R15
d) All of the mentioned
Answer: b
Clarification: Temporary results are stored by the registers R4-R11.
5. Can we allocate variables on the stack?
a) yes
b) no
c) cant be said
d) depends on the conditions
Answer: a
Clarification: Yes, we can allocate the variables on the stack, it is a very effective way of storing the variables.
6. Which registers are reserved for passing the parameters to a subroutine and then returning the final result?
a) R1-R4
b) R4-R11
c) R12-R15
d) All of the mentioned
Answer: c
Clarification: Originally, R12-R15 registers are reserved for passing the parameters to a subroutine and then returning the final result.
7. What actually is the order of stack frame for a parameter to pass to a subroutine?
a) parameter passed to a subroutine
b) return address
c) saved copies of registers(R4-R11)
d) all of the mentioned
Answer: d
Clarification: All the steps i.e. parameter passed to a subroutine, return address, saved copies of registers(R4-R11), local variables in subroutines are required for passing a parameter to a subroutine.
8. When any subroutine is called, then the first value of stack will be
a) value of PC
b) the return address
c) none of the mentioned
d) both are one and the same things
Answer: d
Clarification: When any subroutine is called then the first place of the stack will be filled with the return address, or the address of the PC so that the pointer may return back to its appropriate place after the return instruction of the subroutine.
9. Which of the following instruction/s is/are used to return back to the main program after the subroutine is completed?
a) ret
b) reti
c) ret and reti
d) none of the mentioned
Answer: c
Clarification: For returning back from the subroutine, both ret and reti can be used, the main difference between the two is that reti just resets the interrupt flag before the return, so that the interrupt can occur again.
10. Is the approach of making subroutines effective or not?
a) yes
b) no
c) cant be said
d) depends on the conditions
Answer: a
Clarification: The approach of making subroutine is indeed very effective, as with its help we don’t need to retrace/write a particular set of codes again and again. It makes our approach modular.