Shop OBEX P1 Docs P2 Docs Learn Events
Record Address, sharing variables — Parallax Forums

Record Address, sharing variables

T ChapT Chap Posts: 4,223
edited 2008-09-28 01:53 in Propeller 1
Hey guys, a few years ago I was working on some stepper code where a new cog was apparently accessing a variable outside itself.

Below is a snippet.

If LONG[noparse][[/noparse]radr] >LONG[noparse][[/noparse]radr + 4]



I cannot remember what the + 4 meant. Obviously the Long at radr X cannot never be larger than the same value X added to 4 , but I cannot recall what this was doing.

Can someone remind me of what this trick might be doing? My only guess is that it is comparing a long @X with some variable 4 places down in memory.

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2008-09-28 01:08
    A long is 4 bytes in length. If you have the address of the first of two longs in "radr", LONG[noparse][[/noparse]radr] gets you the value of the first long while LONG[noparse][[/noparse]radr+4] gets you the value of the second long.
  • tpw_mantpw_man Posts: 276
    edited 2008-09-28 01:10
    What it is doing is adding 4 bytes to radr, most likely accessing a long variable after that. One thing to note is that LONG[noparse][[/noparse]radr] accesses the long at the contents of radr and LONG[noparse][[/noparse]@radr] basically accesses the variable radr.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    I am 1011, so be surprised!


    Advertisement sponsored by dfletch:
    Come and join us on the Propeller IRC channel for fast and easy help!
    Channel: #propeller
    Server: irc.freenode.net or freenode.net
    If you don't want to bother installing an IRC client, use Mibbit. www.mibbit.com
    tongue.gif
  • T ChapT Chap Posts: 4,223
    edited 2008-09-28 01:53
    Yes in the VAR there was

    Long X, Xcurrent

    So it was comparing X against the current position. I am not sure why it wouldn't be written If LONG[noparse][[/noparse]radr1] >LONG[noparse][[/noparse]radr2], since it is getting radr a a parameter passed from the call, could just easily pass both var's. I suppose this was just less wordy method, I am sure I borrowed this, or maybe Mike even wrote this as an example for me some time back.

    It does appear that this was a method to have a parameter in one cog getting accessed by a new cog, so the LONG[noparse][[/noparse]radr]. Although I could have sworn that I just read that variables were not accessible outside an object. In this case, a method starts a new cog MoveX, which relies on the variable X and Xcurrent (Xcurrent written as radr + 4) to know where the stepper is.

    Thanks for the info guys.
Sign In or Register to comment.