Shop OBEX P1 Docs P2 Docs Learn Events
SX/B and array — Parallax Forums

SX/B and array

TransistorToasterTransistorToaster Posts: 149
edited 2006-08-23 11:32 in General Discussion
Hello,
I'm looking for an effcient way to handle a byte array in SX/B. It is not for a lookup table. The goal is to have easily compilable high level code.

Can I replace the below code

array1 var byte(16)
ptr1 var byte
x var byte
i var byte
ptr1 = array1
ptr1=ptr1+i
get ptr1, x

with something like array1 ?
Frank

Comments

  • BeanBean Posts: 8,129
    edited 2006-08-22 23:07
    Frank,
    Use the virtual array __RAM() like so:

    array1 var byte(16)
    ptr1 var byte
    x var byte
    i var byte
    
     
    ptr1 = array1
    
    x = __RAM(ptr1)
    


    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
    ·
  • TransistorToasterTransistorToaster Posts: 149
    edited 2006-08-22 23:46
    HI,
    Nice to hear from you again. Is there anything with built in indexing?

    N.B. The previous post seems to have lost the index...
    >with something like array1(i) ?

    Frank
  • BeanBean Posts: 8,129
    edited 2006-08-22 23:58
    Frank,
    I don't follow what you mean by "Is there anything with built in indexing?".
    What exactly is it you want to do ?

    Array names are just constants into the __RAM() array. So array1(5) basically gets translated into __RAM(array1+5) by the compiler.

    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
    ·
  • TransistorToasterTransistorToaster Posts: 149
    edited 2006-08-23 05:15
    Hi Bean,
    I've been doing assembly for 10+ years. I agree that the declaration array1 var byte(16) assigns the address of the first element of array1 and that __RAM(array1+5) is absolute addressing, with, as you said, just constants.

    I am not looking for indirect addressing , which is pretty much the first piece of code I wrote. (OK, we don't use that term for non-assembly languages)

    I'd like to do in SX Basic array1( i), where i is a variable.

    In RISC assembly with no absolute indexed support, it should be quite ugly and look like
    mov fsr, #i ;2cc pseudo-instruction
    mov fsr, ind ;2cc pseudo-instruction
    add fsr, #array ;result in IND = array1(i).

    Frank
  • BeanBean Posts: 8,129
    edited 2006-08-23 11:32
    Frank said...
    I'd like to do in SX Basic array1( i), where i is a variable.
    Okay, now I'm really confused...

    In SX/B you CAN do:
    x = array1(i)
    

    Now if i is a WORD, you'll need to use:
    x = array1(i_LSB)
    

    Other than that, keep beating me over the head until you get what you want. I'm a little lost (but it's early, and I haven't had my Mt. Dew yet).

    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.