Shop OBEX P1 Docs P2 Docs Learn Events
ASM question using rdlong/wrlong.... — Parallax Forums

ASM question using rdlong/wrlong....

Chris_DChris_D Posts: 305
edited 2009-04-11 16:49 in Propeller 1
Hi guys,

I am in a bit of a snag with my ASM learnings...

I have a number of variables in HUB memory that I need to access from with an ASM routine in a COG.· So far, I was able to get the pointer set up and passed through to the cog and I was able to write to it ...

······················· mov···· Hub_Index, par············· 'Makes a copy of the pointer which is passed as a parameter
······················ 'other lines of code......
······················· wrlong· A1P_AbsPos,Hub_Index··'copies A1P_AbsPos into the·hub variable pointed to by Hub_index

I remember seeing somewhere and can't find it again, some sort of trick that allowed easy access to other variables...

····· wrlong· A1P_AbsPos,Hub_Index··+ #4· 'Something like this I think?

I suspect it was easy and similar to shown above, but sure could use a bit of explanation and clarification.

Thanks!

Chris
·

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2009-04-11 15:41
    You have to actually change Hub_Index like this:
       mov Hub_Index,par   ' Copy PAR to a temporary location
       rdlong temp,Hub_Index   ' Get 1st long value
       add Hub_Index,#4   ' Change address
       rdlong A1P_AbsPos,Hub_Index   ' Get 2nd long value
       add Hub_Index,#4   ' Change address
       rdlong A2P_AbsPos,Hub_Index   ' Get 3rd long value
    


    It works the same with wrlong
  • Chris_DChris_D Posts: 305
    edited 2009-04-11 15:58
    Ah yes,· that looks familiar!

    Now, at somepoint I need to reset the Hub_index back to the original setting.· Will the par retain its value?

    If so, all I need to do then is simply repeat the mov·Hub_Index,par instruction to get back to my base pointer value.

    Thank Mike!

    Chris
  • Chris_DChris_D Posts: 305
    edited 2009-04-11 16:01
    Arghhh,· need details on one more thing...



    When I declare these variables, I assume I have to make sure they are listed like this·?

    · Long A1_Pos
    · Long A2_Pos
    ····... and so on all the way through my list.

    What I am trying to clarify is that the order in which I delcare them establishes their memory location relative to the first one.

    Chris

    ·
  • JonnyMacJonnyMac Posts: 9,194
    edited 2009-04-11 16:02
    I'm pretty new at this, too, and have been working through similar struggles (remembering RDxxxx an WRxxxx instead of MOV when dealing with hub RAM). I have a program I'm working on now that is for bi-color LEDs; the first parameter is the color mode, the next two are times for the two colors (to create blinking, etc.). The entry into my code looks like this:

    asm                     mov     tmp1, par                       ' address of structure
                            mov     modeAddr, tmp1                  ' mode address
                            add     tmp1, #4
                            mov     phase0Addr, tmp1                ' phase 0 ms timing address
                            add     tmp1, #4
                            mov     phase1Addr, tmp1                ' phase 1 ms timing address
                            add     tmp1, #4
                            rdlong  gPin, tmp1                      ' read green pin #
                            add     tmp1, #4
                            rdlong  rPin, tmp1                      ' read red pin #
    


    As you can see, I'm saving the hub address of the led mode and the timing durations for each phase -- this lets me get to them later to check for changes. Here are the varaible declarations at the end of the ASM section:

    tmp1                    long    0
    
    modeAddr                long    0
    phase0Addr              long    0
    phase1Addr              long    0
    gPin                    long    0
    rPin                    long    0
    


    I only need to read the green and red pin #s once so their address in the hub is not required.
  • Mike GreenMike Green Posts: 23,101
    edited 2009-04-11 16:03
    PAR will retain its value. In fact, it's read-only as far as the cog is concerned. It's set by the COGNEW/COGINIT instruction only.
  • Chris_DChris_D Posts: 305
    edited 2009-04-11 16:49
    Thanks guys,

    That should do it, I on may way to dig meself into the next hole!

    Chris
Sign In or Register to comment.