How can I flip bits in SX/B?
If I have a variable tmpB3 which·let's say looks·something like this: %11001010 and I want the bits to be fliped so it now is: %01010011
How can this be done?
More specifically·I have a data statement with a character (or really lots of characters in DATA statements):
UC_Letter_A:
DATA· %01111100 'A
DATA· %00010010
DATA· %00010001
DATA· %00010010
DATA· %01111100
and I don't want to have to retype every character in flipped again but I need this:
UC_Letter_A:
DATA· %00111110·'A (flipped bits)
DATA· %01001000
DATA· %10001000
DATA· %01001000
DATA· %00111110
There should be a way to read it in and flip the bits. How can this be done in SX/B 2.0?
Thanks for your help!
·
How can this be done?
More specifically·I have a data statement with a character (or really lots of characters in DATA statements):
UC_Letter_A:
DATA· %01111100 'A
DATA· %00010010
DATA· %00010001
DATA· %00010010
DATA· %01111100
and I don't want to have to retype every character in flipped again but I need this:
UC_Letter_A:
DATA· %00111110·'A (flipped bits)
DATA· %01001000
DATA· %10001000
DATA· %01001000
DATA· %00111110
There should be a way to read it in and flip the bits. How can this be done in SX/B 2.0?
Thanks for your help!
·

Comments
Of course, you can write a function with two bit masks if you need to operate on a wide swatch of variables with variable reverse counts and lengths (a la the Stamp REV operator), or you can use two other temps or a local stack and load 'em up as parameters...
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
When the going gets weird, the weird turn pro. -- HST
1uffakind.com/robots/povBitMapBuilder.php
1uffakind.com/robots/resistorLadder.php
DEVICE SX28, OSC4MHZ FREQ 4_000_000 origData VAR BYTE flipData VAR BYTE PROGRAM Start NOSTARTUP Start: origData = %11001010 ASM 'flipData = OrigData with bits flipped; NOTE: Destoys value in origData RR origData RL flipData RR origData RL flipData RR origData RL flipData RR origData RL flipData RR origData RL flipData RR origData RL flipData RR origData RL flipData RR origData RL flipData ENDASM ENDBean
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
There is a fine line between arrogance and confidence. Make sure you don't cross it...
·
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
When the going gets weird, the weird turn pro. -- HST
1uffakind.com/robots/povBitMapBuilder.php
1uffakind.com/robots/resistorLadder.php
I thought about Zoot's first approach but was locked into thinking I could use a FOR NEXT loop which failed as seen in another post from PJ Allen.
e.g.
j = 7
FOR i = 0 TO 7
tmp4.j = tmp3.i
j=j-1
NEXT
However, sometimes you need to break it down to the simplest form like Zoot did. This is working but I have other minor issues to deal with (which I will try to work out before I ask for help).
I am writing code for the new 0832 Display boards and have it almost working but these boards use nibbles not bytes so it's a bit awkward: http://www.sureelectronics.net/goods.php?id=903
PS: Is there any advantage (e.g. significant speed difference or saving ram space, etc.) using Bean's assembly language routine as I am not familiar with this as much as SX/B?
Thanks again guys!
http://www.sxlist.com/techref/ubicom/lib/math/bit/revbits_sx.htm
regards peter
·
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
When the going gets weird, the weird turn pro. -- HST
1uffakind.com/robots/povBitMapBuilder.php
1uffakind.com/robots/resistorLadder.php
' Use: result = FLIP_BYTE aByte ' -- flips bits in byte end-to-end FUNC FLIP_BYTE '{$IFUSED FLIP_BYTE} ASM MOV __PARAM2, __PARAM1 ' make copy to __PARAM2 CLR __PARAM3 ' clear count FB_Loop: RR __PARAM2 ' get bit from __PARAM2 RL __PARAM1 ' move into __PARAM1 INC __PARAM3 ' update count JNB __PARAM3.3, @FB_Loop ' abort at 8 ENDASM '{$ENDIF} ENDFUNC' Use: result = FLIP_WORD aWord ' -- flips bits in word end-to-end FUNC FLIP_WORD '{$IFUSED FLIP_WORD} ASM MOV __PARAM3, __PARAM1 ' make copy to __WPARAM34 MOV __PARAM4, __PARAM2 CLR __PARAM5 ' clear count FW_Loop: RR __PARAM4 ' get bit from __WPARAM34 RR __PARAM3 RL __PARAM1 ' move into __WPARAM12 RL __PARAM2 INC __PARAM5 ' update count JNB __PARAM5.4, @FW_Loop ' abort at 16 ENDASM '{$ENDIF} ENDFUNCPost Edited (JonnyMac) : 5/22/2009 12:56:56 AM GMT