View previous topic :: View next topic |
Author |
Message |
syndetic1
Joined: 02 Jan 2007 Posts: 76
|
Posted: Tue Feb 01, 2022 11:22 pm Post subject: Read and Print Program Counter |
|
|
Hi guys,
How can I read the program counter and print it out?
Thanks,
(BASCOM-AVR version : 2.0.8.5 ) |
|
Back to top |
|
|
MWS
Joined: 22 Aug 2009 Posts: 2262
|
Posted: Wed Feb 02, 2022 12:33 am Post subject: |
|
|
You was not replying as I've answered your previous question, it's annoying not to know whether it worked.
Mind to explain why I should answer this one?
Maybe it helps if you explain at least why you think to need to know the PC's value. |
|
Back to top |
|
|
syndetic1
Joined: 02 Jan 2007 Posts: 76
|
Posted: Wed Feb 02, 2022 1:14 am Post subject: |
|
|
MWS wrote: | You was not replying as I've answered your previous question, it's annoying not to know whether it worked.
Mind to explain why I should answer this one?
Maybe it helps if you explain at least why you think to need to know the PC's value. |
This is a stepping stone to solving my other problem with the boot loader.
I am not sure if the boot loader is being loaded in the right place in memory.
In my other forum post, you mentioned commenting out the two error lines and I had already done that and mentioned that in my original post in tat it compiled but does not transfer control to the user program. SO before I went back on that thread, I wanted to check out in more detail what was happening if that makes sense. This is the quote from the other thread
Quote: | If I comment out the two lines, then it compiles and I can program it in and the micro boots into the boot loader.
BUT
If I then use the boot loader to program my user program, the boot loader does not transfer control to my program but re enters the boot loader. It's as if there is a problem with
Goto _reset 'goto the normal reset vector at address 0
I think it's not going to address zero and probably because the rampz bt has not been changed. Maybe it is jumping to address $8000 ??? |
|
|
Back to top |
|
|
MWS
Joined: 22 Aug 2009 Posts: 2262
|
Posted: Wed Feb 02, 2022 1:48 am Post subject: |
|
|
syndetic1 wrote: | In my other forum post, you mentioned commenting out the two error lines |
That's not correct.
I've suggested to put exclamation marks '!' in front of the two assembler opcodes, as these were missing and responsible for the compiler errors.
About the PC, it is not directly accessible.
One can find out like that:
Code: | Dim PCtr as Word
Dim Rz as Byte
' ...
!CALL Dummy
Dummy:
!POP R24
!POP R25
!STS {PCtr + 0}, R24
!STS {PCtr + 1}, R25
!LDS R24, rampz
!STS {Rz}, R24 |
Not tested, it may be that R25 needs to be POP'd first. |
|
Back to top |
|
|
syndetic1
Joined: 02 Jan 2007 Posts: 76
|
Posted: Wed Feb 02, 2022 2:06 am Post subject: |
|
|
Quote: | That's not correct.
I've suggested to put exclamation marks '!' in front of the two assembler opcodes, as these were missing and responsible for the compiler errors. |
Ahh oops. My bad. I read exclamation marks as comment single quote.
I will go try that.
Thank you for clarifying. |
|
Back to top |
|
|
MWS
Joined: 22 Aug 2009 Posts: 2262
|
Posted: Wed Feb 02, 2022 10:51 am Post subject: |
|
|
MWS wrote: | Not tested, it may be that R25 needs to be POP'd first. |
But this is tested:
Code: | $Regfile="xm128a1def.dat"
$Crystal=4000000
$hwstack=40
$swstack=16
$framesize=32
Dim PCtr as Word
Dim Rz as Byte
getPC:
!LDS R22, SREG ' ASM code retrieves PC of this point
!CLI
!CALL Dummy
Dummy:
#if _romsize > 65536
!POP R23 ' a CALL pushes also rampz to stack in multi-page controllers
#endif
!POP R25
!POP R24
!SBIW R24, 5
!STS {PCtr + 1}, R25
!STS {PCtr + 0}, R24
#if _romsize > 65536
!STS {Rz}, R23
#endif
!STS SREG, R22
Print Hex(PCtr)
Print Hex(Rz)
' for single page (<= 65536 flash-bytes) controllers LoadLabel()
' is more simple, but returns only word addresses, thus it does not
' work for controllers like XMega with more pages of flash
PCtr = LoadLabel(getPC) / 2
Print Hex(PCtr)
end |
|
|
Back to top |
|
|
syndetic1
Joined: 02 Jan 2007 Posts: 76
|
Posted: Fri Feb 04, 2022 12:08 am Post subject: |
|
|
Hi MWS,
You are a champion. All working great. Thanks for your patience. Sorry I misread the exclamation marks as commenting it out.
Frank |
|
Back to top |
|
|
MWS
Joined: 22 Aug 2009 Posts: 2262
|
Posted: Fri Feb 04, 2022 2:19 pm Post subject: |
|
|
Good to hear you've succeeded. |
|
Back to top |
|
|
|