Shop OBEX P1 Docs P2 Docs Learn Events
bytefill function question — Parallax Forums

bytefill function question

DXCDXC Posts: 33
edited 2011-02-22 10:42 in Propeller 1
Hello all,

I want to fill an array (Rel[150]) 1-128 with a value '1' except 0.
Can this be done like below?

bytefill(@Rel+1, 1,128)

or maybe another way?

gr,
Bart

Comments

  • kuronekokuroneko Posts: 3,623
    edited 2011-02-17 02:45
    Looks fine to me, though I'd use bytefill(@Rel[1], 1, 128) myself.
  • DXCDXC Posts: 33
    edited 2011-02-17 04:36
    Thnx for the fast reply.

    So @Rel+1 is the same as @Rel[1]?

    gr,
  • kuronekokuroneko Posts: 3,623
    edited 2011-02-17 04:43
    DXC wrote: »
    So @Rel+1 is the same as @Rel[1]?
    Yes, @Rel is short for @Rel[0] and assuming it's a byte array adding one will get you the address of the 2nd element (index 1). That said, @Rel[1] is actually shorter (less code) than @Rel + 1.
  • Bobb FwedBobb Fwed Posts: 1,119
    edited 2011-02-17 08:29
    And if you switch to a different array size (word or long) you wouldn't have to change the "+1" to "+2"/"+4" (though you would have to change the "bytefill".
  • DXCDXC Posts: 33
    edited 2011-02-18 10:08
    I thought that is it be indeed like that.
    Coded some in assembly and thats the same.
    like rdlong function I have to ad 4 to the pointer to get the next long.

    also nice to here Rel[1] is less code.

    gr,
  • DXCDXC Posts: 33
    edited 2011-02-22 02:04
    also if I want to set 1-128 to 1 I have to use:
    bytefill(@Rel[1], 1,127)

    and not 128 as the count
  • MagIO2MagIO2 Posts: 2,243
    edited 2011-02-22 04:00
    1-128 are 128 elements. If you want to set 128 elements to 1 you have to say bytefill( ..., 1, 128 )

    Maybe you mix that up with index-count. If you define an array like
    byte test[128]
    your index range is from 0 to 127. But you still have 128 elements. If you want to fill that from test[1] up to the end you have to say
    bytefill( @test[1], 1, 127 )

    but here you only want to fill 127 bytes.

    In other words the 3rd parameter is really the number of bytes you want to initialize. It has nothing to do with the index.
  • DXCDXC Posts: 33
    edited 2011-02-22 10:42
    Indeed, as it is named count I thought it counts 127 times.
    But it's not, tested it and as you said is has to be 128.

    gr,
Sign In or Register to comment.