hey
just wondering if anyone could tell how i can reverse the order of bits in a byte (i.e. 8 bits)
so 1010 1100 would become 0011 0101
is there one opcode that could do it, or would i have to use a method (if method then how ?)
thanks for any help
just wondering if anyone could tell how i can reverse the order of bits in a byte (i.e. 8 bits)
so 1010 1100 would become 0011 0101
is there one opcode that could do it, or would i have to use a method (if method then how ?)
thanks for any help
hey
just wondering if anyone could tell how i can reverse the order of bits in a byte (i.e. 8 bits)
so 1010 1100 would become 0011 0101
is there one opcode that could do it, or would i have to use a method (if method then how ?)
thanks for any help
Use bswap instruction, but I dont know can it do for 8 bits.
hey
nope bswap swaps bytes, i needa swap bits
thanks anyway
any other ideas ?
nope bswap swaps bytes, i needa swap bits
thanks anyway
any other ideas ?
Search the board, I already raised the question before. LUTs were the solution, iirc
ah yep i found it, thanks
http://www.asmcommunity.net/board/index.php?topic=19267.0
http://www.asmcommunity.net/board/index.php?topic=19267.0
someone,
Perhaps the fastest way is to use a look up table indexed into by the byte you want to reverse. That table will be 64 DWORDs long. If you want to reverse a DWORD, then use BSWAP first, and then reverse each of the four bytes. X86 does not have a reverse word instruction, but a lot of military computers do. It is handy for processing radar signals, where the return signal is reversed from the sent signal. Ratch
Perhaps the fastest way is to use a look up table indexed into by the byte you want to reverse. That table will be 64 DWORDs long. If you want to reverse a DWORD, then use BSWAP first, and then reverse each of the four bytes. X86 does not have a reverse word instruction, but a lot of military computers do. It is handy for processing radar signals, where the return signal is reversed from the sent signal. Ratch
It sounds like an arbitrary 256 byte table using XLATB or manually exchanging the bytes with normal pointer based lookup. The PHUN part will be constructing the table with each byte being its inverse of its location in the table.
ByteReverseLUT db 0, 128, 64, 192, 32, 160, 96, 224, 16, 144, 80, 208, 48, 176, 112, 240, 8, 136, 72, 200, 40, 168, 104, 232, 24, 152, 88, 216, 56, 184, 120, 248, 4, 132, 68, 196, 36, 164, 100, 228, 20, 148, 84, 212, 52, 180, 116, 244, 12, 140, 76, 204, 44, 172, 108, 236, 28, 156, 92, 220, 60, 188, 124, 252, 2, 130, 66, 194, 34, 162, 98, 226, 18, 146, 82, 210, 50, 178, 114, 242, 10, 138, 74, 202, 42, 170, 106, 234, 26, 154, 90, 218, 58, 186, 122, 250, 6, 134, 70, 198, 38, 166, 102, 230, 22, 150, 86, 214, 54, 182, 118, 246, 14, 142, 78, 206, 46, 174, 110, 238, 30, 158, 94, 222, 62, 190, 126, 254, 1, 129, 65, 193, 33, 161, 97, 225, 17, 145, 81, 209, 49, 177, 113, 241, 9, 137, 73, 201, 41, 169, 105, 233, 25, 153, 89, 217, 57, 185, 121, 249, 5, 133, 69, 197, 37, 165, 101, 229, 21, 149, 85, 213, 53, 181, 117, 245, 13, 141, 77, 205, 45, 173, 109, 237, 29, 157, 93, 221, 61, 189, 125, 253, 3, 131, 67, 195, 35, 163, 99, 227, 19, 147, 83, 211, 51, 179, 115, 243, 11, 139, 75, 203, 43, 171, 107, 235, 27, 155, 91, 219, 59, 187, 123, 251, 7, 135, 71, 199, 39, 167, 103, 231, 23, 151, 87, 215, 55, 183, 119, 247, 15, 143, 79, 207, 47, 175, 111, 239, 31, 159, 95, 223, 63, 191, 127, 255
VB6 snippet, 1 command button 1 text box
VB6 snippet, 1 command button 1 text box
Private Sub Command1_Click()
Dim a, b, c, d, e, f, g, h, x As Integer
Text1 = "ByteReverseLUT db "
For a = 0 To 1
For b = 0 To 1
For c = 0 To 1
For d = 0 To 1
For e = 0 To 1
For f = 0 To 1
For g = 0 To 1
For h = 0 To 1
x = a + 2 * b + 4 * c + 8 * d + 16 * e + 32 * f + 64 * g + 128 * h
Text1 = Text1 & x & ", "
Next h: Next g: Next f: Next e: Next d: Next c: Next b: Next a
End Sub
hutch--,
See code below. Ratch
See code below. Ratch
RBYTEBITS MACRO P1:REQ ;reverse byte bits
LOCAL RB,TB
TB = P1
RB = 0
REPEAT 8
RB = RB SHL 1
RB = RB + (1 AND TB)
TB = TB SHR 1
ENDM
EXITM <RB>
ENDM
.DATA
I = 0
REPEAT 256
BYTE RBYTEBITS(I)
I = I + 1
ENDM
.CODE
MAIN:
END MAIN
it's ok, i worked it out from that other post, thanks
i just used the basic loop for converting the one byte (8 bits)
mov edx, 8
@@:
shr ecx,1
rcl eax,1
dec edx
jnz @b
i just used the basic loop for converting the one byte (8 bits)
mov edx, 8
@@:
shr ecx,1
rcl eax,1
dec edx
jnz @b