Shop OBEX P1 Docs P2 Docs Learn Events
Does Par[n] compute — Parallax Forums

Does Par[n] compute

Robert TRobert T Posts: 71
edited 2010-05-02 00:40 in Propeller 1
Lets say I have a data structure(VAR or CON) that consists of more than just one number, such as

CON
Constant 1, 2, 3, 4

VAR
Long VariableName[noparse][[/noparse]20]

If I call an assembly language routine and use the address to either one in the call

CogNew(@AssemblyRoutine, @VariableName)

Can I use the statement

mov p1, par[noparse][[/noparse]n] ``where n is the number of variable I wish to access

or do I simply use

mov p1, par

and add to p1 to get the next variable address.

Comments

  • MagIO2MagIO2 Posts: 2,243
    edited 2010-05-02 00:06
    You can't define a constant like you did. One constant only represents one value.
    CON
    theConOne = 1
    theConTwo = 2

    A constant does not have an address, as it does not exist in memory on it's own. It will only 'materialize' in a variable in case you assign the constant to a variable.
    myVarOne := theConOne

    You should see a constant as a text replacement. Wherever you can use a number you can also use a constant.

    With cognew using a PASM address you can pass a value which is then accessible through the special function register called PAR. (The·least significant·2 bits are always zero). As you did it in your example you usually pass an address to a long-alligned memory address. When you use
    mov p1, par
    you do NOT access the first element of the array. You only copy the address of VariableName from PAR to p1. If you want to get the value of the first element you have to read it from HUB RAM using rdlong:
    rdlong p1, par

    The array access operator [noparse]/noparse is not valid for PASM code, so par[noparse][[/noparse]n] won't compile. If you want to access the next element of the array you have to add 4 to par or a copy of par. Whether you use PAR or a copy of PAR depends on whether you need the same PAR again in another iteration through the code or not.

    Post Edited (MagIO2) : 5/2/2010 12:11:02 AM GMT
  • Robert TRobert T Posts: 71
    edited 2010-05-02 00:15
    Thats what I thought. I didn't mean to use CON, I meant to use DAT. The answer is still the same. No array in assembly.

    Thanks
  • Andrey DemenevAndrey Demenev Posts: 377
    edited 2010-05-02 00:40
    MagIO2 said...
    If you want to access the next element of the array you have to add 4 to par or a copy of par. Whether you use PAR or a copy of PAR depends on whether you need the same PAR again in another iteration through the code or not.
    You cannot modify PAR. It is set once cog is started, writing to it changes shadow register, PAR itself stays unchanged
Sign In or Register to comment.