Shop OBEX P1 Docs P2 Docs Learn Events
BS2 Nibbles for SX/B ?? How can it be done. — Parallax Forums

BS2 Nibbles for SX/B ?? How can it be done.

T&E EngineerT&E Engineer Posts: 1,396
edited 2007-03-24 15:44 in General Discussion
I have a BS2 program I am trying to convert over to SX/B. However, it uses nibbles. I thought there was a _LSB and _MSB command variable that can be used but I think that may only work on WORDs (down to bytes - not nibbles).


'BS2 code
secs············ VAR···· Byte··················· ' seconds
secs01········· VAR···· secs.LOWNIB
secs10········· VAR···· secs.HIGHNIB


I tried in SX/B the following - errors (as expected):

secs············ VAR···· Byte··················· ' seconds
secs01········· VAR···· secs_LSB
secs10········· VAR···· secs_MSB


What is the equivalent in SX/B?

Comments

  • T'SaavikT'Saavik Posts: 60
    edited 2007-03-24 06:27
    I'm a total noob here, but maybe try this out to get at the bits tell the pro's wake up and tell you the better way:

    secs0001 = secs.0
    secs0010 = secs.1
    secs0100 = secs.2
    secs1000 = secs.3

    Checkout the "SX/B Defintions" chapter in the SX/B online help.
  • BeanBean Posts: 8,129
    edited 2007-03-24 12:02
    SX/B doesn't have a nibble variable type. Neither does the propeller.
    The nibble is not a standard variable type, I believe it was used on the BS2 to save RAM.

    You'll have to seperate the values in the code:

    GetSecs
    Secs01 = Secs AND $0F
    Secs10 = Secs >> 4

    Bean.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    "Educate your children to self-control, to the habit of holding passion and prejudice and evil tendencies subject to an upright and reasoning will, and you have done much to abolish misery from their future and crimes from society"

    Benjamin Franklin
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    www.hittconsulting.com
    ·
  • T&E EngineerT&E Engineer Posts: 1,396
    edited 2007-03-24 12:10
    Thanks.

    Is GetSecs a label or something (e.g. GetSecs: )?

    Should it be like this?

    Secs············ VAR···· Byte··················· ' Seconds

    Secs01········· VAR···· Secs

    Secs10··········VAR·····Secs


    GetSecs:
    Secs01 = Secs AND $0F······················ ' Secs01 = %xxxx1111
    Secs10 = Secs >> 4··························· ' Secs10 = %1111xxxx

    Post Edited (T&E Engineer) : 3/24/2007 12:34:23 PM GMT
  • JonnyMacJonnyMac Posts: 9,284
    edited 2007-03-24 15:44
    If you declare secs01 and secs10 as aliases of secs then the second line:

    secs10 = secs >> 4
    



    will always return 0 (because the preceding line stripped off the upper nibble). Unfortunately, the ease-of-use of the BASIC Stamp and its great language features have made many of us lazy and that shows up when we switch to a core processor like the SX. The great thing about SX/B, however, is that it's easy to extend the language via subroutines and functions. I do this:

    DEC2BCD         FUNC    1, 1
    BCD2DEC         FUNC    1, 1
    



    ... and then code those functions like this (both accept and return one byte):

    DEC2BCD:
      tmpB1 = __PARAM1                              ' get parameter
      tmpB2 = tmpB1 / 10                            ' isolate 10s
      SWAP tmpB2                                    ' move to upper nibble
      tmpB2 = tmpB2 | __REMAINDER                   ' add lower nibble
      RETURN tmpB2
    
    BCD2DEC:
      tmpB1 = __PARAM1                              ' get parameter
      tmpB2 = tmpB1 >> 4                            ' isolate high nibble
      tmpB2 = tmpB2 * 10                            ' convert to decimal
      tmpB1 = tmpB1 & $0F                           ' isolate ones
      tmpB2 = tmpB2 + tmpB1                         ' add them
      RETURN tmpB2
    



    Note on DEC2BCD: You have to be careful about using __REMAINDER; this code works because the SWAP instruction does not modify __PARAM1 (an alias of __REMAINDER) -- you will usually use __REMAINDER immediately after the division. I've tested these routines with values 0..99 and $0..$99 -- they work.

    Post Edited (JonnyMac) : 3/24/2007 3:57:19 PM GMT
Sign In or Register to comment.