This message contains an entire topic ported from a separate forum. The original message and all replies are in this single message. We have seeded this new forum with selected information that we expect will be of value to you as you search for answers to your questions.
Posted: Fri Jun 3, 20054:51 pm
I am using the MC9S12E128 board. How would I store the PC into a memory location? I've been trying to use MOVW or LDD and STD but I've been unsuccessful. It seems like a simple thing to do but I'm failing.
Posted: Fri Jun 3, 20056:08 pm
Posted: Fri Jun 3, 20056:12 pm
Or more simply to save the PC after the call
Posted: Fri Jun 3, 20056:15 pm
Posted: Fri Jun 3, 20057:38 pm
Or to save the function call:
Puts the location of the leax into X. You can should be able to use an expression "Symbol-*-2" to get the address of a symbol in the program.
Posted: Fri Jun 3, 20058:01 pm
What about an inline solution:
Then D has the value
Posted: Fri Jun 3, 20059:43 pm
> What about an inline solution:
> jsr *
There are two problems with that. First, jsrs are absolute. If your code is using absolute addresses, the assembler already knows the address of everything, so there is no need to determine PC at run time. Do "ldd #label" instead.
Second, "*" points to the start of the instruction, so "jsr *" goes into an infinite loop until it overflows the stack and dies.
You could solve both problems with bsr:
bsr label ; 4 cycles
puld ; 3 cycles
The leax/leay solution is quicker at only 2 cycles, and the built-in addition can point to the thing you actually need the address of rather than the address of the instruction obtaining the PC value.
leax label,pcr ; Note "pcr", not "pc" -- assembler then
; does the relative-address math for us!
Note that it's legal to use ",pc" and ",pcr" in all instructions that support indexed addressing (such as ",x"), so there may be no need to explicitly transfer PC to another register.
Posted: Fri Jun 3, 200511:27 pm
Thanks for fixing my idea since I hadn't thought much about it. I do
like the leax idea better, but hadn't seen it before.