Actually, while were talking about binary operations:

While shift and rotate functions *are* masked to 31, is the bt instruction similarly masked??
I always believed that it was, however, I've seen bt used in some posts as indexing into an array several dwords long (one by The Svin in particularly, about determining if a byte is a letter or not) .

So what's the scoop?

--Chorus
Posted on 2002-07-27 12:56:57 by chorus
NOP-erator, for a loop, I sometimes just add the size of the structure:
	mov	ecx, Max_Struct

mov eax, pStruct
imul ecx, sizeof My_Struct
add eax, ecx ; point at end
neg ecx ; back-up to structs
_looop:
mov edx, [eax+ecx].My_Struct.item1
...
...
add ecx, sizeof My_Struct
jne _looop
This works with any size structure.
Posted on 2002-07-27 13:29:19 by bitRAKE
Actually, while were talking about binary operations:

While shift and rotate functions *are* masked to 31, is the bt instruction similarly masked??
I always believed that it was, however, I've seen bt used in some posts as indexing into an array several dwords long (one by The Svin in particularly, about determining if a byte is a letter or not) .

So what's the scoop?
Sorry, I have no idea on bt, haven't used bt in a long time since my CPUID program. Never did a lot of experiment with it. Usually bt on reg/mem is "slow" that's why I've only used it for such a short time. I'd rather load the memory value to a register and then TEST or AND the register with an immediate value...

The good thing about bt is you can test a specific bit position in memory or register *without having to think about what values to use on TEST or AND.* <-- Kinda lame excuse.

bt is like AND or TEST or CMP on bits but only affects the cf flag.

:)
Posted on 2002-07-27 13:36:28 by stryker
HERE is an interesting discussion of BT. Basically it is masked for register lookups, but not for memory lookups.
Posted on 2002-07-27 14:05:53 by bitRAKE
Thank you bitRAKE for clarifying :)

--Chorus
Posted on 2002-07-27 14:57:56 by chorus
Offtopic: An interesting discussion turn out into a "flame war" :grin: I love hearing those. :grin: Never heard flame wars in a long time. Maybe we could create a FAQ for flame wars. :grin: LOL :grin: <--- I'm an idiot :grin:
Posted on 2002-07-27 15:41:03 by stryker
We have some very passionate coders here - it is a very good thing even if we must wait for the flames to die down - the embers burn on forever. ;)
Posted on 2002-07-27 19:35:49 by bitRAKE
NOP,

Regarding your message "" vs. "", inquiry, i thought i would point that the technical reason why you cant use 12 is because it is not a PURE power of base 2. That is 12 is 2^2 + 2^3 = 4 + 8.

The actual assemly instruction, when converted to binary by the assembler, has a reserve for 3 or 4 bits (cant remember exact count off hand) in the op-code for SHIFTING (SHL) the register operand (and effectively multiplying).

So if three bits is reserved (think this is the # intel uses),
you can do:

Which is a selection of 8 (2^3) options depending on the value of these three bits in the opcode.

If the bits were "101" = 5, then the multiply would be 2^5 = 32, and the asm would be .


I kinda skimmed the latter messages, so if this was already said, sorry ;)
But if not,

Hope it helps..
:alright:
NaN
Posted on 2002-07-27 21:22:11 by NaN
NaN, there are two bits in the SIB Byte labeled SS. This scaled index allows the register to be multiplied by 1,2,4, or 8. It is Table 2-3 in the Intel Manual.
Posted on 2002-07-27 23:10:38 by bitRAKE
WOW! :eek: thank you very much!! now i got the clue about that stuff, thanks again!! from this on, i will always code with shifting and LEAing :grin: , it looks more professional :alright: :tongue:

mov eax,120h
shr eax,1

eax :grin:
Posted on 2002-07-28 04:52:11 by NOP-erator
A special case mathematical application of AND

and eax,(n-1) calculates the remainder (is that known as the modulus?) of eax divided by n if n is a power of 2

eg:

and eax,127        ;remainder of eax/128


I've found it useful sometimes...
Posted on 2002-07-28 16:43:00 by eGo