Shop OBEX P1 Docs P2 Docs Learn Events
Extracting Byte Variable from a Word Variable — Parallax Forums

Extracting Byte Variable from a Word Variable

John CoutureJohn Couture Posts: 370
edited 2008-07-22 03:55 in General Discussion
Hey all,

In the SX/B·help manual it says you can extract a byte variable from a word variable.· To wit:
==============================
Word variables have an additional assignment option with two byte values (variables or constants):
wordVar = lsbValue, msbValue==================================If I call a subroutine an immediately store the word variable,
what is the syntax for getting the lsb? (I know it is going to
be painfully simple its just that the manual does not give an example.===============================tempW1 = __WPARAM12····' get string address
templsb = tempW1.lsb ' doesn't work===============================

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
John J. Couture

San Diego Miramar College

Comments

  • ZootZoot Posts: 2,227
    edited 2008-07-22 00:51
    WordVarName_LSB ' = low byte of word variable "WordVarName"
    WordVarName_MSB ' = high byte of word variable "WordVarName"

    ByteVarName = WordVarName_LSB ' move lower byte into byte variable "ByteVarName"

    If you view the list file generated from your SX/B code, you will see where all the variable constants (register addresses) are set up -- any Word variable will automatically create variables for the _LSB and _MSB byte of the word.

    There are other ways of accessing bytes of defined Words, arrays, etc., too. Check the SX/B and SX Manuals for more.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    When the going gets weird, the weird turn pro. -- HST

    1uffakind.com/robots/povBitMapBuilder.php
    1uffakind.com/robots/resistorLadder.php
  • ZootZoot Posts: 2,227
    edited 2008-07-22 00:55
    P.S. -- in the case of SX/B functions/subroutines, any bytes passed are always available as byte or word constructs, e.g.

    tempW1 = __WPARAM12 ' get string address
    templsb = tempW1_LSB '
    'or
    templsb = __PARAM1 ' first byte of all params, a.k.a. lower byte of __WPARAM12

    See SX/B documentation for full list of accessible parameter bytes, words, and parameter count.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    When the going gets weird, the weird turn pro. -- HST

    1uffakind.com/robots/povBitMapBuilder.php
    1uffakind.com/robots/resistorLadder.php
  • John CoutureJohn Couture Posts: 370
    edited 2008-07-22 03:55
    Thank you Zoot, that worked!

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    John J. Couture

    San Diego Miramar College
Sign In or Register to comment.