Reputation: 6756
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?
Upvotes: 1
Views: 1009
Reputation: 173
mov eax, [bitarray]
bitmask?
mov eax,[bitarray]
mov ebx,C0 ;11000000 binary
and ax,bx
Upvotes: 0
Reputation: 58427
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.
Upvotes: 3