Shop OBEX P1 Docs P2 Docs Learn Events
Shifting bits in a word — Parallax Forums

Shifting bits in a word

aa200orionaa200orion Posts: 10
edited 2010-06-28 02:09 in General Discussion
I am trying to·send the first 11 low order bits·of a word to a subroutine that converts a "1" or "0" into time.
Attached is my code.· The problem I am having is I can only send bits 0-7 to the subroutine.· Bits 9 & 10 are always "0".


I'm using an SX28 and SX-Basic·3.3.0


Any help would be appreciated.

Thanks,· Jimmy

CHART_CODE:

·chartcode = $211

··FOR idx = 0 TO 10
···IF chartcodebit = 1· THEN·
····OUTONE
······ ELSE·
····· ·OUTZERO
···ENDIF

···ASM
···CLC
···RR chartcode
···ENDASM

··NEXT

RETURN

·

Comments

  • ZootZoot Posts: 2,227
    edited 2010-06-28 02:09
    Post your full program. You would need to make sure that the parameter being passed to the sub/func is a WORD and is passed a word, and that the paramcnt is being set and handled in the subroutine if 1 or 3 or 4 bytes are allowed as parameters. Ditto for the return parameter(s) where applicable. Just a guess w/o seeing the whole program.

    Regardless, your assembly code for shifting a word will not work (but ironically, would work in straight SX/B, presuming "chartcode" is a word), e.g.

    
    chartcode = chartcode >> 1 ' in SX/B, if chartcode is a word this will always work properly
    
    ASM
    CLC
    RR chartcode ' if you look at your list/src output, you will see the "chartcode" and chartcode_LSB refer to the same byte,
    '  so this would only RR the lower byte, and leave the upper byte unchanged
    ENDASM
    
    'how to rotate with carry a word in assembly:
    ASM 
    CLC
    RR chartcode_MSB ' clear carry and rr upper byte of "chartcode"; at end of op, C hold the value of whatever bit0 of the MSB was
    RR chartcode_LSB ' rotate that bit into lower byte -- whole byte is rotated with C becoming bit7
    ENDASM
    
    



    When you define a Word variable in SX/B, the compiler automatically creates THREE named symbols (variables) for each word:

    wordName
    wordName_LSB
    wordName_MSB

    Note that wordName and wordName_LSB point to the same byte, this allows for clear use when doing things like:

    wordName VAR Word
    
    ASM
    MOV FSR, #wordName
    MOV __PARAM1, IND
    INC FSR
    MOV __PARAM2, IND
    ENDASM
    
    

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

    create bitmap data tool: 1uffakind.com/robots/povBitMapBuilder.php
    resistor ladder tool: 1uffakind.com/robots/resistorLadder.php
    convert images to ascii art: 1uffakind.com/apptoys/convtoascii/


    Post Edited (Zoot) : 6/28/2010 2:17:03 AM GMT
Sign In or Register to comment.