Shop OBEX P1 Docs P2 Docs Learn Events
Propeller Assembly: Memory Addressing — Parallax Forums

Propeller Assembly: Memory Addressing

blfblf Posts: 6
edited 2014-04-06 07:13 in Propeller 1
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?
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

  • msrobotsmsrobots Posts: 3,709
    edited 2014-04-05 23:03
    Your handling of par and the addresses of _resources[0...3] looks good to me.

    But I am not able to follow the rest of it. Maybe to tired.

    Enjoy!

    Mike
  • msrobotsmsrobots Posts: 3,709
    edited 2014-04-05 23:07
    oh.

    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
  • kuronekokuroneko Posts: 3,623
    edited 2014-04-06 04:48
    @blf: wait_delay is effectively undefined (10sec @80MHz), did you mean to use sample_rate? Also, in the start method you use _id > 1, why not => 1 (_id may be 1 after all)?
  • blfblf Posts: 6
    edited 2014-04-06 07:13
    @kuroneko: Right again! I can't believe I didn't see that before. :tongue:

    Thank you both for your help.
Sign In or Register to comment.