So I'm programming a simple Call function for the MSP430FG4168. And it's working perfectly, except when it comes time to RETURN to the caller, the function simply dumps me back at the beginning of the callee function.
It's a multiply function that takes the values in R13 and R14.
Here's the Function file code:
#include "MSP430.h"
Extern main ;allows the function to be aware of main
PUBLIC mult
zero DB 0;
RSEG CODE
mult:
PUSH R7; store the value of R7 on the stack for future reference
CLR R7
MOV R14, R7; R14's value will be used as a counter. R13 will be added the number of times specified in R14 and the final value will be stored in R14.
CLR R14
DEC R7
f_loop:
ADD R13, R14
DEC R7
CMP zero, R7
JGE f_loop;
f_end:
POP R7; bring the value of R7 BACK from the stack.
RET
END
"RET" is where my problem is. Instead of returning me to my caller, it brings me back to the beginning of mult. What's going on?
You're probably somehow messing up the caller's set of registers, or something like a ISR messes up the stack (SP):
RET
is not really an 430 instruction, but implemented asMOV @SP+,PC
, and the same goes forPOP
(which isMOV @SP+,destination
).