array problem


Closed Thread
Results 1 to 12 of 12

Thread: array problem

  1. #1
    ro37bis's Avatar
    ro37bis Guest

    Angry array problem

    hello guys,
    I need to make some like this:
    ---------------
    array var word [5]
    C var byte

    for c = 0 to 5
    if array[C].highbyte = 0 then ' <- Compiler message: This style array syntax not supported
    gosub Compute
    endif
    next c

    end

    Compute:
    'Do something
    return
    ----------------------
    but the compiler do not support my array style.
    Some idea to solve it?
    tnk in advance.
    Roberto from Italy

  2. #2
    Join Date
    Jul 2003
    Posts
    2,358


    Did you find this post helpful? Yes | No

    Default

    Most things are already somewhere here on the forum... you just need to SEARCH for them...

    http://www.picbasic.co.uk/forum/showthread.php?t=544

  3. #3
    ro37bis's Avatar
    ro37bis Guest


    Did you find this post helpful? Yes | No

    Thumbs up RE: Array problem

    Hi Melanie,
    usefull!!
    Tnk you very much!!!!!!!
    Roberto

  4. #4
    Join Date
    Jan 2006
    Location
    Istanbul
    Posts
    1,185


    Did you find this post helpful? Yes | No

    Default

    Like this ?


    Code:
    array var word [5]
    C var byte
    Temp Var word
    
    
    for c = 0 to 5
       
       Temp = array[C]
       if temp.highbyte = 0 then gosub Compute
    
    next c
    Last edited by sayzer; - 14th September 2006 at 12:13.
    "If the Earth were a single state, Istanbul would be its capital." Napoleon Bonaparte

  5. #5
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    Or maybe
    Code:
    array var word [5]
    C var byte
    
        for c = 0 to 5
            if (array[C]>>8) = 0 then gosub Compute
            next
        end
    
    Compute:
        'Do something
        return
    another method...
    Code:
    array var word [5]
    C var byte
    
        for c = 0 to 5
            if array[C]<=$00FF then gosub Compute
            next
        end
    
    Compute:
        'Do something
        return
    Last edited by mister_e; - 14th September 2006 at 14:13.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  6. #6
    Join Date
    May 2006
    Location
    Del Rio, TX, USA
    Posts
    343


    Did you find this post helpful? Yes | No

    Default

    Roberto, Sayzer and Steve

    Me thinks you will avoid much trouble if the array has 6 elements, or the FOR...NEXT counts from 0 to 4.

    Steve B

  7. #7
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    LMAO! ssshhhhhhut!
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  8. #8
    Join Date
    Jan 2006
    Location
    Istanbul
    Posts
    1,185


    Did you find this post helpful? Yes | No

    Default

    I know that Steve sleeps only a few hrs from late morning to later morning.

    Just like I do.


    Don't know about Roberto's.

    --------------------
    Last edited by sayzer; - 15th September 2006 at 14:17.
    "If the Earth were a single state, Istanbul would be its capital." Napoleon Bonaparte

  9. #9
    ro37bis's Avatar
    ro37bis Guest


    Did you find this post helpful? Yes | No

    Smile thk you for the support

    Hi guys,
    thank you for the support.

    I tested all of your suggestion.
    the Sayzer solution require 34 bytes,
    the 1st Mister_e solution require 83 bytes,
    the 2nd solution require 66 bytes.
    the Melanie idea for solution:
    ---------------
    array var word [5]
    C var byte

    for c = 1 to 9 step 2
    if array.lowbyte(c) = 0 then gosub Compute
    next
    end

    Compute:
    'Do something
    return
    ------------------
    require 35 bytes.

    The winner is:......... Sayzer.

    bye
    Roberto

  10. #10
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    OH! A competition.

    And as usual, I'm too late, oh well. Here's my entry.
    Code:
    <font color="#008000"><b>DEFINE  </b></font><b>NO_CLRWDT 1                   </b><font color="#0000FF"><b><i>; Saves 2 words  :)
    
    </i></b></font><b>array </b><font color="#008000"><b>VAR WORD </b></font>[<b>5</b>] <b>BANK0 SYSTEM 
    
    ArrayStart </b><font color="#008000"><b>CON </b></font><b>EXT
    </b><font color="#000080">@ArrayStart = array + 1               </font><font color="#0000FF"><b><i>; Start at highbyte of element 0
    </i></b></font><b>LastElement </b><font color="#008000"><b>CON </b></font><b>EXT
    </b><font color="#000080">@LastElement = ArrayStart + (4 * 2)   </font><font color="#0000FF"><b><i>; Stop at element 4
    
    </i></b></font><b>FSR </b>= <b>ArrayStart  
    Loop1</b>:
        <font color="#008000"><b>IF </b></font><b>INDF </b>= <b>0 </b><font color="#008000"><b>THEN GOSUB </b></font><b>Compute
        FSR </b>= <b>FSR </b>+ <b>2
    </b><font color="#008000"><b>IF </b></font><b>FSR </b>&lt; <b>LastElement </b><font color="#008000"><b>THEN </b></font><b>Loop1
    </b><font color="#0000FF"><b><i>;----------------------------------
    
    </i></b></font><b>Compute</b>:
    <font color="#0000FF"><b><i>'Do something
    </i></b></font><font color="#008000"><b>RETURN</b></font>
    21 words<hr>
    Or going the ASM route
    Code:
    <font color="#000000"><b>array </b><font color="#008000"><b>VAR WORD </b></font>[<b>5</b>] <b>BANK0 SYSTEM 
    
    </b><font color="#008000"><b>ASM
    </b></font><font color="#000080">ArrayStart = array + 1               </font><font color="#0000FF"><b><i>; Start at highbyte of element 0
    </i></b></font><font color="#000080">LastElement = ArrayStart + (4 * 2)   </font><font color="#0000FF"><b><i>; Stop at element 4
        </i></b></font><font color="#000080">movlw    ArrayStart
        movwf    FSR                     </font><font color="#0000FF"><b><i>; FSR = ArrayStart
    </i></b></font><font color="#000080">Loop1
        movf     INDF, W                
        btfsc    STATUS, Z               
        call     _Compute                </font><font color="#0000FF"><b><i>; if INDF = 0 then gosub Compute
        </i></b></font><font color="#000080">movlw    2
        addwf    FSR, F                  </font><font color="#0000FF"><b><i>; FSR = FSR + 2
        </i></b></font><font color="#000080">movlw    LastElement
        subwf    FSR, W
        btfss    STATUS, C
        goto     Loop1                   </font><font color="#0000FF"><b><i>; if FSR &lt; LastElement then Loop1
    </i></b></font><font color="#008000"><b>ENDASM    
    </b></font><font color="#0000FF"><b><i>;----------------------------------
    
    </i></b></font><b>Compute</b>:
    <font color="#0000FF"><b><i>'Do something
    </i></b></font><font color="#008000"><b>RETURN</b></font>
    13 words
    DT

  11. #11
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    Neat!
    I wasn't aware that we could access to FSR and INDF directly... thanks!

    i just hope our friend don't use 18Fs or some 12 bit core
    Last edited by mister_e; - 16th September 2006 at 20:44.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  12. #12
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    >> i just hope our friend don't use 18Fs or some 12 bit core

    I had the same concerns, but after compiling the "Melanie idea for solution" example(post 9), I found that it was 35 words instead of bytes. So I knew he was using a 16F (or C).

    And yup, you can directly access any register with PBP. They are all defined in the PIC14EXT.BAS file in the PBP folder.
    <br>
    DT

Similar Threads

  1. Bits, Bytes Words and Arrays
    By Melanie in forum FAQ - Frequently Asked Questions
    Replies: 24
    Last Post: - 14th June 2016, 07:55
  2. Simple Array Demo
    By Archangel in forum Code Examples
    Replies: 5
    Last Post: - 15th February 2010, 04:46
  3. Problem with ASM IRQ using FSR0 on PIC18F252
    By mytekcontrols in forum mel PIC BASIC Pro
    Replies: 10
    Last Post: - 11th March 2008, 20:48
  4. Array problem (18F2550)
    By Ronald123 in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 8th January 2008, 18:47
  5. Problem with bit array
    By Dick M in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 12th May 2005, 17:03

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts