1.1k views

A single instruction to clear the lower four bits of the accumulator in 8085 assembly language?

1. XRI 0FH
2. ANI F0H
3. XRI F0H
4. ANI 0FH
retagged | 1.1k views

ans is B.

explanation:

Quite very very easy, if you know the functions of XRI and ANI.
XRI stands for XOR Immediate. It tells the processor "I'll give you an operand immediately now, XOR it with the Accumulator and put the result in Accumulator itself".
ANI is similar, it says: "I'll give you an operand immediately now, do an AND operation between it and the Accumulator and put the result in Accumulator itself".
Here, we want to clear some bits. Since XOR operation's output always depends on both the operands, it can't be the answer. So, we're left with (b) and (d).
Now, in the AND operator, if one of the operands is a 1, the result is the value of the other operand.
And if one of the operands is 0, the result is 0, whatever the value of the other operand.
From this, we can see that in order to clear some bits (i.e., set them to 0), we have to AND them with 0.
In the question, they say 'lower four bits', which mean the bits to the right hand side (bits in the right hand side have less value, so are considered 'lower'.) So, in order to clear those bits, the 0's in the operand should also be in the right hand side.
Hence, ANI FOH is the answer. Here, each hexadecimal digit corresponds to four bits, so the operand is actually 1111 0000 in binary. Because of this, the lower four bits get cleared.

selected by
ans b)

1