Shop OBEX P1 Docs P2 Docs Learn Events
Redefinition of Two Bytes as a Word Variable in SX/B? — Parallax Forums

Redefinition of Two Bytes as a Word Variable in SX/B?

Sparks-R-FunSparks-R-Fun Posts: 388
edited 2006-12-29 19:40 in General Discussion
Does anyone know what I need to do to redefine two existing byte variables for use as a word variable using SX/B? The goal, of course, is to make maximal use of variable space.

For example, if I have the following:
Temp1 var byte
Temp2 var byte


What must I do to declare Temp12 as a word variable occupying the same memory space as Temp1 and Temp2 combined?

- Sparks

Comments

  • JonnyMacJonnyMac Posts: 9,071
    edited 2006-12-29 18:05
    Yes, make your declaration a word so that SX/B knows how to deal with it as a 16-bit value. You can get to the constituent bytes after the declaration.

    tmpW1    VAR    Word
    



    Will actually define two bytes that you have access to:

    tmpW1_LSB
    tmpW1_MSB
  • Sparks-R-FunSparks-R-Fun Posts: 388
    edited 2006-12-29 18:40
    JonnyMac,

    Declaring the word variable first before the shared byte variables was the trick I was seeking! Thank you.

    - Sparks
  • BeanBean Posts: 8,129
    edited 2006-12-29 19:40
    Sparks,
    In many cases a single element array can be used too.

    temp1 VAR Byte (1)
    temp1(0) = 5

    Arrays are stored differently than regular variables (even single element arrays). So there can be many more of them. They won't work in very case thought (like as a FOR...NEXT control variable).

    Bean.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Cheap used 4-digit LED display with driver IC·www.hc4led.com

    Low power SD Data Logger www.sddatalogger.com
    SX-Video Display Modules www.sxvm.com
    Stuff I'm selling on ebay http://search.ebay.com/_W0QQsassZhittconsultingQQhtZ-1

    "USA Today has come out with a new survey - apparently, three out of every four people make up 75% of the population." - David Letterman
Sign In or Register to comment.