Shop OBEX P1 Docs P2 Docs Learn Events
PropBasic - Arrays — Parallax Forums

PropBasic - Arrays

camelot2camelot2 Posts: 54
edited 2010-12-20 09:35 in Propeller 1
hi, I have 2 HUB arrays (HUB1 and HUB2) each with 100 values.
What I want to do is take the first value from HUB1 array and
store it in HUB3 array at address 1 then take the first value
from HUB2 array and store it in HUB3 array at address 2. Then
take the second value from HUB1 array and store it in HUB3 array
at address 3, then take the second value from HUB2 array and
store it in HUB3 array at address 4 and so on.
So the values in HUB1 go into the odd addresses of HUB3 array and
the values in HUB2 go into the even addresses of HUB3 array. I am
lost as to how to do this in PropBasic. Can someone help me, thanks

Comments

  • MagIO2MagIO2 Posts: 2,243
    edited 2010-12-19 12:52
    I can't give you the right code, as I don't know PropBasic, but here is what you can do:
    Simply have 2 index variables, one for HUB1 and HUB2 and one for HUB3.

    HUB3[ idx2 ] := HUB1[ idx1 ]
    idx2 := idx2 + 1
    HUB3[ idx2 ] := HUB2[ idx1 ]
    idx2 := idx2 + 1
    idx1 := idx1 + 1

    Put this piece of code inside of a loop and don't forget to initialize the idx-variables - then you're done.
    Of course you can optimize this a bit by only using idx1. But I'll leave it as a challenge first ;o)
  • camelot2camelot2 Posts: 54
    edited 2010-12-19 13:50
    thanks for the reply Magl02, gee I wish I knew what you are saying
    Could someone please put this in PropBasic code?? - thanks again for any help
  • BeanBean Posts: 8,129
    edited 2010-12-19 16:50
    Here is how I would do it
    DEVICE P8X32A, XTAL1, PLL16X
    FREQ 80_000_000
    
    temp     VAR LONG
    value1   VAR LONG
    value2   VAR LONG
    idx      VAR LONG
    
    HUB1     HUB LONG(100)
    HUB2     HUB LONG(100)
    HUB3     HUB LONG(200)
    
    PROGRAM Start
    
    Start:
      idx = 0
      FOR temp = 0 TO 99
        RDLONG HUB1(temp), value1
        RDLONG HUB2(temp), value2
        WRLONG HUB3(idx), value1, value2
        idx = idx + 2
      NEXT
    END
    

    Bean
  • camelot2camelot2 Posts: 54
    edited 2010-12-20 09:35
    hi Bean, your code works perfectly in my application
    thanks very much. Also thanks for PropBasic its great.

    Happy Holidays - Dave
Sign In or Register to comment.