Shop OBEX P1 Docs P2 Docs Learn Events
PC -- Program Counter — Parallax Forums

PC -- Program Counter

LustInBlackLustInBlack Posts: 22
edited 2008-03-13 13:27 in Propeller 1
Yep, is there a way to get the value of the PC !?

I know of a way, but a direct way is possible!???

I could do a jumpret and get it from there, but that sounds like x86: call Bob Bob: pop eax (where eax is the EIP value)

I didn't see any reference to PC, looks like I didn't read correctly, or we don't have access to this Register...


I see some use with the PC, it is surely COG dependant, then, we could use this value as a synchronizer ...

If two cogs run the same exact code, they could wait for PC and continue what they are doing..
With relative displacement of PC, cogs could be synchronized in different phase..
Sounds like CNT, however, CNT is more volatile I believe, since HUB operations can happen, and code
isn't necessarily executed at the same exact time (resolution).


Also, I really miss the sbi and cbi instructions from AVR, is there some useful instruction that can be use to replace them!?

I just do "OR" and "AND" instruction to replace them, but I don't like it that much, I need to reserve longs for pin
assignments....

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2008-03-13 04:49
    There's no direct access to the PC. You can store it with the JMPRET instruction and you can load it with any jump instruction.

    There is no equivalent to the sbi and cbi instructions. All bit access you have to do with 32 bit words. OR and ANDN would be the closest things, but, as you mentioned, you do need a mask word. If you're lucky (or careful), you can use the low order 9 bits and an immediate mask.
  • potatoheadpotatohead Posts: 10,260
    edited 2008-03-13 04:57
    I'm really curious why you want it!

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Propeller Wiki: Share the coolness!

    Chat in real time with other Propellerheads on IRC #propeller @ freenode.net
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2008-03-13 05:03
    The easiest way to get the current value of PC into a register is:

            MOV     Addr,#$
    
    
    


    This is cheating, of course, since "$" is a compile-time constant. But since the Propeller doesn't do relative addressing, the code is unlikely ever to execute from other than its absolute assembled location. Even in the future, when relocatable blocks of code are linked in a separate step, the linker should fill in the value of "$".

    -Phil
  • LustInBlackLustInBlack Posts: 22
    edited 2008-03-13 05:19
    While it's true that the PC will be the current line of execution, thus, #$ could do the job..

    My idea is : send the PC on the HUB with a wrlong instruction to signal other COGS where I am currently executing instructions..

    For example, I have COG #1 that runs at PC 40. COG #2 executes at PC44 (same code) ..

    I want them to sync together, if the instruction waitcogpc(1, #44) existed, this could synchronize my COG ..

    .. There are many different ways to synch cogs, but I feel this would be the most efficient..

    For now, I would do it, inefficient, using wrlong in shared variables..
    Poking the variable with a rdlong in RAM each start of loop to see where other cogs are situated..
    Wait for slowest cogs, or synch accesses between cogs...

    Where CNT can synch cogs, it will fail on conditions and hub operations, where the synch will be lost..
    It's like a delta, where you need to offset the error to get in synch..

    PC will not, it will tell you (a cog) exactly where you need to be for synch operation..
  • hippyhippy Posts: 1,981
    edited 2008-03-13 13:27
    An alternative would be to use an I/O line from each Cog. As the output would be wired-OR from all Cogs each could set their line when not at the marker and clear it when they reach the marker, only when the line then became low would they all indicate they were synchronised.
Sign In or Register to comment.