Does Par[n] compute
Robert T
Posts: 71
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.
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
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
Thanks