Propeller Assembly: Memory Addressing
I'm trying to make my code a bit more flexible by allowing a caller to specify multiple parameters. I'm, however, as of yet unable to properly address the locations as received through the assembly parameter register (PAR).
Any ideas where I'm going wrong?
Any ideas where I'm going wrong?
CON
ADDRESS_INCREMENT_UNIT = 4
VAR
LONG _id
LONG _resources[4]
PUB Start(pins, samples, rate)
_resources[0] := pins
_resources[1] := samples
_resources[2] := rate
_id := COGNEW(@SETUP, @_resources) + 1
RETURN _id > 1
PUB State
RETURN _resources[3]
PUB Stop
IF _id <= 0
RETURN
COGSTOP(_id~ - 1)
DAT
ORG
SETUP MOV resources, PAR ' Move array address into writable register
RDLONG sample_mask, resources ' Read array index 0
ADD resources, #ADDRESS_INCREMENT_UNIT ' Increment to next array element
RDLONG sample_count, resources ' Read array index 1
ADD resources, #ADDRESS_INCREMENT_UNIT ' Increment to next array element
RDLONG sample_rate, resources ' Read array index 2
ADD resources, #ADDRESS_INCREMENT_UNIT ' Increment to next array element
MOV current_state, resources ' Retain address for future results
MOV OUTA, sample_mask ' Prepare for reading
MOV wait_time, CNT '
ADD wait_time, wait_delay '
:NEXTSTATE MOV current_sample, sample_mask ' Prepare for button state reading
MOV current_count, sample_count '
:NEXTSAMPLE OR DIRA, sample_mask ' Sample button state sample_count times
ANDN DIRA, sample_mask '
WAITCNT wait_time, wait_delay '
ANDN current_sample, INA '
DJNZ current_count, #:NEXTSAMPLE '
WRLONG current_sample, current_state ' Write array index 3 with current button state
JMP #:NEXTSTATE ' Do it again!
current_count RES 1
current_sample RES 1
current_state RES 1
resources RES 1
sample_count RES 1
sample_mask RES 1
sample_rate RES 1
wait_delay RES 1
wait_time RES 1

Comments
But I am not able to follow the rest of it. Maybe to tired.
Enjoy!
Mike
IF _id <= 0
does not what you want
use
IF _id =< 0
same with >= ... never (until you want that) ... use =>
:=
<=
>=
+=
-=
el.al.
are all changing the first operant
Enjoy
Mike
Thank you both for your help.