Shop OBEX P1 Docs P2 Docs Learn Events
maximum or minimum of an array — Parallax Forums

maximum or minimum of an array

ArchiverArchiver Posts: 46,084
edited 2003-09-03 00:21 in General Discussion
Is there a single PBASIC command that would find the maximum (or
minimum) of a set of values stored sequentially (either in the main
RAM, or preferably in the SPRAM or the EEPROM) of a BS2p?
If not,

would it be possible to add such a command to PBASIC vocabulary in
the future versions?
Thanks
Mohammed

Comments

  • ArchiverArchiver Posts: 46,084
    edited 2003-09-02 23:48
    No. The reason is that array boundaries are NOT enforced by the Stamp;
    in fact the entire BASIC Stamp RAM can be treated like an array without
    even declaring it explicitly. For example.

    colors VAR Byte
    red VAR Colors
    green VAR Byte
    blue VAR Byte

    Since red is overlayed onto the same physical address as colors, and
    green and blue are the same types, they will live in memory in this
    order:

    colors/red, green, blue

    This means you can work with Red, Green, and Blue as named variables, or
    index through them like this:

    FOR idx = 0 TO 2
    colors(idx) = idx
    NEXT

    After this loop, red will be zero, green will be one, and blue will be
    two.

    Another thing to keep in mind is that RAM arrays can be bits, nibs,
    bytes, or words. SPRAM is accessed as bytes and words -- these issue
    complicate creating an internal fuction (that you could certainly code
    in PBASIC). This is not to say that the next-generation Stamp won't
    have such a feature.

    -- Jon Williams
    -- Applications Engineer, Parallax
    -- Dallas Office


    Original Message
    From: mohammedrasiq [noparse]/noparse]mailto:[url=http://forums.parallaxinc.com/group/basicstamps/post?postID=gsSNIOVefYgTutgtEwDYI8PJk9B0XcRbMGRq6VfzXufNbeRswhKUsCYudTdonHK8eUtl0Po0byDLkdWM9CxLvSc]mohammedrasiq@y...[/url
    Sent: Tuesday, September 02, 2003 5:17 PM
    To: basicstamps@yahoogroups.com
    Subject: [noparse][[/noparse]basicstamps] maximum or minimum of an array


    Is there a single PBASIC command that would find the maximum (or
    minimum) of a set of values stored sequentially (either in the main
    RAM, or preferably in the SPRAM or the EEPROM) of a BS2p?
    If not,

    would it be possible to add such a command to PBASIC vocabulary in
    the future versions?
    Thanks
    Mohammed


    To UNSUBSCRIBE, just send mail to:
    basicstamps-unsubscribe@yahoogroups.com
    from the same email address that you subscribed. Text in the Subject
    and Body of the message will be ignored.


    Your use of Yahoo! Groups is subject to
    http://docs.yahoo.com/info/terms/




    This message has been scanned by WebShield. Please report SPAM to
    abuse@p....
  • ArchiverArchiver Posts: 46,084
    edited 2003-09-03 00:21
    Thanks Jon for that explanation!!

    --- In basicstamps@yahoogroups.com, "Jon Williams" <jwilliams@p...>
    wrote:
    > No. The reason is that array boundaries are NOT enforced by the
    Stamp;
    > in fact the entire BASIC Stamp RAM can be treated like an array
    without
    > even declaring it explicitly. For example.
    >
    > colors VAR Byte
    > red VAR Colors
    > green VAR Byte
    > blue VAR Byte
    >
    > Since red is overlayed onto the same physical address as colors, and
    > green and blue are the same types, they will live in memory in this
    > order:
    >
    > colors/red, green, blue
    >
    > This means you can work with Red, Green, and Blue as named
    variables, or
    > index through them like this:
    >
    > FOR idx = 0 TO 2
    > colors(idx) = idx
    > NEXT
    >
    > After this loop, red will be zero, green will be one, and blue will
    be
    > two.
    >
    > Another thing to keep in mind is that RAM arrays can be bits, nibs,
    > bytes, or words. SPRAM is accessed as bytes and words -- these
    issue
    > complicate creating an internal fuction (that you could certainly
    code
    > in PBASIC). This is not to say that the next-generation Stamp won't
    > have such a feature.
    >
    > -- Jon Williams
    > -- Applications Engineer, Parallax
    > -- Dallas Office
    >
    >
    >
    Original Message
    > From: mohammedrasiq [noparse][[/noparse]mailto:mohammedrasiq@y...]
    > Sent: Tuesday, September 02, 2003 5:17 PM
    > To: basicstamps@yahoogroups.com
    > Subject: [noparse][[/noparse]basicstamps] maximum or minimum of an array
    >
    >
    > Is there a single PBASIC command that would find the maximum (or
    > minimum) of a set of values stored sequentially (either in the main
    > RAM, or preferably in the SPRAM or the EEPROM) of a BS2p?
    > If not,
    >
    > would it be possible to add such a command to PBASIC vocabulary in
    > the future versions?
    > Thanks
    > Mohammed
    >
    >
    > To UNSUBSCRIBE, just send mail to:
    > basicstamps-unsubscribe@yahoogroups.com
    > from the same email address that you subscribed. Text in the
    Subject
    > and Body of the message will be ignored.
    >
    >
    > Your use of Yahoo! Groups is subject to
    > http://docs.yahoo.com/info/terms/
    >
    >
    >
    >
    > This message has been scanned by WebShield. Please report SPAM to
    > abuse@p...
Sign In or Register to comment.