How to write an instruction that clears bits 0 and 1 in the AL register using assembly?
and al, 0xFD
Adapt it to the assembler your are using: gas, nasm, masm ...
EDIT: Actually it is and al, 0xFC but you get the idea
AL is the low byte of the AX register, so you should be able to AND AL 0xFC to mask out the low bits.
AND AL,0xfc
equate it to zero?
like
mov al,00000000
ax=16bits al=8bits
now if anything is ored with al the answer will be the same as what is ored
but
if anything is anded with al the answer will be "0"
so i guess clearing it with all 1s or all 0s depends on your work and how you want to identify that there is nothing in the register.
You can clear bits by using the AND -operation.
for each bit index `i`
result[i] = boolean_and(first[i], second[i])
.--------- commonly associated symbol for the operation
|
& 1 0 <- first argument
-------
1 | 1 0 <- result
0 | 0 0
^--------- second argument
An example with a byte:
00101100
00111010
&
00101000
So you can use this operation to mask and flip bit regions in a register. Pass in a constant as the second argument which has bits flipped up you want to keep up.
x86 mnemonic: AND a, b
operation: a = a & b
Here's how to do it unless you didn't yet understood it:
AND eax, 0xfffffffc
AL is the lowest byte portion of EAX -register so you can do it this way.
Here's binary -> hexadecimal conversion table:
0000 | 0
0001 | 1
0010 | 2
0011 | 3
0100 | 4
0101 | 5
0110 | 6
0111 | 7
1000 | 8
1001 | 9
1010 | a
1011 | b
1100 | c
1101 | d
1110 | e
1111 | f
Oh, and you should remember this from the back of your head if you're going to be a self-respecting assembly-knowing programmer.
Also read about OR and XOR -bit operations.