Prev: Apple II Debugger
Next: TMA Assembler?
From: Skybuck on 19 Aug 2006 04:59 Woops, sorry, I did not know comp.lang.asm.x86 is a moderated newsgroup, as I don't like moderated newsgroups I post it again and exclude comp.lang.asm.x86: Reversing bit order in delphi ? Hello, I think intel uses most significant bit first ? However there are some computers which use least significant bit first. So what would be the fastest way in pure delphi code to reverse the bits ? For example: [intel system, most significant bit first] Bit order: 7, 6, 5, 4, 3, 2, 1, 0 128, 64, 32, 16, 8, 4, 2, 1 0, 1, 1, 0, 1, 1, 0, 1 = 109 Reversing the bits would give: 1, 0, 1, 1, 0, 1, 1, 0 = 182 [ibm system or something else, least significant bit first] Bit order: 0, 1, 2, 3, 4, 5, 6, 7 1, 2, 4, 8, 16, 32, 64,128 0, 1, 1, 0, 1, 1, 0, 1 = 182 Reversing the bits would give: 1, 0, 1, 1, 0, 1, 1, 0 = 109 Reversing the bits in delphi code might be too slow, if that's the case is there a special (intel/amd) assembler instruction which might do the trick ? Note: This message/thread is cross posted to: alt.comp.lang.borland-delphi, alt.lang.asm Bye, Skybuck.
From: Rod Pemberton on 19 Aug 2006 06:02 "Skybuck" <skybuck2000(a)hotmail.com> wrote in message news:1155977986.135633.244450(a)h48g2000cwc.googlegroups.com... > Woops, sorry, I did not know comp.lang.asm.x86 is a moderated > newsgroup, as I don't like moderated newsgroups I post it again and > exclude comp.lang.asm.x86: > just email to clax86-submit(a)crayne.org > I think intel uses most significant bit first ? No, Intel uses LSB (Least Significant Byte, i.e., Little Endian, where a byte is 8-bits, i.e., not a byte as defined by C) > However there are some computers which use [the opposite]. Most Significant Byte (i.e., Big Endian) MSB vs LSB If you have 0xABCD in a cpu register, then 'A' is the MSB (Most Significant Byte) and 'D' is the LSB (Least Significant Byte). In Little Endian or LSB, when you save 0xABCD to memory, it will be stored in byte order as: 0xDCBA. The memory addressing decreases from MSB (i.e., 'A') to LSB (i.e., 'D'). The Least Significant Byte or Little Endian (i.e., 'D') is placed into the lowest memory address. In Big Endian or MSB, when you save 0xABCD to memory, it will be stored in byte order as: 0xABCD. The memory addressing increases from MSB (i.e., 'A') to LSB (i.e.,'D'). The Most Significant Byte or Big Endian (i.e., 'A') is placed into the lowest memory address. > Bit order: > 7, 6, 5, 4, 3, 2, 1, 0 > 128, 64, 32, 16, 8, 4, 2, 1 > 0, 1, 1, 0, 1, 1, 0, 1 = 109 > Reversing the bits would give: > 1, 0, 1, 1, 0, 1, 1, 0 = 182 > > Bit order: > 0, 1, 2, 3, 4, 5, 6, 7 > 1, 2, 4, 8, 16, 32, 64,128 > 0, 1, 1, 0, 1, 1, 0, 1 = 182 > Reversing the bits would give: > 1, 0, 1, 1, 0, 1, 1, 0 = 109 > > Reversing the bits in delphi code might be too slow, if that's the case > is there a special (intel/amd) assembler instruction which might do the > trick ? No, but I think you want byte order, not bit order. There are two Intel instructions which can be used to correct the byte order: bswap and xchg. 'bswap' is the current recommended instruction. But, prior to a 486, you'll need to use 'xchg' and some additional instructions. bswap http://www.ews.uiuc.edu/~cjiang/reference/vc21a.htm xchg http://www.ews.uiuc.edu/~cjiang/reference/vc326.htm Rod Pemberton
From: Skybuck on 19 Aug 2006 06:16 > > I think intel uses most significant bit first ? > > No, Intel uses LSB (Least Significant Byte, i.e., Little Endian, where a > byte is 8-bits, i.e., not a byte as defined by C) Oopsie you did not read my post well enough. I really do mean bit order, not byte order. Bye, Skybuck.
From: Frank Kotler on 19 Aug 2006 07:58 Skybuck wrote: > Woops, sorry, I did not know comp.lang.asm.x86 is a moderated > newsgroup, as I don't like moderated newsgroups I post it again and > exclude comp.lang.asm.x86: I agree with ya on principle, but the participants of comp.lang.asm voted to *create* the moderated comp.lang.asm.x86. You can post to comp.lang.asm if you want, but nobody's there - they prefer the moderated group... > Reversing bit order in delphi ? > > Hello, > > I think intel uses most significant bit first ? Yes. > However there are some computers which use least significant bit first. Ahhhh... yeah, in theory... Delphi run on any of 'em? > So what would be the fastest way in pure delphi code to reverse the > bits ? I'm posting from a.l.a., and don't know Delphi, but it allows inline asm, no? I don't think there's any "magic instruction" that'll help. Something like: ; assumes byte to reverse in al ; trashes ah, ecx, flags mov ah, al mov ecx, 8 top: rcr ah, 1 rcl al, 1 sub ecx, 1 jnz top That wouldn't be particularly fast, but I think it'll do what you want. > For example: > > [intel system, most significant bit first] > > Bit order: > > 7, 6, 5, 4, 3, 2, 1, 0 > > 128, 64, 32, 16, 8, 4, 2, 1 > 0, 1, 1, 0, 1, 1, 0, 1 = 109 > > Reversing the bits would give: > 1, 0, 1, 1, 0, 1, 1, 0 = 182 > > [ibm system or something else, least significant bit first] Does IBM actually *have* such a machine? (and does it have 8 bits to a byte?) > Bit order: > > 0, 1, 2, 3, 4, 5, 6, 7 > > 1, 2, 4, 8, 16, 32, 64,128 > 0, 1, 1, 0, 1, 1, 0, 1 = 182 > > Reversing the bits would give: > 1, 0, 1, 1, 0, 1, 1, 0 = 109 > > Reversing the bits in delphi code might be too slow, if that's the case > is there a special (intel/amd) assembler instruction which might do the > trick ? How would you do it in "Delphi code"? "Too slow" for what? You expect to be doing a *lot* of this??? > Note: > > This message/thread is cross posted to: > > alt.comp.lang.borland-delphi, alt.lang.asm "They say" that assembly language is dead. I don't know, but I suspect "they" may be saying the same about Delphi... Well it's back to back, belly to belly. I don't give a damn, 'cause I done dead already. Well it's back to back, belly to belly, at the Zombie Jamboree! Best, Frank
From: Evenbit on 19 Aug 2006 09:28
Skybuck wrote: > So what would be the fastest way in pure delphi code to reverse the > bits ? > Well, first, minimize the number of times you actually need to run through the complete algo. Check the input to see if the bit-pattern is symetrical or not. If it is symetrical, then you don't need to flip it. Examples: 11111111 00000000 11000011 00111100 00011000 11100111 10100101 etc.... Nathan. |