views:

102

answers:

5

How to write an instruction that clears bits 0 and 1 in the AL register using assembly?

A: 
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

mathk
and al, 0xFCYour answer only clears bit 1, not bit 0.
Demi
Whatever, the point is the AND.
mathk
+4  A: 

AND AL,11111100b assuming MASM format

Joel
+3  A: 

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
John Franklin
A: 

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.

how about a comment why this is so un clear to the negative marker/? whats wrong? am also learning
it would appear that you didn't actually understand the question and/or don't know how to answer it, which is probably why you got a couple of downvotes. Look at the other (correct) answers to get a better understanding of what's being asked and how to solve it. In general it's probably a good idea to only attempt answering questions if (a) you're reasonably sure that you understand the question and (b) you have some confidence that you can provide a useful answer. Good luck.
Paul R
he only wants to clear the lowest 2 bits, not the entire register(or sub-register), your method discards too many bits, hence it totally the wrong method, just see the methods above yours.haha, 14 sec ninja Paul R is :P
Necrolis
A: 

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.

Cheery