Shop OBEX P1 Docs P2 Docs Learn Events
SX/B: Variable number of subroutine parameters — Parallax Forums

SX/B: Variable number of subroutine parameters

geekythinggeekything Posts: 53
edited 2006-08-22 23:19 in General Discussion
Today's question:

I have a need to pass a variable number of parameters to a subroutine. The valid data range for each parameter is 0x00 through 0xFF, so I can't use a "padding" parameter and maintain the ability to send four bytes (some commands are four bytes long).

I was happy to see there's a variable that contains the number of parameters passed to a subroutine -- but the SX/B compiler complains when I try and pass less than four parameters with "invalid number of paremeters".

Is there anyway to do what I want? There's no null in SX/B AFAIK?

Thanks!

-marc

Comments

  • BeanBean Posts: 8,129
    edited 2006-08-21 21:06
    You need to define your sub like

    MySub SUB 0,4 ' zero is minimum number of parameter, 4 is maximum number of parameters

    Bean.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Cheap 4-digit LED display with driver IC·www.hc4led.com

    Low power SD Data Logger www.sddatalogger.com

    "You're braver than you believe, stronger than you seem, and smarter than you think" Christopher Robin to Pooh
    ·
  • geekythinggeekything Posts: 53
    edited 2006-08-21 21:08
    D'oh! I'm slightly embarassed now as that's documented! :-o

    Thanks for the quick response! [noparse]:)[/noparse]

    -marc
  • BeanBean Posts: 8,129
    edited 2006-08-21 23:14
    Just remember that if you pass any WORD variables, they count as two.

    Bean.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Cheap 4-digit LED display with driver IC·www.hc4led.com

    Low power SD Data Logger www.sddatalogger.com

    "You're braver than you believe, stronger than you seem, and smarter than you think" Christopher Robin to Pooh
    ·
  • geekythinggeekything Posts: 53
    edited 2006-08-22 01:53
    Bean,

    That was 'remembered'; but thanks for pointing it out. smile.gif

    Am I right in thinking you're 'responsible' for the SX/B compiler? If I may be so bold, as a design request, going to eight (8) passable parameters for a function/sub-routine would really be useful.

    BTW...SX/B rocks! A very good progression for those of use used to Stamps. Passing of parameters, interrupts, better I/O access...

    -marc
  • BeanBean Posts: 8,129
    edited 2006-08-22 02:06
    Marc,
    · Guilty...

    · The 4 parameter were "designed-in" because some of the high-level commands need 4 bytes of tempory storage.
    · To have 8 parameter bytes would decrease the variable space by 4 bytes. Not good.
    · But you can pass an array name as a single byte parameter and access as many elements as you need. Using the __RAM() virtual array.
    · Just ask if you want an example.
    P.S. Thanks for the kind words about the compiler. I will forward them to Ken [noparse];)[/noparse]

    Bean.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Cheap 4-digit LED display with driver IC·www.hc4led.com

    Low power SD Data Logger www.sddatalogger.com

    "You're braver than you believe, stronger than you seem, and smarter than you think" Christopher Robin to Pooh
    ·
  • geekythinggeekything Posts: 53
    edited 2006-08-22 16:48
    Bean,

    An example of passing the array would be great! Thanks!

    -marc
  • BeanBean Posts: 8,129
    edited 2006-08-22 23:19
    Here ya go...

    Bean.


    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Cheap 4-digit LED display with driver IC·www.hc4led.com

    Low power SD Data Logger www.sddatalogger.com

    "You're braver than you believe, stronger than you seem, and smarter than you think" Christopher Robin to Pooh
Sign In or Register to comment.