1

I need 2 bits with offset 6 from bit array.

mov eax, [bitarray]; // get address of bit array
shr eax, 6; // clear first 6 bits
shl eax, 30 // clear last 30 bits
shr eax, 30; // move that 2 bits back to start

now in eax is these 2 bits i need, right?

When i have memory started from 0 (one unit is one bit), then bit on position 0 will be after load into register eax in most right place or most left place?

2 Answers 2

3

Instead of the two shifts at the end you could have use a bitwise AND:

AND EAX,3  ; Keep the original value of the two least significant bits; all
           ; other bits in EAX are cleared.

The left-most bit is the most significant one, and the right-most bit the least significant one.

Sign up to request clarification or add additional context in comments.

4 Comments

yes i know left-most is the most significant, but if there is little endian, then in memory that left-most bit in register is where? On position 0 or position 7?
Endianness doesn't affect the order of bits within a byte. It affects the order of bytes with a word/dword/etc. The most significant bit of a byte is bit 7.
oh i see it now, if you are doing AND with 3
michael: yes, so first bit in memory isn't first bit in eax?
0

mov eax, [bitarray]

bitmask?

mov eax,[bitarray]
mov ebx,C0         ;11000000 binary
and ax,bx

1 Comment

i think this is bad, it should be ANDed with value 3 (00000011)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.