Exact match. Not showing close matches.
PICList
Thread
'[SX] How can I flip bits in SX/B?'
2009\05\20@172713
by
tdg8934n/a
|
|
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!
---------- End of Message ----------
You can view the post on-line at:
http://forums.parallax.com/forums/default.aspx?f=7&p=1&m=353373
Need assistance? Send an email to the Forum Administrator at forumadmin@parallax.com
The Parallax Forums are powered by dotNetBB Forums, copyright 2002-2009 (http://www.dotNetBB.com)
|
|
You mean "reverse" the bit order? There is no command for it. Unrolling a loop is probably the most compact way to do it...
READ someAddr, tmpB99 tmpB3.0 = tmpB99.7
tmpB3.1 = tmpB99.6
tmpB3.2 = tmpB99.5
tmpB3.3 = tmpB99.4
tmpB3.4 = tmpB99.3
tmpB3.5 = tmpB99.2
tmpB3.6 = tmpB99.1
tmpB3.7 = tmpB99.0
FUNC revBits
__PARAM2.0 = __PARAM1.7
__PARAM2.1 = __PARAM1.6
__PARAM2.2 = __PARAM1.5
__PARAM2.3 = __PARAM1.4
__PARAM2.4 = __PARAM1.3
__PARAM2.5 = __PARAM1.2
__PARAM2.6 = __PARAM1.1
__PARAM2.7 = __PARAM1.0
RETURN __PARAM2
|
|
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
END
|
|
Nice. "C"lever use of C flag.
---------- End of Message ----------
You can view the post on-line at:
http://forums.parallax.com/forums/default.aspx?f=7&p=1&m=353373#m353433
Need assistance? Send an email to the Forum Administrator at forumadmin@parallax.com
The Parallax Forums are powered by dotNetBB Forums, copyright 2002-2009 (http://www.dotNetBB.com)
2009\05\21@075349 by tdg8934n/a
|
|
Thank you guys very much!
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!
---------- End of Message ----------
You can view the post on-line at:
http://forums.parallax.com/forums/default.aspx?f=7&p=1&m=353373#m353532
Need assistance? Send an email to the Forum Administrator at forumadmin@parallax.com
The Parallax Forums are powered by dotNetBB Forums, copyright 2002-2009 (http://www.dotNetBB.com)
2009\05\21@082551 by peterverkaikn/a
|
|
More on reversing bits:
http://www.sxlist.com/techref/ubicom/lib/math/bit/revbits_sx.htm
regards peter
---------- End of Message ----------
You can view the post on-line at:
http://forums.parallax.com/forums/default.aspx?f=7&p=1&m=353373#m353544
Need assistance? Send an email to the Forum Administrator at forumadmin@parallax.com
The Parallax Forums are powered by dotNetBB Forums, copyright 2002-2009 (http://www.dotNetBB.com)
|
|
Bean's code is way more compact... var.0 = var.7 compiles to a MOVB which is 4 instructions per bit or 32 instructions to re-map a byte. Bean's code is half that.
---------- End of Message ----------
You can view the post on-line at:
http://forums.parallax.com/forums/default.aspx?f=7&p=1&m=353373#m353566
Need assistance? Send an email to the Forum Administrator at forumadmin@parallax.com
The Parallax Forums are powered by dotNetBB Forums, copyright 2002-2009 (http://www.dotNetBB.com)
2009\05\21@175213 by JonnyMacn/a
|
|
I wrote a library of bit-oriented routines for the SX -- in it you'll find functions that will reverse the bits in a byte and in a word.
' 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
More... (looser matching)
- Last day of these posts
- In 2009
, 2010 only
- Today
- New search...